src/ControllerModel/user/paramUtilTrait.php line 2339

Open in your IDE?
  1. <?php
  2. namespace App\ControllerModel\user;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Contracts\Translation\TranslatorInterface;
  5. use \Symfony\Component\HttpFoundation\Request;
  6. use \Doctrine\ORM\EntityManager;
  7. use App\Entity\stock\Compteur;
  8. use App\Entity\asso\Activite;
  9. use App\Entity\asso\Concerne;
  10. use App\Types\user\TypeEtat;
  11. use App\Entity\stock\SuivieLivraison;
  12. use App\Entity\user\HistoriqueAction;
  13. use App\Services\user\LoginManager;
  14. use App\Controller\param\ParametreController;
  15. use App\Entity\stock\CodeBarre;
  16. use App\Entity\stock\CaissePrix;
  17. use App\Entity\stock\CaisseClient;
  18. use App\Entity\user\Utilisateur;
  19. use App\Entity\client\Client;
  20. use App\Entity\prod\Plante;
  21. use App\Entity\client\ClientPrix;
  22. use App\Entity\stock\Image;
  23. use App\Entity\prod\ProducteurGroupement;
  24. use App\Entity\prod\ProducteurAbonne;
  25. use App\Entity\prod\SurfaceAbonne;
  26. use App\Entity\stock\FournisseurAbonne;
  27. use App\Entity\stock\ProduitAbonne;
  28. use App\Entity\stock\ZoneProducteur;
  29. use App\Entity\stock\Commande;
  30. use App\Entity\stock\Ville;
  31. use App\Repository\param\ParamRepository;
  32. use App\Repository\user\ConnexionRepository;
  33. use App\Repository\user\ActionRepository;
  34. use App\Repository\user\UtilisateurRepository;
  35. use App\Repository\user\AbonneRepository;
  36. use App\Repository\user\ModuleRepository;
  37. use App\Repository\user\ControleurRepository;
  38. use App\Repository\prod\SurfaceAbonneRepository;
  39. use App\Repository\stock\ProduitAbonneRepository;
  40. use App\Repository\prod\ProducteurAbonneRepository;
  41. use App\Repository\user\AbonneVilleRepository;
  42. use App\Repository\prod\GroupementAbonneRepository;
  43. use App\Repository\inspection\InspectionAbonneRepository;
  44. use App\Repository\stock\FournisseurAbonneRepository;
  45. use App\Repository\user\ProfilRepository;
  46. use App\Entity\stock\InfoLivrer;
  47. use App\Entity\stock\Livrer;
  48. use App\Entity\client\EtatInfoClient;
  49. use App\Entity\client\EtatClient;
  50. use App\Entity\stock\LigneCommandeClient;
  51. use App\Repository\stock\InfoLivrerRepository;
  52. use App\Entity\stock\LigneCommande;
  53. use App\Entity\stock\PrixRigueur;
  54. use App\Entity\stock\SurPlus;
  55. use App\Repository\stock\ParamSystDateRepository;
  56. use App\Repository\cms\MenuRepository;
  57. use App\Entity\user\AbonneVille;
  58. use App\Entity\prod\Groupement;
  59. use App\Entity\cms\ZoneGroupement;
  60. use App\Entity\cms\Page;
  61. use App\Entity\inspection\Inspection;
  62. use App\Entity\stock\EtatInfoOpportunite;
  63. use App\Entity\stock\Opportunite;
  64. use App\Entity\prod\SurfaceAnneeHistorique;
  65. use App\Entity\prod\GroupementAbonne;
  66. use App\Entity\inspection\InspectionAbonne;
  67. use App\Entity\stock\CategorieAbonne;
  68. use App\Entity\stock\CategorieProduit;
  69. use App\Entity\stock\EtapeProcessus;
  70. use App\Entity\stock\InfoDeplacer;
  71. use App\Entity\stock\InfoLivrerAbonne;
  72. use App\Entity\stock\TransformationAbonne;
  73. use App\Entity\stock\ZoneAbonne;
  74. use App\Repository\prod\SurfaceAnneeHistoriqueRepository;
  75. use PDO;
  76. use DateInterval;
  77. Trait paramUtilTrait {
  78.     /**
  79.      * @var string
  80.      * Nom du Bundle
  81.      */
  82.     protected $stockBundle 'adminStockBundle:';
  83.     protected $stockBundleSlash 'stock/';
  84.     protected $moduleTitre '';
  85.     protected $moduleDesc '';
  86.     private  $produitAbonneRepository;
  87.     private  $surfaceAbonneRepository;
  88.     private  $producteurAbonneRepository;
  89.     private  $fournisseurAbonneRepository;
  90.     private  $groupementAbonneRepository;
  91.     private  $abonneVilleRepository;
  92.     private  $inspectionAbonneRepository;
  93.     /**
  94.      * @var string
  95.      * Nom du Bundle
  96.      */
  97.     public function __construct(InfoLivrerRepository $infoLivrerRepositoryTranslatorInterface $translatorSurfaceAnneeHistoriqueRepository $surfaceAnneeHistoriqueRepository,
  98.     SurfaceAbonneRepository $surfaceAbonneRepositoryProduitAbonneRepository $produitAbonneRepositoryProducteurAbonneRepository $producteurAbonneRepository
  99.     FournisseurAbonneRepository $fournisseurAbonneRepositoryGroupementAbonneRepository $groupementAbonneRepository,AbonneVilleRepository $abonneVilleRepository,
  100.     InspectionAbonneRepository $inspectionAbonneRepository)
  101.     {
  102.         //parent::__construct();
  103.         $this->infoLivrerRepository $infoLivrerRepository;
  104.         $this->translator $translator;
  105.         $this->surfaceAnneeHistoriqueRepository =  $surfaceAnneeHistoriqueRepository;
  106.         $this->surfaceAnneeHistoriqueRepository =  $surfaceAnneeHistoriqueRepository;
  107.         $this->produitAbonneRepository =$produitAbonneRepository;
  108.         $this->surfaceAbonneRepository=$surfaceAbonneRepository;
  109.         $this->producteurAbonneRepository=$producteurAbonneRepository;
  110.         $this->fournisseurAbonneRepository=$fournisseurAbonneRepository;
  111.         $this->groupementAbonneRepository=$groupementAbonneRepository;
  112.         $this->abonneVilleRepository=$abonneVilleRepository;
  113.         $this->inspectionAbonneRepository=$inspectionAbonneRepository;
  114.         //$this->infoLivrerRepository = 
  115.         //var_dump(1);exit;
  116.     }
  117.     protected $gmaoBundle 'adminGmaoBundle:';
  118.     public function gmaoBundleSlash($typePresentation){
  119.         if($typePresentation == )
  120.             return 'template_1/gmao/';
  121.         elseif($typePresentation == )
  122.             return 'template_2/gmao/';
  123.         else
  124.             return 'gmao/';
  125.     }
  126.     protected $gmaoBundleSlash 'gmao/';
  127.     protected $paramBundle 'adminParamBundle:';
  128.     
  129.     public function paramBundleSlash($typePresentation){
  130.         if($typePresentation == )
  131.             return 'template_1/param/';
  132.         elseif($typePresentation == )
  133.             return 'template_2/param/';
  134.         elseif($typePresentation == )
  135.             return 'template_3/param/';
  136.         else
  137.             return 'param/';
  138.     }
  139.     protected $cmsBundle 'adminCmsBundle:';
  140.     
  141.     public function cmsBundleSlash($typePresentation){
  142.         if($typePresentation == )
  143.             return 'template_1/cms/';
  144.         elseif($typePresentation == )
  145.             return 'template_2/cms/';
  146.         elseif($typePresentation == )
  147.             return 'template_3/cms/';
  148.         else
  149.             return 'cms/';
  150.     }
  151.     protected $trackBundle 'adminTrackBundle:';
  152.     
  153.     public function trackBundleSlash($typePresentation){
  154.         if($typePresentation == )
  155.             return 'template_1/track/';
  156.         elseif($typePresentation == )
  157.             return 'template_2/track/';
  158.         elseif($typePresentation == )
  159.             return 'template_3/track/';
  160.         else
  161.             return 'track/';
  162.     }
  163.     
  164.     protected $aVenteBundle 'AppBundle:';
  165.     protected $userBundle 'App\\Entity\\user\\';
  166.   
  167.     protected $prodBundle 'adminProdBundle:';
  168.     
  169.     public function prodBundleSlash($typePresentation){
  170.         if($typePresentation == )
  171.             return 'template_1/prod/';
  172.         elseif($typePresentation == )
  173.             return 'template_2/prod/';
  174.         elseif($typePresentation == )
  175.             return 'template_3/prod/';
  176.         else
  177.             return 'prod/';
  178.     }
  179.     public function stockBundleSlash($typePresentation){
  180.         if($typePresentation == )
  181.             return 'template_1/stock/';
  182.         elseif($typePresentation == )
  183.             return 'template_2/stock/';
  184.         elseif($typePresentation == )
  185.             return 'template_3/stock/';
  186.         else
  187.             return 'stock/';
  188.     }
  189.     public function statistiquesBundleSlash($typePresentation){
  190.         if($typePresentation == )
  191.             return 'template_1/statistiques/';
  192.         elseif($typePresentation == )
  193.             return 'template_2/statistiques/';
  194.         elseif($typePresentation == )
  195.             return 'template_3/statistiques/';
  196.         else
  197.             return 'stock/';
  198.     }
  199.     protected $siteBundle 'adminSiteBundle:'
  200.     protected $siteBundleSlash 'site/';
  201.     protected $inspectionBundle 'adminInspectionBundle:'
  202.     
  203.     public function inspectionBundleSlash($typePresentation){
  204.         if($typePresentation == )
  205.             return 'template_1/inspection/';
  206.         elseif($typePresentation == )
  207.             return 'template_2/inspection/';
  208.         elseif($typePresentation == )
  209.             return 'template_3/inspection/';
  210.         else
  211.             return 'inspection/';
  212.     }
  213.     protected $clientBundle 'adminClientBundle:'
  214.     
  215.     public function clientBundleSlash($typePresentation){
  216.         if($typePresentation == )
  217.             return 'template_1/client/';
  218.         elseif($typePresentation == )
  219.             return 'template_2/client/';
  220.         elseif($typePresentation == )
  221.             return 'template_3/client/';
  222.         else
  223.             return 'client/';
  224.     }
  225.     protected $assoBundle 'adminAssoBundle:'
  226.     
  227.     public function assoBundleSlash($typePresentation){
  228.         if($typePresentation == )
  229.             return 'template_1/asso/';
  230.         elseif($typePresentation == )
  231.             return 'template_2/asso/';
  232.         elseif($typePresentation == )
  233.             return 'template_3/asso/';
  234.         else
  235.             return 'asso/';
  236.     }
  237.     protected $bailleurBundle 'adminBailleurBundle:'
  238.    
  239.     public function bailleurBundleSlash($typePresentation){
  240.         if($typePresentation == )
  241.             return 'template_1/bailleur/';
  242.         elseif($typePresentation == )
  243.             return 'template_2/bailleur/';
  244.         elseif($typePresentation == )
  245.             return 'template_3/bailleur/';
  246.         else
  247.             return 'bailleur/';
  248.     }
  249.     public function userBundleSlash($typePresentation){
  250.         if($typePresentation == )
  251.             return 'template_1/user/';
  252.         elseif($typePresentation == )
  253.             return 'template_2/user/';
  254.         elseif($typePresentation == )
  255.             return 'template_3/user/';
  256.         else
  257.             return 'user/';
  258.     }
  259.     public function getInfoPartenaire($em$objetAbonne){
  260.         $data =array();
  261.         if($objetAbonne->getSiPrincipale() == ){
  262.             $data['typeAction'] = $objetAbonne->getSiPrincipale();
  263.             $data['partenaireId'] = $objetAbonne->getPartenaire()->getId();
  264.         }else if ($objetAbonne->getSiPrincipale() == 1){
  265.             $data['typeAction'] = $objetAbonne->getSiPrincipale();
  266.             $data['partenaireId'] = $objetAbonne->getPartenaire()->getId();
  267.         }else{
  268.             $data['typeAction'] = $objetAbonne->getSiPrincipale() ;
  269.             $data['partenaireId'] = 0;
  270.         }
  271.         return $data;
  272.     }
  273.     public function ajoutCategorieProduit($em$nomCategorie$typeCategorie$objetAbonne){
  274.         $categorieCond = new CategorieProduit();
  275.         $categorieCond->setNom($nomCategorie);
  276.         $categorieCond->setDescription($typeCategorie);
  277.         $categorieCond->setCode("CAT".rand(200099999));
  278.         $categorieCond->setTypeCategorie($typeCategorie);
  279.         $categorieCond->setAbonne($objetAbonne);
  280.         $em->persist($categorieCond);
  281.         $em->flush();
  282.         return true;
  283.     }
  284.     
  285.     public function setUpdateAbonnePartenaire($em$objetAbonne$objetPartenaire$objetClasse$typeObjet$siPrincipale=1$surfaceAbonneRepository$produitAbonneRepository,  $producteurAbonneRepository
  286.      $fournisseurAbonneRepository,  $groupementAbonneRepository$abonneVilleRepository,
  287.      $inspectionAbonneRepository){
  288.         
  289.         $data =array();
  290.         if($typeObjet == ){
  291.             $objetAbonnePartenaire $produitAbonneRepository->findOneBy(['abonne'=>$objetAbonne'produit'=>$objetClasse'partenaire'=>$objetPartenaire]);
  292.             if($objetAbonnePartenaire == null)
  293.                 $objetAbonnePartenaire = new  ProduitAbonne();
  294.             $objetAbonnePartenaire->setProduit($objetClasse);
  295.         }else if ($typeObjet == 2){
  296.             $objetAbonnePartenaire $producteurAbonneRepository->findOneBy(['abonne'=>$objetAbonne'producteur'=>$objetClasse'partenaire'=>$objetPartenaire]);
  297.             if($objetAbonnePartenaire == null)
  298.                 $objetAbonnePartenaire = new  ProducteurAbonne();
  299.             $objetAbonnePartenaire->setProducteur($objetClasse);
  300.         }else if ($typeObjet == 3){
  301.             $objetAbonnePartenaire $surfaceAbonneRepository->findOneBy(['abonne'=>$objetAbonne'surfaceannee'=>$objetClasse'partenaire'=>$objetPartenaire]);
  302.             if($objetAbonnePartenaire == null)
  303.                 $objetAbonnePartenaire = new SurfaceAbonne();
  304.             $objetAbonnePartenaire->setSurfaceannee($objetClasse);
  305.            
  306.         }else if ($typeObjet == 4){
  307.             $objetAbonnePartenaire $fournisseurAbonneRepository->findOneBy(['abonne'=>$objetAbonne'fournisseur'=>$objetClasse'partenaire'=>$objetPartenaire]);
  308.             if($objetAbonnePartenaire == null)
  309.                 $objetAbonnePartenaire = new FournisseurAbonne();
  310.             $objetAbonnePartenaire->setFournisseur($objetClasse);
  311.         }else if ($typeObjet == 5){
  312.             $objetAbonnePartenaire $groupementAbonneRepository->findOneBy(['abonne'=>$objetAbonne'groupement'=>$objetClasse'partenaire'=>$objetPartenaire]);
  313.             if($objetAbonnePartenaire == null)
  314.                 $objetAbonnePartenaire = new GroupementAbonne();
  315.             $objetAbonnePartenaire->setGroupement($objetClasse);
  316.         }else if ($typeObjet == 6){
  317.             $objetAbonnePartenaire $abonneVilleRepository->findOneBy(['abonne'=>$objetAbonne'ville'=>$objetClasse'partenaire'=>$objetPartenaire]);
  318.             if($objetAbonnePartenaire == null)
  319.                 $objetAbonnePartenaire = new AbonneVille();
  320.             $objetAbonnePartenaire->setVille($objetClasse);
  321.         }else if ($typeObjet == 7){
  322.             $objetAbonnePartenaire $inspectionAbonneRepository->findOneBy(['abonne'=>$objetAbonne'inspection'=>$objetClasse'partenaire'=>$objetPartenaire]);
  323.             if($objetAbonnePartenaire == null)
  324.                 $objetAbonnePartenaire = new InspectionAbonne();
  325.             $objetAbonnePartenaire->setInspection($objetClasse);
  326.         }
  327.         $objetAbonnePartenaire->setAbonne($objetAbonne);
  328.         $objetAbonnePartenaire->setPartenaire($objetPartenaire);
  329.         $objetAbonnePartenaire->setSiPrincipale($siPrincipale);
  330.         $em->persist($objetAbonnePartenaire);
  331.         $em->flush();
  332.         return 1;
  333.     }
  334.     public function setUpdateAbonnePartenaireEvolue($em$objetAbonne$objetPartenaire$objetClasse$typeObjet$siPrincipale=1$categorieAbonneRepository$infoLivrerAbonneRepository$transformationAbonneRepository){
  335.         
  336.         $data =array();
  337.         if ($typeObjet == 8){
  338.             $objetAbonnePartenaire $categorieAbonneRepository->findOneBy(['abonne'=>$objetAbonne'categorie'=>$objetClasse]);
  339.             if($objetAbonnePartenaire == null)
  340.                 $objetAbonnePartenaire = new CategorieAbonne();
  341.             $objetAbonnePartenaire->setCategorie($objetClasse);
  342.         }else if ($typeObjet == 9){
  343.             
  344.             $objetAbonnePartenaire $infoLivrerAbonneRepository->findOneBy(['abonne'=>$objetAbonne'infolivrer'=>$objetClasse]);
  345.             if($objetAbonnePartenaire == null)
  346.                 $objetAbonnePartenaire = new InfoLivrerAbonne();
  347.             $objetAbonnePartenaire->setInfoliver($objetClasse);
  348.         }else if ($typeObjet == 10){
  349.             
  350.             $objetAbonnePartenaire $transformationAbonneRepository->findOneBy(['abonne'=>$objetAbonne'infolivrer'=>$objetClasse]);
  351.             if($objetAbonnePartenaire == null)
  352.                 $objetAbonnePartenaire = new TransformationAbonne();
  353.             $objetAbonnePartenaire->setTransformation($objetClasse);
  354.         }
  355.         $objetAbonnePartenaire->setAbonne($objetAbonne);
  356.         $objetAbonnePartenaire->setPartenaire($objetPartenaire);
  357.         $objetAbonnePartenaire->setSiPrincipale($siPrincipale);
  358.         $em->persist($objetAbonnePartenaire);
  359.         $em->flush();
  360.         return 1;
  361.     }
  362.     public function setAbonnePartenaire($em$objetAbonne$objetPartenaire$objetClasse$typeObjet$siPrincipale=1){
  363.         
  364.         $data =array();
  365.         if($typeObjet == ){
  366.            
  367.             $objetAbonnePartenaire = new  ProduitAbonne();
  368.             $objetAbonnePartenaire->setProduit($objetClasse);
  369.         }else if ($typeObjet == 2){
  370.             
  371.             $objetAbonnePartenaire = new  ProducteurAbonne();
  372.             $objetAbonnePartenaire->setProducteur($objetClasse);
  373.         }else if ($typeObjet == 3){
  374.             
  375.             $objetAbonnePartenaire = new SurfaceAbonne();
  376.             $objetAbonnePartenaire->setSurfaceannee($objetClasse);
  377.            
  378.         }else if ($typeObjet == 4){
  379.             
  380.             $objetAbonnePartenaire = new FournisseurAbonne();
  381.             $objetAbonnePartenaire->setFournisseur($objetClasse);
  382.         }else if ($typeObjet == 5){
  383.             
  384.             $objetAbonnePartenaire = new GroupementAbonne();
  385.             $objetAbonnePartenaire->setGroupement($objetClasse);
  386.         }else if ($typeObjet == 6){
  387.             
  388.             $objetAbonnePartenaire = new AbonneVille();
  389.             $objetAbonnePartenaire->setVille($objetClasse);
  390.         }else if ($typeObjet == 7){
  391.             
  392.             $objetAbonnePartenaire = new InspectionAbonne();
  393.             $objetAbonnePartenaire->setInspection($objetClasse);
  394.         }
  395.         $objetAbonnePartenaire->setAbonne($objetAbonne);
  396.         $objetAbonnePartenaire->setPartenaire($objetPartenaire);
  397.         $objetAbonnePartenaire->setSiPrincipale($siPrincipale);
  398.         $em->persist($objetAbonnePartenaire);
  399.         $em->flush();
  400.         return 1;
  401.     }
  402.     /**
  403.      * @var string
  404.      *      Nom du Bundle
  405.      */
  406.     protected $messagerieBundle 'adminMessagerieBundle:';
  407.     // use \Symfony\Component\DependencyInjection\ContainerAwareTrait;
  408.     public function infosConnecte(Request $requestLoginManager $loginManagerParamRepository $paramRepositor,ConnexionRepository $connexionRepositoryActionRepository $actionRepository ) {
  409.         //$this->updateMessageNonLu();
  410.         //
  411.         $sessionData $loginManager->getSessionData(LoginManager::SESSION_DATA_NAME);
  412.         $status $loginManager->isConnecte('',$paramRepositor,$connexionRepository,$actionRepository );
  413. //        $banque = $loginManager->getBanque();
  414.         $request->attributes->set('isConnecte'$status['isConnecte']);
  415.         $request->attributes->set('isUser'$status['isUser']);
  416.         $request->attributes->set('logoUrl'ParametreController::DEFAULT_LOGO_NAME);
  417.         $request->attributes->set('nbMessageNonLu'0);
  418. //        $request->attributes->set('infos', $banque);
  419. //        if($banque instanceof  Banque){
  420. //            $request->attributes->set('logoUrl',$banque->getUrlLogo());
  421. //        }
  422.         if (($sessionData != NULL) && (is_array($sessionData)) && ($status['isConnecte'])) {
  423.             if (array_key_exists('nbMessageNonLu'$sessionData)) {
  424.                 $request->attributes->set('nbMessageNonLu'$sessionData['nbMessageNonLu']);
  425.             }
  426.             if (array_key_exists('nomTableConnecte'$sessionData)) {
  427.                 $request->attributes->set('nomTableConnecte'$sessionData['nomTableConnecte']);
  428.             }
  429.             if (array_key_exists('isUser'$sessionData)) {
  430.                 $request->attributes->set('isUser'$sessionData['isUser']);
  431.             }
  432.             if (array_key_exists('isAbonne'$sessionData)) {
  433.                 $request->attributes->set('isAbonne'$sessionData['isAbonne']);
  434.             }
  435.             if (array_key_exists('urlImage'$sessionData)) {
  436.                 $request->attributes->set('urlImage'$sessionData['urlImage']);
  437.             }
  438.             if (array_key_exists('id'$sessionData)) {
  439.                 $request->attributes->set('id'$sessionData['id']);
  440.             }
  441.             if (array_key_exists('prenoms'$sessionData)) {
  442.                 $request->attributes->set('prenoms'$sessionData['prenoms']);
  443.             }
  444.             if (array_key_exists('nom'$sessionData)) {
  445.                 $request->attributes->set('nom'$sessionData['nom']);
  446.             }
  447.             if (array_key_exists('sexe'$sessionData)) {
  448.                 $request->attributes->set('sexe'$sessionData['sexe']);
  449.             }
  450.             if (array_key_exists('idConnexion'$sessionData)) {
  451.                 $request->attributes->set('idConnexion'$sessionData['idConnexion']);
  452.             }
  453.             if (array_key_exists('username'$sessionData)) {
  454.                 $request->attributes->set('username'$sessionData['username']);
  455.             }
  456.             if (array_key_exists('idProfil'$sessionData)) {
  457.                 $request->attributes->set('idProfil'$sessionData['idProfil']);
  458.             }
  459.             if (array_key_exists('libelleProfil'$sessionData)) {
  460.                 $request->attributes->set('libelleProfil'$sessionData['libelleProfil']);
  461.             }
  462.             if (array_key_exists('codeProfil'$sessionData)) {
  463.                 $request->attributes->set('codeProfil'$sessionData['codeProfil']);
  464.             }
  465.             $this->data['tabIdActions'] = array();
  466.             if (array_key_exists('tabIdActions'$sessionData)) {
  467.                 $request->attributes->set('tabIdActions'$sessionData['tabIdActions']);
  468.                 $this->data['tabIdActions'] = $sessionData['tabIdActions'];
  469.             }
  470.             if (array_key_exists('locale'$sessionData)) {
  471.                 $request->attributes->set('locale'$sessionData['locale']);
  472.                 $this->data['locale'] = $sessionData['locale'];
  473.                 $request->setLocale($sessionData['locale']);
  474.             } else {
  475.                 $locale $loginManager->getLocale();
  476.                 $request->attributes->set('locale'$locale);
  477.                 $this->data['locale'] = $locale;
  478.                 $request->setLocale($locale);
  479.             }
  480.             if ($status['isUser']) {
  481. //                $profilsAbonne = $loginManager->getAllProfilAbonne();
  482.             }
  483.         }
  484.         //var_dump($sessionData);exit;
  485. //        $this->data['profilsAbonne'] = $profilsAbonne;
  486.         return $sessionData;
  487.     }
  488.     /**
  489.      * Récupération du service de gestion des logs;
  490.      * @return LogManager
  491.      */
  492.     private function getLogManager() {
  493.         return $this->get('logManager');
  494.     }
  495.     /**
  496.      * Retourne le nom d'une classe à partir de l'espace de nom complet de la classe
  497.      * @param type $nameSpace
  498.      * @return type
  499.      */
  500.     public function getNomClassRun($nameSpace) {
  501.         $nom '';
  502.         if (strlen($nameSpace) > 0) {
  503.             $tab explode("\\"$nameSpace);
  504.             $taille count($tab);
  505.             if ($taille 0) {
  506.                 $nom $tab[$taille 1];
  507.             }
  508.         }
  509.         return $nom;
  510.     }
  511.     public function gestionDroitUtil($request$nomAction$descAction$module$moduledescript LoginManager $loginManager,ParamRepository $paramRepositor,ConnexionRepository $connexionRepository,ActionRepository $actionRepository,
  512.     ModuleRepository $moduleRepository,ControleurRepository $controleurRepository,ProfilRepository $profilRepository) {
  513.         /*
  514.          * Préparation du message de log 
  515.          */
  516.         $this->logMessage .= ' [ ' $nomAction ' ] ';
  517.         /*
  518.          * Service de gestion des droits
  519.          */
  520.         //
  521.         /*
  522.          * Informations de session
  523.          */
  524.         $sessionData $this->infosConnecte($request$loginManager$paramRepositor,$connexionRepository$actionRepository);
  525.         /*
  526.          * Locale en cours
  527.          */
  528.         $locale $loginManager->getLocale();
  529.         $this->data['locale'] = $locale;
  530.         /*
  531.          * On vérifie si l'utilisateur est connecté
  532.          */
  533.         $status $loginManager->isConnecte($nomAction,$paramRepositor,$connexionRepository$actionRepository);
  534.         if ($status['isConnecte']) {
  535.             /*
  536.              * Au cas ou l'utilisateur est connecté on vérifie s'il nest pas innactif. S'il est innactif
  537.              * on garde en mémoire flash la route actuelle pour effectuer une redirection lors de la prochaine connexion
  538.              */
  539.             if ($status['isInnactif']) {
  540.                 $routeName $request->get('_route');
  541.                 $routeParams $request->get('_route_params');
  542.                 $this->get('session')->getFlashBag()->add('restoreUrl'$this->generateUrl($routeName$routeParams));
  543.                 $this->get('session')->getFlashBag()->add('ina'$this->translator->trans("site.long.periode"));
  544.                 return 1// $this->redirect($this->generateUrl('app_logout'));
  545.             }
  546.             /*
  547.              * Seuls les utilisateurs admins ont le droit d'acceder à cette action
  548.              */
  549.             if (!$status['isUser']) {
  550.                 return 1//$this->redirect($this->generateUrl('app_logout'));
  551.             }
  552.         } else {
  553.             return 1//return $this->redirect($this->generateUrl('app_logout'));
  554.         }
  555.         /*
  556.          * Gestion des droits
  557.          */
  558.         if (!$loginManager->getOrSetActions($module$moduledescript$this->getNomClassRun(__CLASS__), $this->description$nomAction$descAction$sessionData['idProfil'], $moduleRepository$controleurRepository$actionRepository$profilRepository$moduleRepository$controleurRepository$actionRepository$profilRepository)) {
  559.             $this->logMessage .= ' [ TENTATIVE DE VIOLATION DE DROITS ] ';
  560.             $this->get('session')->getFlashBag()->add('access'"Vous n'avez pas le droit d'accéder à cette page");
  561.             return 2//$this->redirect($this->generateUrl('app_admin_user_access_refuse'));
  562.         }
  563.         return 0;
  564.     }
  565.     public function getRefCommande(EntityManager $em$type 0$an 0$mois 0$entite 'COMMANDE'$taille 5$four=0) {
  566.         $res '';
  567.         $cp $this->getcompteur($em$type$an$mois$entite$taille$four);
  568.         
  569.         
  570.         ( array_key_exists('compteur'$cp[0])) ? $cp $cp[0]['compteur'] : $cp '';
  571.         
  572.         ($type === 1) ? $res .= 'CDF' $res .= 'CDC';
  573.         
  574.         if ($four == 2) {
  575.             $val "K";
  576.         } else {
  577.             $val "C";
  578.         }
  579.         return $val "" str_pad($cp30STR_PAD_LEFT) . '/' $this->traiteInfoMois($mois) . '/' $an;
  580.     }
  581.     
  582.     public function getRefCommandeSoja(EntityManager $em$type 0$an 0$mois 0$entite 'COMMANDE'$taille 5$four=0) {
  583.         $res '';
  584.         $cp $this->getcompteur($em$type$an$mois$entite$taille$four);
  585.         ( array_key_exists('compteur'$cp)) ? $cp $cp['compteur'] : $cp '';
  586.         ($type === 1) ? $res .= 'CDF' $res .= 'CDC';
  587.         if ($four == 2) {
  588.             $val "S";
  589.         } else {
  590.             $val "S";
  591.         }
  592.         $toutInfoLivrer $em->getRepository($this->stockBundle 'InfoLivrer')->findAll();
  593.         return $val "" count($toutInfoLivrer ) . '/' $this->traiteInfoMois($mois) . '/' $an;
  594.     }
  595.     public function reinitialiserRef(EntityManager $em$type 0$an 0$mois 0$entite 'COMMANDE'$taille 5$four=0) {
  596.         $res '';
  597.         $cp $this->reinitialiser($em$type$an$mois$entite$taille$four);
  598.         return $cp;
  599.     }
  600.     function traiteInfoMois($mois) {
  601.         switch ($mois) {
  602.             case :
  603.                 return "JAN";
  604.             case :
  605.                 return "FEV";
  606.             case :
  607.                 return "MAR";
  608.             case :
  609.                 return "AVR";
  610.             case :
  611.                 return "MAI";
  612.             case :
  613.                 return "JUIN";
  614.             case :
  615.                 return "JUIL";
  616.             case :
  617.                 return "AOU";
  618.             case :
  619.                 return "SEP";
  620.             case 10 :
  621.                 return "OCT";
  622.             case 11 :
  623.                 return "NOV";
  624.             case 12 :
  625.                 return "DEC";
  626.         }
  627.     }
  628.     public function getRefLivrer(EntityManager $em$type 0$an 0$mois 0$entite 'COMMANDE'$taille 5$jour "") {
  629.         $res '';
  630.         $cp $this->getcompteur($em$type$an$mois$entite$taille,0);
  631.         ( array_key_exists('compteur'$cp)) ? $cp $cp['compteur'] : $cp rand(0,999999);
  632.         ($type === 1) ? $res .= 'REC' $res .= 'LIV';
  633.        
  634.         return $res '-' substr($an, -2) . $mois $jour '-' $cp;
  635.     }
  636.     public function getcompteur(EntityManager $em$type 0$an 0$mois 0$entite 'COMMANDE'$taille 5$four) {
  637.         
  638.         try {
  639.             $sqlrech ' SELECT getcompteur(:p_type ,:p_an ,:p_mois ,:p_entite ,:p_taille, :four) as compteur; ';
  640.             $stmt $em->getConnection()->prepare($sqlrech);
  641.             $stmt->bindValue(':p_type'$typePDO::PARAM_INT);
  642.             $stmt->bindValue(':p_an'$anPDO::PARAM_INT);
  643.             $stmt->bindValue(':p_mois'$moisPDO::PARAM_INT);
  644.             $stmt->bindValue(':p_entite'$entitePDO::PARAM_STR);
  645.             $stmt->bindValue(':p_taille'$taillePDO::PARAM_INT);
  646.             $stmt->bindValue(':four'$fourPDO::PARAM_INT);
  647.         
  648.             $result $stmt->executeQuery()->fetchAllAssociative();
  649.             //$stmt->execute();
  650.             //var_dump($stmt);exit;
  651.             $res $result;//$stmt->fetch(PDO::FETCH_ASSOC);
  652.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  653.             $stmt null;
  654.             $res nnull;
  655.             var_dump($e->getMessage());
  656.         }
  657.         return $res;
  658.     }
  659.     public function manageStock(EntityManager $em$id 0$quantite 0$action 0) {
  660.        /* try {
  661.             $sqlrech = ' SELECT getcompteur(:p_id ,:p_quantite,:p_action) as compteur; ';
  662.             $stmt = $em->getConnection()->prepare($sqlrech);
  663.             $stmt->bindValue(':p_id', $id, PDO::PARAM_INT);
  664.             $stmt->bindValue(':p_quantite', $quantite, PDO::PARAM_INT);
  665.             $stmt->bindValue(':p_action', $action, PDO::PARAM_INT);
  666.             $stmt->execute();
  667.             $res = $stmt->fetch(PDO::FETCH_ASSOC);
  668.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  669.             $stmt = null;
  670.             $res = nnull;
  671.             var_dump($e->getMessage());
  672.         }*/
  673.         return 1;
  674.     }
  675.     public function reinitialiser(EntityManager $em$type 0$an 0$mois 0$entite 'COMMANDE'$taille 5$four) {
  676.         try {
  677.             $sqlrech ' SELECT reinitiation(:p_type ,:p_an ,:p_mois ,:p_entite ,:p_taille, :four) as compteur; ';
  678.             $stmt $em->getConnection()->prepare($sqlrech);
  679.             $stmt->bindValue(':p_type'$typePDO::PARAM_INT);
  680.             $stmt->bindValue(':p_an'$anPDO::PARAM_INT);
  681.             $stmt->bindValue(':p_mois'$moisPDO::PARAM_INT);
  682.             $stmt->bindValue(':p_entite'$entitePDO::PARAM_STR);
  683.             $stmt->bindValue(':p_taille'$taillePDO::PARAM_INT);
  684.             $stmt->bindValue(':four'$fourPDO::PARAM_INT);
  685.             $stmt->execute();
  686.             $res $stmt->executeQuery()->fetchAllAssociative();//$stmt->fetch(PDO::FETCH_ASSOC);
  687.             
  688.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  689.             $stmt null;
  690.             $res null;
  691.             var_dump($e->getMessage());
  692.         }
  693.         return $res;
  694.     }
  695.     public function getNumMvt(EntityManager $em$type 0$an 0$mois 0$entite 'COMMANDE'$taille 5) {
  696.         $res '';
  697.         $cp $this->getcompteur($em$type$an$mois$entite$taille1);
  698.         ( array_key_exists('compteur'$cp)) ? $cp $cp['compteur'] : $cp '';
  699.         ($type === 1) ? $res .= 'MVT' $res .= 'MVT';
  700.         return $res '' substr($an, -2) . $mois '' $cp;
  701.     }
  702.     public function initialiserAncienPrixZero(EntityManager $em$idProduit 0) {
  703.         try {
  704.             $sqlrech ' UPDATE prix_rigueur set etat_prix = 0 where produit_id =:produitId ';
  705.            // var_dump($sqlrech, $idProduit);exit;
  706.             $stmt $em->getConnection()->prepare($sqlrech);
  707.             $stmt->bindValue(':produitId'$idProduitPDO::PARAM_INT);
  708.             $stmt->execute();
  709.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  710.             $stmt null;
  711.             $res null;
  712.             var_dump($e->getMessage());
  713.         }
  714.         return 1;
  715.     }
  716.     public function initialiserLesAncienPolygon(EntityManager $em$surfaceanneeId0$typeLocalisation) {
  717.         try {
  718.             $sqlrech ' UPDATE localisation set etat_localisation = 2 where surfaceannee_id =:surfaceanneeId AND type_localisation =:typeLocalisation ';
  719.            // var_dump($sqlrech, $idProduit);exit;
  720.             $stmt $em->getConnection()->prepare($sqlrech);
  721.             $stmt->bindValue(':surfaceanneeId'$surfaceanneeIdPDO::PARAM_INT);
  722.             $stmt->bindValue(':typeLocalisation'$typeLocalisationPDO::PARAM_INT);
  723.             $stmt->execute();
  724.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  725.             $stmt null;
  726.             $res null;
  727.             var_dump($e->getMessage());
  728.         }
  729.         return 1;
  730.     }
  731.     public function initialiserSeTrouver(EntityManager $em$fournisseurId 0) {
  732.         try {
  733.             $sqlrech ' UPDATE se_trouver set etat_se_trouver = 0 where fournisseur_id =:fournisseurId ';
  734.            // var_dump($sqlrech, $idProduit);exit;
  735.             $stmt $em->getConnection()->prepare($sqlrech);
  736.             $stmt->bindValue(':fournisseurId'$fournisseurIdPDO::PARAM_INT);
  737.             $stmt->execute();
  738.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  739.             $stmt null;
  740.             $res null;
  741.             var_dump($e->getMessage());
  742.         }
  743.         return 1;
  744.     }
  745.     public function initialiserInspectionRempli(EntityManager $em$inspectionId 0$surfaceAnneeId=0) {
  746.         try {
  747.             $sqlrech ' UPDATE inspection_rempli set etat_fournisseur_producteur = 0 where surfaceannee_id =:surfaceAnneeId AND inspection_id =:inspectionId ';
  748.            // var_dump($sqlrech, $idProduit);exit;
  749.             $stmt $em->getConnection()->prepare($sqlrech);
  750.             $stmt->bindValue(':inspectionId'$inspectionIdPDO::PARAM_INT);
  751.             $stmt->bindValue(':surfaceAnneeId'$surfaceAnneeIdPDO::PARAM_INT);
  752.             $stmt->execute();
  753.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  754.             $stmt null;
  755.             $res null;
  756.             var_dump($e->getMessage());
  757.         }
  758.         return 1;
  759.     }
  760.     public function updatePageTemplate(EntityManager $em$abonneId$ancienTemplate 0$nouveauTemplate) {
  761.         try {
  762.             $sqlrech ' UPDATE page set template_id =:nouveauTemplate  where template_id =:ancienTemplate and abonne_id =:abonneId ';
  763.            // var_dump($sqlrech, $idProduit);exit;
  764.             $stmt $em->getConnection()->prepare($sqlrech);
  765.             $stmt->bindValue(':nouveauTemplate'$nouveauTemplatePDO::PARAM_INT);
  766.             $stmt->bindValue(':ancienTemplate'$ancienTemplatePDO::PARAM_INT);
  767.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  768.             $stmt->execute();
  769.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  770.             $stmt null;
  771.             $res null;
  772.             var_dump($e->getMessage());
  773.         }
  774.         return 1;
  775.     }
  776.     public function updateParcelle(EntityManager $em$abonneId$producteurId =0) {
  777.         try {
  778.             $sqlrech ' UPDATE surface_annee set etat_surface_annee =:etatSupprime  where producteur_id =:producteurId and abonne_id =:abonneId ';
  779.            // var_dump($sqlrech, $idProduit);exit;
  780.             $stmt $em->getConnection()->prepare($sqlrech);
  781.             $stmt->bindValue(':etatSupprime'2PDO::PARAM_INT);
  782.             $stmt->bindValue(':producteurId'$producteurIdPDO::PARAM_INT);
  783.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  784.             $stmt->execute();
  785.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  786.             $stmt null;
  787.             $res null;
  788.             var_dump($e->getMessage());
  789.         }
  790.         return 1;
  791.     }
  792.     public function initialiserToutIspectionApresAjour(EntityManager $em$abonneId 0$type=0) {
  793.         try {
  794.             $sqlrech ' UPDATE inspection set si_apres_ajout = 0 where abonne_id =:abonneId  and type_inspection =:typeinspection';
  795.            // var_dump($sqlrech, $idProduit);exit;
  796.             $stmt $em->getConnection()->prepare($sqlrech);
  797.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  798.             $stmt->bindValue(':typeinspection'$typePDO::PARAM_INT);
  799.             $stmt->execute();
  800.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  801.             $stmt null;
  802.             $res null;
  803.             var_dump($e->getMessage());
  804.         }
  805.         return 1;
  806.     }
  807.     public function initialiserInspectionSuivant(EntityManager $em$abonneId 0$inspectionId=0) {
  808.         try {
  809.             $sqlrech ' UPDATE inspection set si_apres_ajout = 0 where abonne_id =:abonneId  and id =:inspectionId';
  810.            // var_dump($sqlrech, $idProduit);exit;
  811.             $stmt $em->getConnection()->prepare($sqlrech);
  812.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  813.             $stmt->bindValue(':inspectionId'$inspectionIdPDO::PARAM_INT);
  814.             $stmt->execute();
  815.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  816.             $stmt null;
  817.             $res null;
  818.             var_dump($e->getMessage());
  819.         }
  820.         return 1;
  821.     }
  822.     public function supprimerSurfaceAnnee(EntityManager $em) {
  823.         try {
  824.             $sqlrech ' UPDATE 
  825.             producteur p, surface_annee s  SET s.etat_surface_annee = 2
  826.             WHERE  p.id = s.producteur_id  and  p.etat_prod = 2 ';
  827.            // var_dump($sqlrech, $idProduit);exit;
  828.             $stmt $em->getConnection()->prepare($sqlrech);
  829.             //$stmt->bindValue(':produitId', $idProduit, PDO::PARAM_INT);
  830.             $stmt->execute();
  831.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  832.             $stmt null;
  833.             $res null;
  834.             var_dump($e->getMessage());
  835.         }
  836.         return 1;
  837.     }
  838.    
  839.     public function supprimerInspectionRempliSurface(EntityManager $em) {
  840.         try {
  841.             $sqlrech ' UPDATE 
  842.             surface_annee s, inspection_rempli r SET r.etat_fournisseur_producteur = 2
  843.             WHERE  s.id = r.surfaceannee_id  and  s.etat_surface_annee = 2
  844.             ';
  845.            // var_dump($sqlrech, $idProduit);exit;
  846.             $stmt $em->getConnection()->prepare($sqlrech);
  847.             //$stmt->bindValue(':produitId', $idProduit, PDO::PARAM_INT);
  848.             $stmt->execute();
  849.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  850.             $stmt null;
  851.             $res null;
  852.             var_dump($e->getMessage());
  853.         }
  854.         return 1;
  855.     }
  856.     public function supprimerInspectionRempliProducteur(EntityManager $em) {
  857.         try {
  858.             $sqlrech ' UPDATE 
  859.             producteur p, inspection_rempli r SET r.etat_fournisseur_producteur = 2
  860.             WHERE  p.id = r.surfaceannee_id  and  p.etat_prod = 2
  861.             ';
  862.            // var_dump($sqlrech, $idProduit);exit;
  863.             $stmt $em->getConnection()->prepare($sqlrech);
  864.             //$stmt->bindValue(':produitId', $idProduit, PDO::PARAM_INT);
  865.             $stmt->execute();
  866.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  867.             $stmt null;
  868.             $res null;
  869.             var_dump($e->getMessage());
  870.         }
  871.         return 1;
  872.     }
  873.     public function initialiserSuiviHistoriqueCommande(EntityManager $em$oldId=0$lnewId=0$produitId=0) {
  874.         try {
  875.             $sqlrech ' UPDATE lignecommande set suivi_historique = :lnewId where suivi_historique = :oldId and produit_id =:produitId  ';
  876.            // var_dump($sqlrech, $idProduit);exit;
  877.             $stmt $em->getConnection()->prepare($sqlrech);
  878.             $stmt->bindValue(':oldId'$oldIdPDO::PARAM_INT);
  879.             $stmt->bindValue(':lnewId'$lnewIdPDO::PARAM_INT);
  880.             $stmt->bindValue(':produitId'$produitIdPDO::PARAM_INT);
  881.             $stmt->execute();
  882.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  883.             $stmt null;
  884.             $res null;
  885.             var_dump($e->getMessage());
  886.         }
  887.         return 1;
  888.     }
  889.     public function initialiserCommandeSuivant(EntityManager $em$oldId=0$produitId=0$ligneCommandeId) {
  890.         try {
  891.             $sqlrech ' UPDATE lignecommande set suivant_commande = :ligneCommandeId where suivi_historique = :oldId and produit_id =:produitId  ';
  892.            // var_dump($sqlrech, $idProduit);exit;
  893.             $stmt $em->getConnection()->prepare($sqlrech);
  894.             $stmt->bindValue(':oldId'$oldIdPDO::PARAM_INT);
  895.             $stmt->bindValue(':ligneCommandeId'$ligneCommandeIdPDO::PARAM_INT);
  896.             $stmt->bindValue(':produitId'$produitIdPDO::PARAM_INT);
  897.             $stmt->execute();
  898.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  899.             $stmt null;
  900.             $res null;
  901.             var_dump($e->getMessage());
  902.         }
  903.         return 1;
  904.     }
  905.     public function deleteCommandeTmp(EntityManager $em$clientId 0) {
  906.         try {
  907.             $sqlrech ' DELETE  FROM commandetmp  where client_id =:clientId ';
  908.            // var_dump($sqlrech, $idProduit);exit;
  909.             $stmt $em->getConnection()->prepare($sqlrech);
  910.             $stmt->bindValue(':clientId'$clientIdPDO::PARAM_INT);
  911.             $stmt->execute();
  912.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  913.             $stmt null;
  914.             $res null;
  915.             var_dump($e->getMessage());
  916.         }
  917.         //var_dump($clientId );exit;
  918.         return 1;
  919.     }
  920.     public function deleteLigneCommandeTmp(EntityManager $em$clientId 0) {
  921.         try {
  922.             $sqlrech ' DELETE FROM lignecommandetmp  where client_id =:clientId ';
  923.            // var_dump($sqlrech, $idProduit);exit;
  924.             $stmt $em->getConnection()->prepare($sqlrech);
  925.             $stmt->bindValue(':clientId'$clientIdPDO::PARAM_INT);
  926.             $stmt->execute();
  927.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  928.             $stmt null;
  929.             $res null;
  930.             var_dump($e->getMessage());
  931.         }
  932.         return 1;
  933.     }
  934.     public function initialiserVille(EntityManager $em) {
  935.         try {
  936.             $sqlrech ' UPDATE ville set etat_ville= 3  ';
  937.            // var_dump($sqlrech, $idProduit);exit;
  938.             $stmt $em->getConnection()->prepare($sqlrech);
  939.             
  940.             $stmt->execute();
  941.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  942.             $stmt null;
  943.             $res null;
  944.             var_dump($e->getMessage());
  945.         }
  946.         return 1;
  947.     }
  948.     
  949.      public function initialisePreparationPayement(EntityManager $em) {
  950.         try {
  951.             $sqlrech ' UPDATE info_livrer set etat_payement = 0';
  952.             $stmt $em->getConnection()->prepare($sqlrech);
  953.             
  954.             $stmt->execute();
  955.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  956.             $stmt null;
  957.             $res null;
  958.             var_dump($e->getMessage());
  959.         }
  960.         return 1;
  961.     }
  962.        
  963.     public function initialiserAnneeCampagne(EntityManager $em$idProduit 0){
  964.         try {        
  965.                 $sqlrech ' UPDATE annee_campagne set etat_annee = 0 where produit_id = :produitId ';           
  966.                 $stmt $em->getConnection()->prepare($sqlrech);
  967.                 $stmt->bindValue(':produitId'$idProduitPDO::PARAM_INT);
  968.                 $stmt->execute();
  969.                 //var_dump(1);exit;
  970.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  971.                 $stmt null;
  972.                 $res null;
  973.                 var_dump($e->getMessage()) ;
  974.         } 
  975.         
  976.        return 1;
  977.     } 
  978.     public function initialiserInventaire(EntityManager $em$idProduit 0){
  979.         try {        
  980.                 $sqlrech ' UPDATE inventaire set etat_inventaire = 0 where produit_id = :produitId ';           
  981.                 $stmt $em->getConnection()->prepare($sqlrech);
  982.                 $stmt->bindValue(':produitId'$idProduitPDO::PARAM_INT);
  983.                 $stmt->execute();
  984.                 //var_dump(1);exit;
  985.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  986.                 $stmt null;
  987.                 $res null;
  988.                 var_dump($e->getMessage()) ;
  989.         } 
  990.         
  991.        return 1;
  992.     } 
  993.     
  994.     
  995.     
  996.     
  997.     public function initialiserAncienConteneurZero(EntityManager $em) {
  998.         try {
  999.             $sqlrech ' UPDATE conteneur set etat_conteneur = 0  ';
  1000.             $stmt $em->getConnection()->prepare($sqlrech);
  1001.             $stmt->execute();
  1002.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  1003.             $stmt null;
  1004.             $res null;
  1005.             var_dump($e->getMessage());
  1006.         }
  1007.         return 1;
  1008.     }
  1009.     public function calculerStatCommande($listeCommande) {
  1010.         foreach ($listeCommande as $uneCommande) {
  1011.             $statTab['quantiteTotal'] = $statTab['quantiteTotal'] + $uneCommande->getLignecommandes()[0]->getQuantite();
  1012.             $statTab['quantiteTotalLivre'] = $statTab['quantiteTotalLivre'] + $uneCommande->getLignecommandes()[0]->getQuantiteLivre();
  1013.             // 
  1014.             // var_dump($uneCommande->getLignecommandes()[0]->getId());
  1015.         }
  1016.         $statTab['pourcentage'] = intval(($statTab['quantiteTotalLivre'] / $statTab['quantiteTotal']) * 100);
  1017.         return $statTab;
  1018.     }
  1019.     function traiterDateFormat($date) {
  1020.         $tabDate = array();
  1021.         $tabdateWithHour explode(' ',  $date);
  1022.         $tabDate array_reverse(explode('-'str_replace("/""-"$tabdateWithHour[0])));
  1023. //        $tabDateOrd[0]=$tabDate[0];
  1024. //        $tabDateOrd[1]=$tabDate[2];
  1025. //        $tabDateOrd[2]=$tabDate[1];
  1026. //        var_dump($tabDate);exit;
  1027.         return $tabDate;
  1028.     }
  1029.    
  1030.     function getDateFormat($date) {
  1031.         $tabDate = array();
  1032.         $tabdateWithHour explode(' ',  $date);
  1033.         $tabDate array_reverse(explode('-'str_replace("/""-"$tabdateWithHour[0])));
  1034. //        $tabDateOrd[0]=$tabDate[0];
  1035. //        $tabDateOrd[1]=$tabDate[2];
  1036. //        $tabDateOrd[2]=$tabDate[1];
  1037. //        var_dump($tabDate);exit;
  1038.         return $tabDate[0]."-".$tabDate[1]."-".$tabDate[2]." ".$tabdateWithHour[1] ;
  1039.     }
  1040.     function affichageCorrectDate($date) {
  1041.         $tabDate = array();
  1042.         $tabDate array_reverse(explode('-'$date));
  1043.         $tabDateOrd[0] = $tabDate[1];
  1044.         $tabDateOrd[1] = $tabDate[2];
  1045.         $tabDateOrd[2] = $tabDate[0];
  1046.         //var_dump($tabDateOrd);exit;
  1047.         return implode("/"$tabDateOrd);
  1048.     }
  1049.     function dateDuPremierDuMois($dateJour) {
  1050.         $datedebMois $dateJour->format("m");
  1051.         $datedebYear $dateJour->format("Y");
  1052.         return new \DateTime($datedebMois "/01/" $datedebYear);
  1053.     }
  1054.     public function bloquerFournisseur($em$montantRestant$montantSessionData$id$fournisseurRepository) {
  1055.         if ($montantRestant $montantSessionData) {
  1056.             $objetFournisseur $fournisseurRepository->find($id);
  1057.             $objetFournisseur->setEtatFournisseur(TypeEtat::INACTIF);
  1058.             $em->persist($objetFournisseur);
  1059.             $em->flush();
  1060.             return true;
  1061.         } else {
  1062.             return false;
  1063.         }
  1064.     }
  1065.     public function activerFournisseur($em$montantRestant$montantSessionData$id$fournisseurRepository) {
  1066.         if ($montantRestant $montantSessionData) {
  1067.             $objetFournisseur $fournisseurRepository->find($id);
  1068.             $objetFournisseur->setEtatFournisseur(TypeEtat::ACTIF);
  1069.             $em->persist($objetFournisseur);
  1070.             $em->flush();
  1071.             return true;
  1072.         } else {
  1073.             return false;
  1074.         }
  1075.     }
  1076.     public function genereLigneSuivieLivraison($em$zone$montant$typeOperation$institule$objetOperation$objetInfoLivrer) {
  1077.         $objetSuivieLivraison = new SuivieLivraison();
  1078.         $objetSuivieLivraison->setInfolivrer($objetInfoLivrer);
  1079.         $objetSuivieLivraison->setOperation($objetOperation);
  1080.         $objetSuivieLivraison->setTypeoperation($typeOperation);
  1081.         $objetSuivieLivraison->setMontant($montant);
  1082.         $objetSuivieLivraison->setInstitule($institule);
  1083.         $objetSuivieLivraison->setVille($zone);
  1084.         $em->persist($objetSuivieLivraison);
  1085.         $em->flush();
  1086.         return true;
  1087.     }
  1088.     public function getParamLivraisonDate($em$idParamSystDateRepository $paramSystDateRepository) {
  1089.         $unParam $paramSystDateRepository->find($id);
  1090.         if($unParam !=null){
  1091.             $dateChoisi $unParam->getDateParam();
  1092.         }else{
  1093.             $dateChoisi = new \DateTime(); 
  1094.         }
  1095.         
  1096.         return $dateChoisi->format("d/m/Y");
  1097.     }
  1098.     public function traiteCommande($em$tempIds$prixLimiteCacao$typeaction 1$fournisseurRepository,$commandeRepository ) {
  1099.         $oneOk false;
  1100.         $rep = array();
  1101.         $rep['quantiteTotal'] = 1;
  1102.         $rep['quantiteTotalLivre'] = 1;
  1103.         $rep['montantTotal'] = 1;
  1104.         $rep['montantTotalLivre'] = 1;
  1105.         $detailFournisseur $fournisseurRepository->find($tempIds);
  1106.         $rep['nomFournisseur'] = $detailFournisseur->getNomFournisseur();
  1107.         $rep['id'] = $detailFournisseur->getId();
  1108.         $rep['contactFournisseur'] = $detailFournisseur->getContactFournisseur();
  1109.         $listeCommande $commandeRepository->getUtilisateurCommande($tempIds);
  1110.         $quantite 0;
  1111.         $quantiteLivre 0;
  1112.         $prix 0;
  1113.         foreach ($listeCommande as $uneCommande) {
  1114.             if($uneCommande->getLignecommandes()[0] != null){
  1115.                 $quantite $uneCommande->getLignecommandes()[0]->getQuantite();
  1116.                 $quantiteLivre  $uneCommande->getLignecommandes()[0]->getQuantiteLivre();
  1117.                 $prix $uneCommande->getLignecommandes()[0]->getPrixRigueur()->getInfoPrixRigueur();
  1118.             }
  1119.             $rep['quantiteTotal'] = $rep['quantiteTotal'] + $quantite;
  1120.             $rep['quantiteTotalLivre'] = $rep['quantiteTotalLivre'] + $quantiteLivre ;
  1121.             $montantTotal $quantite $prix;
  1122.             $montantTotalLivre $quantiteLivre  $prix;
  1123. // var_dump($uneCommande->getLignecommandes()[0]->getId());
  1124.             $rep['montantTotal'] = $rep['montantTotal'] + $montantTotal;
  1125.             $rep['montantTotalLivre'] = $rep['montantTotalLivre'] + $montantTotalLivre;
  1126.         }
  1127.         $rep['pourcentage'] = intval(($rep['quantiteTotalLivre'] / $rep['quantiteTotal']) * 100);
  1128.         $rep['resteLivre'] = $rep['quantiteTotal'] - $rep['quantiteTotalLivre'];
  1129.         $rep['montantRestant'] = $rep['montantTotal'] - $rep['montantTotalLivre'];
  1130.         $prixLimiteCacao $detailFournisseur->getCreditFournisseur() + $detailFournisseur->getDepassementFournisseur();
  1131.         /*
  1132.          * variable boolean initialisé a false .elle va être modifier à true si tout se passe bien
  1133.          */
  1134.         if ($typeaction == 1) {
  1135.             $actionFournisseur $this->activerFournisseur($em$rep['montantRestant'], $prixLimiteCacao$tempIds,  $fournisseurRepository);
  1136.         } else {
  1137.             $actionFournisseur $this->bloquerFournisseur($em$rep['montantRestant'], $prixLimiteCacao$tempIds);
  1138.         }
  1139.         if ($actionFournisseur) {
  1140.             $rep['msg'] = 'bloque';
  1141.             $rep['montantDu'] = $rep['montantRestant'];
  1142.             $rep['montantAccepte'] = $prixLimiteCacao;
  1143.         } else {
  1144.             if ($oneOk) {
  1145. //                    $this->flashMessage->add('fournisseur.gerer.success', $this->translator->trans("site.ajouter.succes"));
  1146.                 $rep['msg'] = '';
  1147.                 $rep['etat'] = true;
  1148.             }
  1149.         }
  1150.         return $rep;
  1151.     }
  1152.     public function getInfoAvcanceFournisseur($em$tempIds) {
  1153.         $oneOk false;
  1154.         $rep = array();
  1155.         $rep['quantiteTotal'] = 1;
  1156.         $rep['quantiteTotalLivre'] = 1;
  1157.         $rep['montantTotal'] = 1;
  1158.         $rep['montantTotalLivre'] = 1;
  1159.         $detailFournisseur $em->getRepository($this->stockBundle 'Fournisseur')->find($tempIds);
  1160.         $rep['nomFournisseur'] = $detailFournisseur->getNomFournisseur();
  1161.         $rep['id'] = $detailFournisseur->getId();
  1162.         $rep['contactFournisseur'] = $detailFournisseur->getContactFournisseur();
  1163.         $listeCommande $em->getRepository($this->stockBundle 'Commande')->getUtilisateurCommande($tempIds);
  1164.         $infoSurPlus $em->getRepository($this->stockBundle 'SurPlus')->findOneBy(array("fournisseur" => $detailFournisseur));
  1165.         $quantite 0;
  1166.         $quantiteLivre 0;
  1167.         $prix 0;
  1168.         foreach ($listeCommande as $uneCommande) {
  1169.            if($uneCommande->getLignecommandes()[0] != null){
  1170.                 $quantite $uneCommande->getLignecommandes()[0]->getQuantite();
  1171.                 $quantiteLivre  $uneCommande->getLignecommandes()[0]->getQuantiteLivre();
  1172.                 $prix $uneCommande->getLignecommandes()[0]->getPrixRigueur()->getInfoPrixRigueur();
  1173.             }
  1174.        
  1175.             $rep['quantiteTotal'] = $rep['quantiteTotal'] + $quantite;
  1176.             $rep['quantiteTotalLivre'] = $rep['quantiteTotalLivre'] +$quantiteLivre ;
  1177.             $montantTotal $quantite $prix;
  1178.             $montantTotalLivre $quantite $prix;
  1179.             $rep['montantTotal'] = $rep['montantTotal'] + $montantTotal;
  1180.             $rep['montantTotalLivre'] = $rep['montantTotalLivre'] + $montantTotalLivre;
  1181.         }
  1182.         $prixR $em->getRepository($this->stockBundle 'PrixRigueur')->getActifPrixRigueur();
  1183.         $nombreInfoLi 0;
  1184.         $montantInfoLi 0;
  1185.         if ($infoSurPlus != null  ) {
  1186.             $nombreInfoLi $infoSurPlus->getQuantite();
  1187.             $montantInfoLi $prixR[0]->getInfoPrixRigueur() * $nombreInfoLi;
  1188.         }
  1189.         $rep['quantiteTotalLivre'] = $rep['quantiteTotalLivre'] + $nombreInfoLi;
  1190.         $rep['montantTotalLivre'] = $rep['montantTotalLivre'] + $montantInfoLi;
  1191.         $rep['pourcentage'] = intval(($rep['quantiteTotalLivre'] / $rep['quantiteTotal']) * 100);
  1192.         $rep['resteLivre'] = $rep['quantiteTotal'] - $rep['quantiteTotalLivre'];
  1193.         $rep['montantRestant'] = $rep['montantTotal'] - $rep['montantTotalLivre'];
  1194.         //var_dump(1);exit;
  1195.         if ($oneOk) {
  1196. //                    $this->flashMessage->add('fournisseur.gerer.success', $this->translator->trans("site.ajouter.succes"));
  1197.             $rep['msg'] = '';
  1198.             $rep['etat'] = true;
  1199.         }
  1200.         return $rep;
  1201.     }
  1202.     public function RecuperCritereRecherche($em$nomcol$datefin$datedeb$ville$util$silivre$numcom) {
  1203.         if ($datedeb == && $datefin == 0) {
  1204.             $dateJour = new \DateTime();
  1205.             $premierDate $this->dateDuPremierDuMois($dateJour);
  1206.             $datedeb $premierDate->format("d/m/Y");
  1207.             $dateMoi $premierDate->add(new DateInterval('P1M'));
  1208.             $datefin $dateMoi->format("d/m/Y");
  1209.         }
  1210.         $tabRetour = array();
  1211.         if ($nomcol != 0) {
  1212.             $objetCollecteur $em->getRepository($this->stockBundle 'Fournisseur')->find($nomcol);
  1213.             $tabRetour['nomCollecteur'] = $objetCollecteur->getNomFournisseur();
  1214.         } else {
  1215.             $tabRetour['nomCollecteur'] = '-';
  1216.         }
  1217.         if ($ville != 0) {
  1218.             $objetVille $em->getRepository($this->stockBundle 'Ville')->find($ville);
  1219.             $tabRetour['nomVille'] = $objetVille->getNomVille();
  1220.         } else {
  1221.             $tabRetour['nomVille'] = '-';
  1222.         }
  1223.         if ($util != 0) {
  1224.             $objetUtil $em->getRepository($this->userBundle 'Utilisateur')->find($util);
  1225.             $tabRetour['nomGerant'] = $objetUtil->getNom();
  1226.         } else {
  1227.             $tabRetour['nomGerant'] = '-';
  1228.         }
  1229.         if ($silivre != 0) {
  1230.             if ($silivre == 1) {
  1231.                 $tabRetour['livre'] = 'Non Livrée';
  1232.             } elseif ($silivre == 2) {
  1233.                 $tabRetour['livre'] = 'Livr. partielle';
  1234.             } elseif ($silivre == 3) {
  1235.                 $tabRetour['livre'] = 'Livr. totale';
  1236.             } else {
  1237.                 $tabRetour['livre'] = 'livr. partielle|totale';
  1238.             }
  1239.         } else {
  1240.             $tabRetour['livre'] = '-';
  1241.         }
  1242.         if ($numcom != 0) {
  1243.             $tabRetour['codeCommande'] = $numcom;
  1244.         } else {
  1245.             $tabRetour['codeCommande'] = '-';
  1246.         }
  1247.         //var_dump($datedeb);exit;
  1248.         $tabRetour['dateDebut'] = $datedeb//$this->affichageCorrectDate($datedeb);
  1249.         $tabRetour['dateFin'] = $datefin//$this->affichageCorrectDate($datefin);
  1250.         return $tabRetour;
  1251.     }
  1252.     public function RecuperCritereRechercheSuivie($em$datefin$datedeb$ville) {
  1253.         if ($datedeb == && $datefin == 0) {
  1254.             $dateJour = new \DateTime();
  1255.             $premierDate $this->dateDuPremierDuMois($dateJour);
  1256.             $datedeb $premierDate->format("d/m/Y");
  1257.             $dateMoi $premierDate->add(new DateInterval('P1M'));
  1258.             $datefin $dateMoi->format("d/m/Y");
  1259.         }
  1260.         $tabRetour = array();
  1261.         if ($ville != 0) {
  1262.             $objetVille $em->getRepository($this->stockBundle 'Ville')->find($ville);
  1263.             $tabRetour['nomVille'] = $objetVille->getNomVille();
  1264.         } else {
  1265.             $tabRetour['nomVille'] = '-';
  1266.         }
  1267.         $tabRetour['dateDebut'] = $datedeb//$this->affichageCorrectDate($datedeb);
  1268.         $tabRetour['dateFin'] = $datefin//$this->affichageCorrectDate($datefin);
  1269.         return $tabRetour;
  1270.     }
  1271.     public function upDateSurPlus($em$nomCollecteur$quantite$fournisseurRepository,$surplusRepository ) {
  1272.         //objet collecteur
  1273.         $criteria = array('codeFournisseur' => $nomCollecteur);
  1274.         $unFournisseur $fournisseurRepository->findOneBy($criteria);
  1275.         //Information sur le surplus
  1276.         $criteriaSurplus = array('fournisseur' => $unFournisseur);
  1277.         $objetSurplus $surplusRepository->findOneBy($criteriaSurplus);
  1278.         if ($objetSurplus == null) {
  1279.             $objetSurplus = new SurPlus();
  1280.         }
  1281.         $objetSurplus->setQuantite($quantite);
  1282.         $objetSurplus->setFournisseur($unFournisseur);
  1283.         $objetSurplus->setDatePublication(new \DateTime());
  1284.         $em->persist($objetSurplus);
  1285.         $em->flush();
  1286.         return $objetSurplus;
  1287.     }
  1288.     public function recupererSurPlus($em$nomCollecteur$fournisseurRepository,$surplusRepository ) {
  1289.         //objet collecteur
  1290.         $criteria = array('codeFournisseur' => $nomCollecteur);
  1291.         $unFournisseur $fournisseurRepository->findOneBy($criteria);
  1292.         //Information sur le surplus
  1293.         $criteriaSurplus = array('fournisseur' => $unFournisseur);
  1294.         $objetSurplus $surplusRepository->findOneBy($criteriaSurplus);
  1295.         if ($objetSurplus == null) {
  1296.             $quantite 0;
  1297.         } else {
  1298.             $quantite $objetSurplus->getQuantite();
  1299.         }
  1300.         return $quantite;
  1301.     }
  1302.     
  1303.     
  1304.       public function saveSurfaceAnnee($em,$objetSurfaceAnnee,$objetAnneeCampagne,$objetSurface,$objetProduit,$objetProducteur,$codeGenere){
  1305.     
  1306.         $objetSurfaceAnnee->setAnneecampagne($objetAnneeCampagne);
  1307.         $objetSurfaceAnnee->setSurface($objetSurface);
  1308.         $objetSurfaceAnnee->setProduit($objetProduit);    
  1309.         $objetSurfaceAnnee->setCodeGenere($codeGenere);
  1310.         $objetSurfaceAnnee->setProducteur($objetProducteur);    
  1311.         $em->persist($objetSurfaceAnnee);
  1312.         $em->flush($objetSurfaceAnnee);
  1313.         
  1314.         return  $objetSurfaceAnnee;
  1315.         
  1316.     }
  1317.     
  1318.     public function getStringSqlVille($niveau){
  1319.         
  1320.         $sql "";
  1321.         $j=0;
  1322.         for($i=1$i<=$niveau$i++){           
  1323.             if($i==1){
  1324.                 $sql .=" LEFT JOIN p.ville v".$i;
  1325.             }else{
  1326.                 $sql .=" LEFT JOIN v".$j.".ville v".$i;
  1327.             }
  1328.             $j=$i;
  1329.         }
  1330.         
  1331.         
  1332.         $sqlCond ="";
  1333.         
  1334.         
  1335.         $sqlCond .=" AND v".$niveau.".id = :ville";
  1336.         
  1337.         $tab[0]= $sql
  1338.         $tab[1]= $sqlCond;
  1339.          
  1340.         return $tab;
  1341.         
  1342.     }
  1343.     
  1344.     public function initialiserIntentionSemence(EntityManager $em) {
  1345.         try {
  1346.             $sqlrech ' UPDATE  producteur set si_intention = 1 , si_semence = 1 ';
  1347.             $stmt $em->getConnection()->prepare($sqlrech);
  1348.             $stmt->bindValue(':prod'$prodPDO::PARAM_INT);
  1349.             $stmt->execute();
  1350.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  1351.             $stmt null;
  1352.             $res null;
  1353.             var_dump($e->getMessage());
  1354.         }
  1355.         return 1;
  1356.     }
  1357.     public function addHistoriqueAction($em$info$operation$codeGenere$utilisateur$producteurId$plateforme$donneeUtilisateurRepository $utilisateurRepository) {
  1358.         //Objet Utilisateur
  1359.         $objetUtilisateur $utilisateurRepository->find($utilisateur);
  1360.        
  1361.         //Objet Producteur
  1362.         //$objetProducteur = $em->getRepository($this->prodBundle . 'Producteur')->find($producteurId);             
  1363.         $objetHistoriqueAction = new HistoriqueAction();
  1364.         //$objetHistoriqueAction->setProducteur($objetProducteur);
  1365.         if($objetUtilisateur !=null){
  1366.             $objetHistoriqueAction->setUtilisateur($objetUtilisateur);
  1367.             $objetHistoriqueAction->setAbonne($objetUtilisateur->getAbonne());
  1368.         }
  1369.         $objetHistoriqueAction->setInfoTable($info);
  1370.         $objetHistoriqueAction->setOperation($operation);
  1371.         $objetHistoriqueAction->setCodeGenere($codeGenere);
  1372.         $objetHistoriqueAction->setDonnee($donnee);
  1373.         $objetHistoriqueAction->setTypePlateforme($plateforme);
  1374.         $em->persist($objetHistoriqueAction);
  1375.         $em->flush();
  1376.         //var_dump($info);exit;
  1377.         return true;
  1378.     }
  1379.     public function addHistoriqueAgentAction($em$info$operation$codeGenere$utilisateur$producteurId$plateforme$donnee,$agentIdUtilisateurRepository $utilisateurRepository$fournisseurRepository) {
  1380.         //Objet Utilisateur
  1381.         $objetUtilisateur $utilisateurRepository->find($utilisateur);
  1382.         $objetFournisseur $fournisseurRepository->find($agentId);
  1383.         //Objet Producteur
  1384.         //$objetProducteur = $em->getRepository($this->prodBundle . 'Producteur')->find($producteurId);             
  1385.         $objetHistoriqueAction = new HistoriqueAction();
  1386.         
  1387.         //$objetHistoriqueAction->setProducteur($objetProducteur);
  1388.         if($objetUtilisateur !=null){
  1389.             
  1390.             $objetHistoriqueAction->setUtilisateur($objetUtilisateur);
  1391.             $objetHistoriqueAction->setAbonne($objetUtilisateur->getAbonne());
  1392.         }
  1393.         
  1394.         $objetHistoriqueAction->setInfoTable($info);
  1395.         $objetHistoriqueAction->setOperation($operation);
  1396.         $objetHistoriqueAction->setFournisseur($objetFournisseur);
  1397.         $objetHistoriqueAction->setCodeGenere($codeGenere);
  1398.         $objetHistoriqueAction->setDonnee($donnee);
  1399.         $objetHistoriqueAction->setTypePlateforme($plateforme);
  1400.         $em->persist($objetHistoriqueAction);
  1401.         $em->flush();
  1402.         //var_dump($info);exit;
  1403.         return true;
  1404.     }
  1405.     public function getHistoriqueAction(EntityManager $em,$abonneId,$etat$datesych) {
  1406.         try {
  1407.             $sqlrech 'SELECT info_table as infoTable, operation, codeGenere, donnee FROM  historique_action WHERE abonne_id =:abonneId  and  date_publication >=:datesych and operation = 1 '//
  1408.            // $sqlrech .= ' SELECT id FROM historique_action_utilisateur WHERE 1=1 )';
  1409.             $stmt $em->getConnection()->prepare($sqlrech);
  1410.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  1411.             $stmt->bindValue(':datesych'$datesychPDO::PARAM_STR);
  1412.             
  1413.             $stmt->execute();
  1414.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  1415.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  1416.             $stmt null;
  1417.             $res null;
  1418.             var_dump($e->getMessage());
  1419.         }
  1420.         return $res;
  1421.     }
  1422.     public function getHistoriqueAgentAction(EntityManager $em,$abonneId,$etat$datesych) {
  1423.         try {
  1424.             $sqlrech 'SELECT info_table as infoTable, operation, codeGenere, donnee FROM  historique_action WHERE abonne_id =:abonneId  and  date_publication >=:datesych and operation = 2 '//
  1425.            // $sqlrech .= ' SELECT id FROM historique_action_utilisateur WHERE 1=1 )';
  1426.             $stmt $em->getConnection()->prepare($sqlrech);
  1427.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  1428.             $stmt->bindValue(':datesych'$datesychPDO::PARAM_STR);
  1429.             
  1430.             $stmt->execute();
  1431.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  1432.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  1433.             $stmt null;
  1434.             $res null;
  1435.             var_dump($e->getMessage());
  1436.         }
  1437.         return $res;
  1438.     }
  1439.     public function genereCodeBarre($em$nombre$conditionnementId){
  1440.         $tab = array();
  1441.         for($i 0;$i<=$nombre;$i++){
  1442.             $tab[$i] = uniqid()."_".$i ;
  1443.             // Inserer les informations dans la table 
  1444.             $unCodeBarre  = new CodeBarre();
  1445.             $unCodeBarre->setCodeBarre($tab[$i]);
  1446.             $unCodeBarre->setUrlCodeBarre($tab[$i]);
  1447.             if($conditionnementId != 0){
  1448.                 $unCodeBarre->setConditionnement($em->getRepository($this->stockBundle 'Conditionnement')->find($conditionnementId));
  1449.             }
  1450.             $em->persist($unCodeBarre);
  1451.             $em->flush();
  1452.         }
  1453.         return $tab ;
  1454.     }
  1455.     public function getAbonne(EntityManager $em$abonneIdAbonneRepository $abonne) {
  1456.         
  1457.         return $abonne->find($abonneId);
  1458.     }
  1459.     public function initialiserClientTableCommande(EntityManager $em$commandeId 0) {
  1460.         try {
  1461.             $sqlrech ' UPDATE commande set client_id = null, table_mange_id = null where id =:commandeId ';
  1462.            // var_dump($sqlrech, $idProduit);exit;
  1463.             $stmt $em->getConnection()->prepare($sqlrech);
  1464.             $stmt->bindValue(':commandeId'$commandeIdPDO::PARAM_INT);
  1465.             $stmt->execute();
  1466.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  1467.             $stmt null;
  1468.             $res null;
  1469.             var_dump($e->getMessage());
  1470.         }
  1471.         return 1;
  1472.     }
  1473.      /**
  1474.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  1475.      *
  1476.      * @author armand.tevi@gmail.com
  1477.      * @copyright ADMIN 2015
  1478.      *
  1479.      * @version 1
  1480.      *
  1481.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  1482.      */
  1483.     protected function validateLigneCommandeInterne($em$codeVente$objetInfoLivrer$objetCommande$objetProduit$objetPrixRigueur$quantite$idLigneCommande 0,
  1484.     $ligneCommandeRepository$livrerRepository) {
  1485.             $em->getConnection()->beginTransaction();
  1486.             
  1487.             //(
  1488.             try {
  1489.                //var_dump($objetPrixRigueur->getInfoPrixRigueur(), $quantite);exit;
  1490.                $montant=0;
  1491.                if($objetPrixRigueur != null){
  1492.                 $prix $objetPrixRigueur->getInfoPrixRigueur();
  1493.                 $montant =  (int)$prix $quantite;
  1494.                 
  1495.             }
  1496.                            // $prix = $objetPrixRigueur->getInfoPrixRigueur();
  1497.                             //$montant =  (int)$prix * $quantite;
  1498.                             $uneLigneCommande$ligneCommandeRepository->find($idLigneCommande);  
  1499.                             if($uneLigneCommande==null){
  1500.                                 $uneLigneCommande = new LigneCommande();
  1501.                                 $quantite $quantite $objetProduit->getQuantiteDetail();
  1502.                                 
  1503.                                 $uneLigneCommande->setAnnule(false);
  1504.                                 $uneLigneCommande->setEtatLigneCommande(1);
  1505.                                 $uneLigneCommande->setProduit($objetProduit);
  1506.                                 $uneLigneCommande->setFournisseur($objetCommande->getFournisseur());
  1507.                                 $uneLigneCommande->setMontantAutreTaxe($montant);
  1508.                                 $uneLigneCommande->setMontantHt($montant);
  1509.                                 $uneLigneCommande->setQuantite($quantite);
  1510.                                 $uneLigneCommande->setQuantiteLivre($quantite);
  1511.                                 if($objetPrixRigueur != null)
  1512.                                     $uneLigneCommande->setPrixrigueur($objetPrixRigueur);
  1513.                                 $uneLigneCommande->setAbonne($objetCommande->getAbonne());
  1514.                                 $uneLigneCommande->setQuantiteReste(0);
  1515.                                 $uneLigneCommande->setCodeGenere("L_".rand());
  1516.                                 $uneLigneCommande->setTauxTva(0);
  1517.                                 $uneLigneCommande->setCommande($objetCommande);
  1518.                                 $em->persist($uneLigneCommande);
  1519.                                 $em->flush();
  1520.                             }
  1521.                             $uneLivrer$livrerRepository->findOneBy(['lignecommande'=>$uneLigneCommande]); 
  1522.                             if($uneLivrer == null){
  1523.                                 $uneLivrer = new Livrer();
  1524.                             }
  1525.                             $uneLivrer->setDateLivraison(new \DateTime());
  1526.                             $uneLivrer->setEtatLivraison(1);
  1527.                             $uneLivrer->setLignecommande($uneLigneCommande);
  1528.                             $uneLivrer->setNbreLivre($quantite);
  1529.                             //$uneLivrer->setAbonne($objetCommande->getUtilisateur()->getAbonne());
  1530.                             $uneLigneCommande->setQuantiteLivre($quantite);
  1531.                             $uneLigneCommande->setQuantiteReste(0);
  1532.                             //$uneLigneCommande->setEtatLigneCommande(2);
  1533.                             $objetCommande->setEtatCommande(2);
  1534.                             $uneLivrer->setNbreReste(0);
  1535.                             
  1536.                             $uneLivrer->setNombreRestantLivrer(0);
  1537.                             if($objetInfoLivrer!=null){
  1538.                                 $uneLivrer->setInfoLivrer($objetInfoLivrer);
  1539.                                 $uneLivrer->setRefBonLivraison($objetInfoLivrer->getRefBonLivraison());
  1540.                                 $uneLivrer->setRefBonReception($objetInfoLivrer->getRefBonLivraison());
  1541.                             }else{
  1542.                                 $uneLivrer->setRefBonLivraison($codeVente);
  1543.                                 $uneLivrer->setRefBonReception($codeVente);
  1544.                             }
  1545.                             
  1546.                             $uneLivrer->setPrixrigueur($objetPrixRigueur);
  1547.                             $objetInfoLivrer->setNbreTotalLivre($quantite);
  1548.                             $objetInfoLivrer->setNbreSaisie($quantite);
  1549.                             $em->persist($objetInfoLivrer);
  1550.                             $em->persist($uneLigneCommande);
  1551.                             $em->persist($uneLivrer);
  1552.                         
  1553.                             $em->flush();
  1554.                 $em->getConnection()->commit();
  1555.                 //var_dump($quantite, 4000);exit;
  1556.                
  1557.             } catch (\Exception $e) {
  1558.                 $em->getConnection()->rollback();
  1559.                 $em->close();
  1560.                 throw $e;
  1561.             }
  1562.             return  $uneLigneCommande;  
  1563.         
  1564.     }
  1565. /**
  1566.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  1567.      *
  1568.      * @author armand.tevi@gmail.com
  1569.      * @copyright ADMIN 2015
  1570.      *
  1571.      * @version 1
  1572.      *
  1573.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  1574.      */
  1575.     protected function saveCommande($em$codeCommande,  $montant$objetClient$objetutilisateur) {
  1576.         $objetCommande = new Commande();
  1577.     
  1578.         $objetCommande->setAnnule(FALSE);
  1579.         $objetCommande->setCodeCommande($codeCommande);
  1580.         $objetCommande->setDescriptionCommande("Reception mobile");
  1581.         $objetCommande->setEtatCommande(1);
  1582.         $objetCommande->setRefBonCommande($codeCommande);
  1583.         $objetCommande->setCodeGenere($codeCommande);
  1584.         $objetCommande->setTauxEchange(0);
  1585.         $objetCommande->setDatePublication(new \DateTime());
  1586.         $objetCommande->setMontantResteCommande(0);
  1587.         $objetCommande->setTypeCommande(3);    
  1588.         $objetCommande->setUtilisateur($objetutilisateur);  
  1589.         $objetCommande->setSiCredit(0);
  1590.         
  1591.         if($objetutilisateur != null)
  1592.             $objetCommande->setAbonne($objetutilisateur->getAbonne());
  1593.         $objetCommande->setMontantCommande($montant);
  1594.         if($objetClient !=null){
  1595.             $objetCommande->setUtilisateur($objetClient->getUtilisateur());
  1596.             if($objetClient->getUtilisateur() !=null ){
  1597.                 if($objetClient->getCaisse() != null)
  1598.                     $objetCommande->setCaisse($objetClient->getCaisse());
  1599.                 else
  1600.                     $objetCommande->setAbonne($objetClient->getUtilisateur()->getAbonne());
  1601.             }
  1602.         }
  1603.         
  1604.         $em->persist($objetCommande);                       
  1605.         $em->flush(); 
  1606.         return $objetCommande;
  1607.     }
  1608.     /**
  1609.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  1610.      *
  1611.      * @author armand.tevi@gmail.com
  1612.      * @copyright ADMIN 2015
  1613.      *
  1614.      * @version 1
  1615.      *
  1616.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  1617.      */
  1618.     protected function saveEtapeProcessus($em$nomEtapeProcessus$objetAbonne$typeEtapeProcessus) {
  1619.         $objetProcesssus = new EtapeProcessus();
  1620.     
  1621.         $objetProcesssus->setNomEtapeProcessus($nomEtapeProcessus);
  1622.         $objetProcesssus->setAbonne($objetAbonne);
  1623.         $objetProcesssus->setTypeEtapeProcessus($typeEtapeProcessus);
  1624.         
  1625.         $em->persist($objetProcesssus);
  1626.         $em->flush();
  1627.         //Enregistre les formulaire qui sera lié à l'étape créée
  1628.         $objetInspection  = new Inspection();
  1629.         $objetInspection->setLabel($nomEtapeProcessus);
  1630.         $objetInspection->setDescription($nomEtapeProcessus);
  1631.         $objetInspection->setLabel($nomEtapeProcessus);
  1632.         $objetInspection->setTypeInspection(12);
  1633.         $objetInspection->setAbonne($objetAbonne);
  1634.         $objetInspection->setOrdre(1);
  1635.         $objetInspection->setInfoAutre($objetProcesssus->getId());
  1636.         $em->persist($objetInspection);
  1637.         
  1638.         $em->flush();
  1639.         
  1640.         return $objetProcesssus;
  1641.     }
  1642.     /**
  1643.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  1644.      *
  1645.      * @author armand.tevi@gmail.com
  1646.      * @copyright ADMIN 2015
  1647.      *
  1648.      * @version 1
  1649.      *
  1650.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  1651.      */ 
  1652.     protected function saveLivraison($em$objetCommande$objetClient,$infoLivrerRepository$siProducteur 1){
  1653.         $uneInfoLivraison  =   $infoLivrerRepository->findOneBy(['commande'=>$objetCommande]);  
  1654.         if($uneInfoLivraison == null){
  1655.             $uneInfoLivraison = new InfoLivrer();
  1656.             $uneInfoLivraison->setCommande($objetCommande);
  1657.             $uneInfoLivraison->setRefBonLivraison("L".$objetCommande->getRefBonCommande());
  1658.             $uneInfoLivraison->setRefBonReception("L".$objetCommande->getRefBonCommande());
  1659.             $uneInfoLivraison->setCodeGenere("L".$objetCommande->getRefBonCommande());
  1660.             $uneInfoLivraison->setEtatInfoLivrer(1);
  1661.             
  1662.             if($objetCommande->getFournisseur()!=NULL){
  1663.                 $uneInfoLivraison->setFournisseur($objetCommande->getFournisseur());
  1664.             }
  1665.             $uneInfoLivraison->setNbreTotalLivre(0);
  1666.             $uneInfoLivraison->setNbreSaisie(0);
  1667.             $uneInfoLivraison->setAbonne($objetCommande->getAbonne());
  1668.             if($objetClient!=null ){
  1669.                 if($objetClient->getUtilisateur() !=null ){
  1670.                     
  1671.                     if($objetClient->getCaisse() != null)
  1672.                         $uneInfoLivraison->setCaisse($objetClient->getCaisse());
  1673.                     //else
  1674.                         
  1675.                 }
  1676.             }else{
  1677.                 if($siProducteur == 1)
  1678.                     $uneInfoLivraison->setSiProducteur(1);
  1679.             }
  1680.             $uneInfoLivraison->setAbonne($objetCommande->getAbonne());
  1681.             if($objetCommande->getSurfaceannee()!=null)
  1682.                 $uneInfoLivraison->setSurfaceannee($objetCommande->getSurfaceannee());
  1683.             $em->persist($uneInfoLivraison);
  1684.             $em->flush();
  1685.         }
  1686.             return $uneInfoLivraison;
  1687.     }
  1688. /**
  1689.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  1690.      *
  1691.      * @author armand.tevi@gmail.com
  1692.      * @copyright ADMIN 2015
  1693.      *
  1694.      * @version 1
  1695.      *
  1696.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  1697.      */
  1698.     protected function saveClient($em$nom$prenoms$cni$telephone$codeGenere$idVille$sexe$id,$password=""$utilisateurRepository$villeRepository$clientRepository$prixRigueurRepository$etatClientRepository) {
  1699.         
  1700.                  $objetVille$villeRepository->find($idVille);                  
  1701.                  $objetAgent=$utilisateurRepository->find($id);
  1702.                  $donnee $nom ."#".$prenoms ."#".$cni ."#"."0"."#".$telephone  ."#".$codeGenere ."#".$idVille "#".$sexe ;
  1703.                  
  1704.                 $d = new \DateTime();
  1705.                 $an $d->format('Y');
  1706.                 $m $d->format('m');
  1707.                 $j $d->format('d');
  1708.                 $testObjetUtilisateur$utilisateurRepository->findOneBy(['username'=>$telephone'abonne'=>$objetAgent->getAbonne()]);
  1709.                 $objetClient$clientRepository->findOneBy(['utilisateur'=>$testObjetUtilisateur]);
  1710.                 if( $testObjetUtilisateur == null){
  1711.                     $objetUtilisateur$utilisateurRepository->findOneBy(['codeGenere'=>$codeGenere]);
  1712.                     if($objetUtilisateur == null)
  1713.                         $objetUtilisateur= new Utilisateur();
  1714.                         //Enregestre ces données comme livraison                        
  1715.                         $objetUtilisateur->setNom($nom);
  1716.                         $objetUtilisateur->setPrenoms($prenoms);
  1717.                         $objetUtilisateur->setCni($cni);
  1718.                         $objetUtilisateur->setSexe($sexe);
  1719.                         // $objetUtilisateur->setVille($objetVille);
  1720.                         if($objetVille !=null ){
  1721.                             $objetUtilisateur->setVille($objetVille);
  1722.                         }
  1723.                     $objetUtilisateur->setTel1($telephone);
  1724.                     $objetUtilisateur->setCodeGenere($codeGenere);
  1725.                     $objetUtilisateur->setAbonne($objetAgent->getAbonne());
  1726.                     if($password != ""){
  1727.                         $objetUtilisateur->setPassword($password);
  1728.                         $objetUtilisateur->setCPassword($password); 
  1729.                     }
  1730.                     if($telephone != ""){
  1731.                         $objetUtilisateur->setUsername($telephone);
  1732.                         $objetUtilisateur->setProfil($objetAgent->getProfil()); 
  1733.                     }
  1734.                         
  1735.                     
  1736.                     $em->persist($objetUtilisateur);
  1737.                     $em->flush($objetUtilisateur);
  1738.                     
  1739.                     if($objetClient == null)
  1740.                         $objetClient= new Client(); 
  1741.                     //Generer un code pour les producteurs
  1742.                         $objetClient->setCodeClient($codeGenere);   
  1743.                         $objetClient->setCodeGenere($codeGenere);  
  1744.                         if($objetVille !=null ){
  1745.                         $objetClient->setVille($objetVille);
  1746.                         }
  1747.                         $objetClient->setUtilisateur($objetUtilisateur); 
  1748.                         $objetClient->setAbonne($objetAgent->getAbonne());
  1749.                         $em->persist($objetClient);    
  1750.                         $em->flush($objetClient);
  1751.                         if($objetUtilisateur == null){
  1752.                             //Enregistrer dans la prix lie à la caisse
  1753.                         $unCaisseClient = new CaisseClient();
  1754.                                 
  1755.                         $unCaisseClient->setCaisse($objetUtilisateur->getCaisse());
  1756.                         $unCaisseClient->setClient($objetClient) ;
  1757.                         $unCaisseClient->setAbonne($objetUtilisateur->getAbonne());
  1758.                         $em->persist($unCaisseClient);
  1759.                     }
  1760.                     // if($password !=""){
  1761.                         $objetListePrix$prixRigueurRepository->findBy(['etatPrixRigueur'=>1'abonne'=>$objetAgent->getAbonne()]);
  1762.                         foreach($objetListePrix as $objetPrix){
  1763.                             $unClientPrix = new ClientPrix();
  1764.                             $unClientPrix->setPrixrigueur($objetPrix);
  1765.                             $unClientPrix->setClient($objetClient) ;
  1766.                             $unClientPrix->setInfoPrix($objetPrix->getInfoPrixRigueur()) ;
  1767.                             $em->persist($unClientPrix);
  1768.                         }
  1769.                         $em->flush();
  1770.                         //Enregister le type de client
  1771.                         $objectEtatClient =  $etatClientRepository->find($etat=1);
  1772.                         $this->saveEtatClient$em$objectEtatClient$objetClient);
  1773.                     
  1774.                     //}
  1775.                     
  1776.                     $this->addHistoriqueAction($em"ClientAdd"1$codeGenere1$objetClient->getId(), 1$donnee$utilisateurRepository);
  1777.                     $tabInfomation["etat"]=true;
  1778.                     $tabInfomation["client"]=$objetClient;
  1779.                     $tabInfomation["codeGenere"]=$codeGenere;
  1780.                     $tabInfomation["message"]='Compte crée avec succés  !';
  1781.                     
  1782.                     
  1783.                 }else {   
  1784.                     
  1785.                     $tabInfomation["etat"]=false;
  1786.                     $tabInfomation["client"]=$objetClient;
  1787.                     $tabInfomation["codeGenere"]=$codeGenere;
  1788.                     $tabInfomation["message"]='Un compte est déjà crée avec ce numéro !'
  1789.                 }  
  1790.                     return $tabInfomation ;
  1791.     }
  1792.     /**
  1793.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  1794.      *
  1795.      * @author armand.tevi@gmail.com
  1796.      * @copyright ADMIN 2015
  1797.      *
  1798.      * @version 1
  1799.      *
  1800.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  1801.      */
  1802.     protected function saveApiClient($em$nom$prenoms$cni$telephone$codeGenere$idVille$sexe$id,$password=""$utilisateurRepository$villeRepository$clientRepository$prixRigueurRepository$etatClientRepository) {
  1803.         
  1804.         $objetVille$villeRepository->find($idVille);                  
  1805.         $objetAgent=$utilisateurRepository->find($id);
  1806.         $donnee $nom ."#".$prenoms ."#".$cni ."#"."0"."#".$telephone  ."#".$codeGenere ."#".$idVille "#".$sexe ;
  1807.         
  1808.        $d = new \DateTime();
  1809.        $an $d->format('Y');
  1810.        $m $d->format('m');
  1811.        $j $d->format('d');
  1812.        $testObjetUtilisateur$utilisateurRepository->findOneBy(['username'=>$telephone'abonne'=>$objetAgent->getAbonne()]);
  1813.        $objetClient$clientRepository->findOneBy(['utilisateur'=>$testObjetUtilisateur]);
  1814.        if( $testObjetUtilisateur == null){
  1815.            $objetUtilisateur$utilisateurRepository->findOneBy(['codeGenere'=>$codeGenere]);
  1816.            if($objetUtilisateur == null)
  1817.                $objetUtilisateur= new Utilisateur();
  1818.                //Enregestre ces données comme livraison                        
  1819.                $objetUtilisateur->setNom($nom);
  1820.                $objetUtilisateur->setPrenoms($prenoms);
  1821.                $objetUtilisateur->setCni($cni);
  1822.                $objetUtilisateur->setSexe($sexe);
  1823.                // $objetUtilisateur->setVille($objetVille);
  1824.                if($objetVille !=null ){
  1825.                    $objetUtilisateur->setVille($objetVille);
  1826.                }
  1827.            $objetUtilisateur->setTel1($telephone);
  1828.            $objetUtilisateur->setCodeGenere($codeGenere);
  1829.            $objetUtilisateur->setAbonne($objetAgent->getAbonne());
  1830.            if($password != ""){
  1831.                $objetUtilisateur->setPassword($password);
  1832.                $objetUtilisateur->setCPassword($password); 
  1833.            }
  1834.            if($telephone != ""){
  1835.                $objetUtilisateur->setUsername($telephone);
  1836.                $objetUtilisateur->setProfil($objetAgent->getProfil()); 
  1837.            }
  1838.                
  1839.            
  1840.            $em->persist($objetUtilisateur);
  1841.            $em->flush($objetUtilisateur);
  1842.            
  1843.            if($objetClient == null)
  1844.                $objetClient= new Client(); 
  1845.            //Generer un code pour les producteurs
  1846.                $objetClient->setCodeClient($codeGenere);   
  1847.                $objetClient->setCodeGenere($codeGenere);  
  1848.                if($objetVille !=null ){
  1849.                $objetClient->setVille($objetVille);
  1850.                }
  1851.                $objetClient->setUtilisateur($objetUtilisateur); 
  1852.                $objetClient->setAbonne($objetAgent->getAbonne());
  1853.                $em->persist($objetClient);    
  1854.                $em->flush($objetClient);
  1855.                if($objetUtilisateur == null){
  1856.                    //Enregistrer dans la prix lie à la caisse
  1857.                $unCaisseClient = new CaisseClient();
  1858.                        
  1859.                $unCaisseClient->setCaisse($objetUtilisateur->getCaisse());
  1860.                $unCaisseClient->setClient($objetClient) ;
  1861.                $unCaisseClient->setAbonne($objetUtilisateur->getAbonne());
  1862.                $em->persist($unCaisseClient);
  1863.            }
  1864.            // if($password !=""){
  1865.                $objetListePrix$prixRigueurRepository->findBy(['etatPrixRigueur'=>1'abonne'=>$objetAgent->getAbonne()]);
  1866.                foreach($objetListePrix as $objetPrix){
  1867.                    $unClientPrix = new ClientPrix();
  1868.                    $unClientPrix->setPrixrigueur($objetPrix);
  1869.                    $unClientPrix->setClient($objetClient) ;
  1870.                    $unClientPrix->setInfoPrix($objetPrix->getInfoPrixRigueur()) ;
  1871.                    $em->persist($unClientPrix);
  1872.                }
  1873.                $em->flush();
  1874.                //Enregister le type de client
  1875.                $objectEtatClient =  $etatClientRepository->find($etat=1);
  1876.                $this->saveEtatClient$em$objectEtatClient$objetClient);
  1877.            
  1878.            //}
  1879.            
  1880.            $this->addHistoriqueAction($em"ClientAdd"1$codeGenere1$objetClient->getId(), 1$donnee$utilisateurRepository);
  1881.            $tabInfomation["etat"]=true;
  1882.            //$tabInfomation["client"]=$objetClient;
  1883.            $tabInfomation["codeGenere"]=$codeGenere;
  1884.            $tabInfomation["message"]='Compte crée avec succés  !';
  1885.            
  1886.            
  1887.        }else {   
  1888.            
  1889.            $tabInfomation["etat"]=false;
  1890.            //$tabInfomation["client"]=$objetClient;
  1891.            $tabInfomation["codeGenere"]=$codeGenere;
  1892.            $tabInfomation["message"]='Un compte est déjà crée avec ce numéro !'
  1893.        }  
  1894.            return $tabInfomation ;
  1895. }
  1896.   
  1897.     protected function saveEtatClient($em$objectEtatClient$objetClient){   
  1898.                     
  1899.         $objetEtatInfoClient = new  EtatInfoClient();
  1900.         $objetEtatInfoClient->setEtatclient($objectEtatClient);
  1901.         $objetEtatInfoClient->setClient($objetClient) ;
  1902.         $em->persist($objetEtatInfoClient);
  1903.         return $objetEtatInfoClient;
  1904.     } 
  1905.   
  1906.     protected function saveEtatInfoOpportuniteClient($em$objetEtatOpportunite$objetOpportunite){   
  1907.                     
  1908.         $objetEtatInfoOpportunite= new  EtatInfoOpportunite();
  1909.         $objetEtatInfoOpportunite->setOpportunite($objetOpportunite);
  1910.         $objetEtatInfoOpportunite->setEtatopportunite($objetEtatOpportunite) ;
  1911.         $em->persist($objetEtatInfoOpportunite);
  1912.         return $objetEtatInfoOpportunite;
  1913.     } 
  1914.     protected function saveOpportuniteClient($em$objetClient$objetAbonne$codeCommande$dateJour){   
  1915.         $objetOpportunite= new  Opportunite();
  1916.         $objetOpportunite->setClient($objetClient);
  1917.         $objetOpportunite->setAbonne($objetAbonne) ;
  1918.         if($objetClient != null)
  1919.             $objetOpportunite->setTitreOpportunite("commande du client ".$objetClient->getUtilisateur()->getNom()." <br/> Num Commnande "$codeCommande ." <br/> Date Commnande ".$dateJour->format("d-m-Y") ) ;
  1920.         else
  1921.             $objetOpportunite->setTitreOpportunite("commande du client  <br/> Num Commnande "$codeCommande ." <br/> Date Commnande ".$dateJour->format("d-m-Y") ) ;
  1922.         $em->persist($objetOpportunite);
  1923.         return $objetOpportunite;
  1924.     } 
  1925.   /**
  1926.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  1927.      *
  1928.      * @author armand.tevi@gmail.com
  1929.      * @copyright ADMIN 2015
  1930.      *
  1931.      * @version 1
  1932.      *
  1933.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  1934.      */
  1935.     protected function updateClient($em$nom$prenoms$cni$telephone$codeGenere$idVille$sexe$id,$password=""$email$adresse$utilisateurRepository$villeRepository$clientRepository$prixRigueurRepository) {
  1936.         
  1937.                  $objetVille$em->getRepository($this->stockBundle 'Ville')->find($idVille);                  
  1938.                  $objetAgent$em->getRepository($this->userBundle 'Utilisateur')->find($id);
  1939.                  $donnee $nom ."#".$prenoms ."#".$cni ."#"."0"."#".$telephone  ."#".$codeGenere ."#".$idVille "#".$sexe ;
  1940.                  //$groupement
  1941.                  // $objetProduit= $em->getRepository($this->stockBundle . 'Produit')->find(1);
  1942.                  //$objetAnneeCampagne = $em->getRepository($this->prodBundle . 'AnneeCampagne')->findOneBy(array("produit"=>$objetProduit,"etatAnneeCampagne"=>1 )) ;
  1943.                  ///$ligneCommande = $em->getRepository($this->stockBundle . 'Commande')->getLigneCommandeOperation($producteur_id, $anneecampagne_id);
  1944.                  
  1945.                  $d = new \DateTime();
  1946.                  $an $d->format('Y');
  1947.                     $m $d->format('m');
  1948.                     $j $d->format('d');
  1949.                     //$testObjetUtilisateur= $em->getRepository($this->userBundle . 'Utilisateur')->findOneBy(['username'=>$telephone, 'abonne'=>$objetAgent->getAbonne()]);
  1950.                     
  1951.                     //if( $testObjetUtilisateur == null){
  1952.                         $objetUtilisateur$utilisateurRepository->findOneBy(['codeGenere'=>$codeGenere]);
  1953.                         if($objetUtilisateur == null)
  1954.                             $objetUtilisateur= new Utilisateur();
  1955.                          //Enregestre ces données comme livraison                        
  1956.                          $objetUtilisateur->setNom($nom);
  1957.                          $objetUtilisateur->setPrenoms($prenoms);
  1958.                          $objetUtilisateur->setCni($cni);
  1959.                          $objetUtilisateur->setSexe($sexe);
  1960.                          
  1961.                          $objetUtilisateur->setEmail($email);
  1962.                          $objetUtilisateur->setAdresse($adresse);
  1963.                          // $objetUtilisateur->setVille($objetVille);
  1964.     
  1965.                          if($objetVille !=null ){
  1966.                             $objetUtilisateur->setVille($objetVille);
  1967.                          }
  1968.                         $objetUtilisateur->setTel1($telephone);
  1969.                         $objetUtilisateur->setCodeGenere($codeGenere);
  1970.                         $objetUtilisateur->setAbonne($objetAgent->getAbonne());
  1971.     
  1972.                         if($password != ""){
  1973.                             $objetUtilisateur->setPassword(md5($password));
  1974.                             $objetUtilisateur->setCPassword(md5($password)); 
  1975.                         }
  1976.     
  1977.                         if($telephone != ""){
  1978.                             $objetUtilisateur->setUsername($telephone);
  1979.                             $objetUtilisateur->setProfil($objetAgent->getProfil()); 
  1980.                         }
  1981.                             
  1982.     
  1983.                         
  1984.                         $em->persist($objetUtilisateur);
  1985.                         $em->flush($objetUtilisateur);
  1986.                         $objetClient$clientRepository->findOneBy(['codeGenere'=>$codeGenere]);
  1987.                         if($objetClient == null)
  1988.                             $objetClient= new Client(); 
  1989.                         //Generer un code pour les producteurs
  1990.                          $objetClient->setCodeClient($codeGenere);   
  1991.                          $objetClient->setCodeGenere($codeGenere);  
  1992.                          if($objetVille !=null ){
  1993.                             $objetClient->setVille($objetVille);
  1994.                          }
  1995.                          $objetClient->setUtilisateur($objetUtilisateur); 
  1996.                          $objetClient->setAbonne($objetAgent->getAbonne());
  1997.                          $em->persist($objetClient);    
  1998.                          $em->flush($objetClient);
  1999.     
  2000.                          if($objetUtilisateur == null){
  2001.                              //Enregistrer dans la prix lie à la caisse
  2002.                         $unCaisseClient = new CaisseClient();
  2003.                                 
  2004.                         $unCaisseClient->setCaisse($objetUtilisateur->getCaisse());
  2005.                         $unCaisseClient->setClient($objetClient) ;
  2006.                         $unCaisseClient->setAbonne($objetUtilisateur->getAbonne());
  2007.                         $em->persist($unCaisseClient);
  2008.                          }
  2009.     
  2010.                         
  2011.                          $this->addHistoriqueAction($em"ClientAdd"1$codeGenere1$objetClient->getId(), 1$donnee$utilisateurRepository);
  2012.                          
  2013.                         $tabInfomation["etat"]=true;
  2014.                         $tabInfomation["message"]='Compte mise à jour avec succes   !';
  2015.                         
  2016.                         
  2017.                    /* }else {   
  2018.                         
  2019.                         $tabInfomation["etat"]=false;
  2020.                         $tabInfomation["message"]='Un compte est déjà crée avec ce numéro !'; 
  2021.                     }  */
  2022.                      return $tabInfomation ;
  2023.     }
  2024.   /**
  2025.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  2026.      *
  2027.      * @author armand.tevi@gmail.com
  2028.      * @copyright ADMIN 2015
  2029.      *
  2030.      * @version 1
  2031.      *
  2032.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  2033.      */
  2034.     protected function saveLigneCommande($em$codeVente$objetInfoLivrer$objetCommande$objetProduit$objetPrixRigueur$quantite$idLigneCommande 0$etat=1$ligneCommandeRepository) {
  2035.         $em->getConnection()->beginTransaction();
  2036.         //(
  2037.         try {
  2038.             $montant =0;    
  2039.                         if($objetPrixRigueur != null){
  2040.                             $prix $objetPrixRigueur->getInfoPrixRigueur();
  2041.                             $montant =  (int)$prix $quantite;   
  2042.                         }
  2043.                         
  2044.                         $objetLigneCommande =$ligneCommandeRepository->findOneBy(array("codeGenere"=>$codeVente));
  2045.                            
  2046.                         $siNouveau 0;
  2047.                         
  2048.                         if($objetLigneCommande ==null){
  2049.                             $siNouveau 1;
  2050.                             $objetLigneCommande = new LigneCommande();
  2051.                         }
  2052.                         
  2053.                         $objetLigneCommande->setAnnule(false);
  2054.                         $objetLigneCommande->setEtatLigneCommande($etat);
  2055.                         $objetLigneCommande->setProduit($objetProduit);
  2056.                         $objetLigneCommande->setMontantAutreTaxe(0);
  2057.                         $objetLigneCommande->setMontantHt($montant);
  2058.                         $objetLigneCommande->setQuantite($quantite);
  2059.                         $objetLigneCommande->setQuantiteLivre($quantite);
  2060.                         $objetLigneCommande->setCodeGenere($codeVente);
  2061.                         if($objetPrixRigueur != null)
  2062.                             $objetLigneCommande->setPrixrigueur($objetPrixRigueur);
  2063.                         $objetLigneCommande->setQuantiteReste(0);
  2064.                         // $objetLigneCommande->setCaisse($objetUtilisateur->getCaisse());
  2065.                         $objetLigneCommande->setTypeOperation($objetCommande->getTypeCommande());
  2066.                         
  2067.                         $objetLigneCommande->setCommande($objetCommande);
  2068.                        // if($objetUtilisateur !=null ){
  2069.                             $objetLigneCommande->setAbonne($objetCommande->getAbonne());
  2070.                         
  2071.                         $objetLigneCommande->setTypeLigneCommande(1);
  2072.                     // $montantCommande = (int) $montantCommande + (int) $montant;
  2073.                         $em->persist($objetLigneCommande);
  2074.                         $em->flush();
  2075.             $em->getConnection()->commit();
  2076.            
  2077.         } catch (\Exception $e) {
  2078.             $em->getConnection()->rollback();
  2079.             $em->close();
  2080.             throw $e;
  2081.         }
  2082.         return  $objetLigneCommande;
  2083.     
  2084. }
  2085. /**
  2086.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  2087.      *
  2088.      * @author armand.tevi@gmail.com
  2089.      * @copyright ADMIN 2015
  2090.      *
  2091.      * @version 1
  2092.      *
  2093.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  2094.      */
  2095.     protected function saveLigneCommandeClient($em$codeVente$objetInfoLivrer$objetCommande$objetProduit$objetPrixRigueur$quantite$idLigneCommande 0$etat=1) {
  2096.         $em->getConnection()->beginTransaction();
  2097.         //(
  2098.         try {
  2099.             $montant =0;    
  2100.                         if($objetPrixRigueur != null){
  2101.                             $prix $objetPrixRigueur->getInfoPrixRigueur();
  2102.                             $montant =  (int)$prix $quantite;
  2103.                             
  2104.                         }
  2105.                         
  2106.                         $objetLigneCommande =$this->LigneCommandeClient->findOneBy(array("codeGenere"=>$codeVente));
  2107.                            
  2108.                         $siNouveau 0;
  2109.                         
  2110.                         if($objetLigneCommande ==null){
  2111.                             $siNouveau 1;
  2112.                             $objetLigneCommande = new LigneCommandeClient();
  2113.                         }
  2114.                         
  2115.                         $objetLigneCommande->setAnnule(false);
  2116.                         $objetLigneCommande->setEtatLigneCommande($etat);
  2117.                         $objetLigneCommande->setProduit($objetProduit);
  2118.                         $objetLigneCommande->setMontantAutreTaxe(0);
  2119.                         $objetLigneCommande->setMontantHt($montant);
  2120.                         $objetLigneCommande->setQuantite($quantite);
  2121.                         $objetLigneCommande->setQuantiteLivre($quantite);
  2122.                         $objetLigneCommande->setCodeGenere($codeVente);
  2123.                         if($objetPrixRigueur != null)
  2124.                             $objetLigneCommande->setPrixrigueur($objetPrixRigueur);
  2125.                         $objetLigneCommande->setQuantiteReste(0);
  2126.                         // $objetLigneCommande->setCaisse($objetUtilisateur->getCaisse());
  2127.                         $objetLigneCommande->setTypeOperation($objetCommande->getTypeCommande());
  2128.                         
  2129.                         $objetLigneCommande->setCommandeclient$objetCommande);
  2130.                        // if($objetUtilisateur !=null ){
  2131.                             $objetLigneCommande->setAbonne($objetCommande->getAbonne());
  2132.                         
  2133.                         $objetLigneCommande->setTypeLigneCommande(1);
  2134.                     // $montantCommande = (int) $montantCommande + (int) $montant;
  2135.                         $em->persist($objetLigneCommande);
  2136.                         $em->flush();
  2137.             $em->getConnection()->commit();
  2138.            
  2139.         } catch (\Exception $e) {
  2140.             $em->getConnection()->rollback();
  2141.             $em->close();
  2142.             throw $e;
  2143.         }
  2144.         return  $objetLigneCommande;
  2145.     
  2146. }
  2147.    
  2148.     protected function savePrix($em$prix$objetProduit$typePrix$objetUtilisateur$prixRigueurRepository,  $cibleRepository$caracteristiquePrixRepository) {
  2149.         $objetPrix $prixRigueurRepository->findOneBy(['infoPrixRigueur'=>$prix'produit'=>$objetProduit'typePrixRigueur'=> $typePrix]);
  2150.             if($objetPrix == null){
  2151.                 $objetCible $cibleRepository->findOneBy(['etat'=>3'abonne'=>$objetUtilisateur->getAbonne()]);
  2152.                 $objetCarat $caracteristiquePrixRepository->findOneBy(['etat'=>3'abonne'=>$objetUtilisateur->getAbonne()]);
  2153.                 $objetPrix = new PrixRigueur();
  2154.                 if($objetCible!= null)
  2155.                     $objetPrix->setCible($objetCible );
  2156.                 if($objetCarat != null)   
  2157.                     $objetPrix->setCaracteristiquePrix($objetCarat);
  2158.                 $objetPrix->setProduit($objetProduit);
  2159.                 $objetPrix->setInfoPrixRigueur($prix);
  2160.                 $objetPrix->setTypePrixRigueur(2);
  2161.                 $objetPrix->setEtatPrixRigueur(1);
  2162.                 $objetPrix->setAbonne($objetUtilisateur->getAbonne());
  2163.                 $em->persist($objetPrix);
  2164.                 $em->flush();
  2165.                 //Enregistrer dans la prix lie à la caisse
  2166.                 if($objetUtilisateur->getCaisse()!=null){
  2167.                     $unCaissePrix = new CaissePrix();   
  2168.                     $unCaissePrix->setCaisse($objetUtilisateur->getCaisse());
  2169.                     $unCaissePrix->setPrixrigueur($objetPrix) ;
  2170.                     $unCaissePrix->setAbonne($objetUtilisateur->getAbonne());
  2171.                     $em->persist($unCaissePrix);
  2172.                 }
  2173.             }
  2174.             return  $objetPrix;
  2175.     }
  2176.     protected function saveSurfaceAnneeFormulaire($em$surfaceAnnee$producteurId$produitId$objetAnneeCampagne$codeGenere$utilId$producteurRepository$produitRepository$utilisateurRepository$codeExploitation=0$typeParcelle=0) {
  2177.             $objetProducteur $producteurRepository->find($producteurId);
  2178.             if($produitId !=0)
  2179.                 $objetProduit =$produitRepository->find($produitId);
  2180.             $parCodeGenere $codeGenere;
  2181.             $surfaceAnnee->setAnneecampagne($objetAnneeCampagne);
  2182.             $surfaceAnnee->setProducteur($objetProducteur);
  2183.             $surfaceAnnee->setProduit($objetProduit);
  2184.             $surfaceAnnee->setCodeGenere($codeGenere);
  2185.             $surfaceAnnee->setCodeSurface($codeGenere);
  2186.             $surfaceAnnee->setProdCodeGenere($objetProducteur->getCodeGenere());
  2187.             $em->persist($surfaceAnnee);
  2188.             $em->flush();
  2189.             if($surfaceAnnee->getSurfaceannee() != null)
  2190.                 $parCodeGenere $surfaceAnnee->getSurfaceannee()->getCodeGenere();
  2191.             $donnee $surfaceAnnee->getSuperficie() ."#".$objetProducteur->getCodeGenere() ."#".$codeGenere ."#"$parCodeGenere ."#1#".$produitId ."#0#".$utilId."#".$codeExploitation."#".$typeParcelle."#0#0";   
  2192.             $this->addHistoriqueAction($em'ProducteurIntention'1$codeGenere$utilId$objetProducteur->getId(), 1$donnee$utilisateurRepository);
  2193.     
  2194.             return  $surfaceAnnee;
  2195.     }
  2196.     protected function saveTacheFormulaire($em$titre$observation$datedeb$datefin$heuredeb$heurefin$idOperation,$tabIdUtil$utilId,  $type,
  2197.      $utilisateurRepository$anneCampagneRepository$surfaceAnneeRepository$planteRepository$projetRepository$producteurRepository$tacheProduitEtapeCroissanceRepository) {
  2198.    
  2199.         
  2200.         $objetUtilisateur $utilisateurRepository->find((int)$utilId);
  2201.         //$idProjet =0;
  2202.         if($type == 1){
  2203.             $objetSaison $anneCampagneRepository->find((int)$idOperation);
  2204.         }
  2205.         else if($type == 2){
  2206.             $objetSurfaceAnnee $surfaceAnneeRepository->findOneBy(["codeGenere"=>$idOperation]);
  2207.         }
  2208.         else if($type == 3){
  2209.             $objetPlante$planteRepository->findOneBy(["codeGenere"=>$idOperation]);
  2210.         }
  2211.         
  2212.         else if($type == 4){
  2213.             $objetProducteur$producteurRepository->findOneBy(["codeGenere"=>$idOperation]);
  2214.         }
  2215.         
  2216.         else if($type == 5){
  2217.             $objeTacheProduitEtapeCroissance$tacheProduitEtapeCroissanceRepository->find($idOperation);
  2218.         }else{
  2219.             $unProjet $projetRepository->find((int)$idOperation);
  2220.         }
  2221.         //$unBeneficiaire = $em->getRepository($this->assoBundle . 'Beneficiaire')->find((int) $idBeneficiaire);
  2222.         //$type = $request->request->get("type");
  2223.         $uneActivite =  new Activite();
  2224.         //AnneeCampagne  
  2225.         if($type != 5)                          
  2226.             $uneActivite->setDescriptionActivite($observation); 
  2227.         else
  2228.             $uneActivite->setSurfaceAnnee($observation); 
  2229.         //$uneActivite->setMotif($motif);        
  2230.         //$uneActivite->setCat($cat);        
  2231.         $uneActivite->setTitreActivite($titre);    
  2232.         $uneActivite->setDateDebut(new \DateTime($datedeb." ".$heuredeb));
  2233.         $uneActivite->setDateFin(new \DateTime($datefin." ".$heurefin));
  2234.         if($type == 5){
  2235.             $uneActivite->setSiAgricole(1);    
  2236.             if($utilId == )
  2237.                 $uneActivite->setSiRecolte(1);    
  2238.         }
  2239.         //$objetPlante->setAbonne($objetUtilisateur->getAbonne());                        
  2240.         //$uneActivite->setBeneficiaire($descriptionActivite);
  2241.         //$uneActivite->setVille($uneVille);
  2242.         if($type == 1){
  2243.             $uneActivite->setSaison($objetSaison);
  2244.         } else if($type == 2){
  2245.             $uneActivite->setSurfaceAnnee($objetSurfaceAnnee);
  2246.         } else if($type == 3){
  2247.             $uneActivite->setPlante($objetPlante);
  2248.         } else if($type == 4){
  2249.             $uneActivite->setProducteur($objetProducteur);
  2250.             //var_dump(1);exit;
  2251.         } else if($type == 5){
  2252.             $uneActivite->setTacheproduitetapecroissance($objeTacheProduitEtapeCroissance);
  2253.             //var_dump(1);exit;
  2254.         }else{
  2255.             $uneActivite->setProjet($unProjet);
  2256.         }
  2257.         
  2258.         $uneActivite->setTypeActivite($type);
  2259.         $uneActivite->setAbonne($objetUtilisateur->getAbonne());
  2260.         $em->persist($uneActivite);    
  2261.         $tabIdUtil explode('|'$tabIdUtil); 
  2262.             $i 0;
  2263.             foreach($tabIdUtil as $utilId){
  2264.                 if($utilId !=""){
  2265.                     $objetUtilisateur$utilisateurRepository->find($utilId);
  2266.                     $concerne =  new Concerne();
  2267.                     $concerne->setActivite($uneActivite);
  2268.                     // $concerne->setBeneficiaire($unBeneficiaire);
  2269.                     $concerne->setUtilisateur($objetUtilisateur);
  2270.                     //$concerne->setObservation($observation);
  2271.                     //$em->persist($uneActivite);
  2272.                     $em->persist($concerne);
  2273.                     ++$i;
  2274.                 }
  2275.             }
  2276.         $em->flush();
  2277.     }
  2278.     public function getActiviteSuivant(EntityManager $em$objetProduitEtapeCroissance,  $objetTacheProduitEtapeCroissance$produitEtapeCroissanceRepository,  $tacheProduitEtapeCroissanceRepository$objetSurfaceAnnee) {
  2279.         $i=1;
  2280.         do {
  2281.             $ordreSuivant $objetProduitEtapeCroissance->getOrdre() + $i;
  2282.             $siStop false ;
  2283.             $objetProduitEtapeCroissanceSuivant $produitEtapeCroissanceRepository->findOneBy(['produit'=>$objetProduitEtapeCroissance->getProduit(), "ordre"=>$ordreSuivant]);
  2284.             
  2285.             if($objetProduitEtapeCroissanceSuivant != null){
  2286.             
  2287.                 $objetTacheProduitEtapeCroissance $tacheProduitEtapeCroissanceRepository->findOneBy(['produitetapecroissance'=>$objetProduitEtapeCroissanceSuivant'siLastEtapeActivite'=>1]);
  2288.                 if($objetTacheProduitEtapeCroissance != null) {
  2289.                     $objetActivite= new Activite();
  2290.                     $objetActivite->setDescriptionActivite("Tache");
  2291.                     $objetActivite->setTypeActivite($objetTacheProduitEtapeCroissance->getActivite()->getTypeActivite());
  2292.                     $objetActivite->setTitreActivite($objetTacheProduitEtapeCroissance->getActivite()->getTitreActivite());
  2293.                     $periode =  $objetProduitEtapeCroissance->getPeriodeEtapeCroissance();
  2294.                     $periodeSuivant $objetProduitEtapeCroissance->getPeriodeEtapeCroissance() + 10;
  2295.                     if($i == 1){
  2296.                         $dateDebut $objetTacheProduitEtapeCroissance->getDateDebut()->modify("+"$periode +" days");
  2297.                         
  2298.                         $dateFin $objetTacheProduitEtapeCroissance->getDateFin()->modify("+"$periodeSuivant +" days");
  2299.                     }else{
  2300.                         $dateDebut $objetProduitEtapeCroissanceSuivant->getDateDebut()->modify("+"$periode +" days");
  2301.                         $dateFin $objetProduitEtapeCroissanceSuivant->getDateFin()->modify("+"$periodeSuivant +" days");
  2302.                     }
  2303.                     $objetActivite->setDateDebut($dateDebut);
  2304.                     $objetActivite->setDateFin($dateFin);
  2305.                     $objetActivite->setTacheproduitetapecroissance($objetTacheProduitEtapeCroissance);
  2306.                     $objetActivite->setSurfaceannee($objetSurfaceAnnee);
  2307.                     $objetActivite->setProducteur($objetSurfaceAnnee->getProducteur());
  2308.                     $em->persist($objetActivite);
  2309.                     
  2310.                 }
  2311.                 
  2312.             }
  2313.             if($objetProduitEtapeCroissance ==null)
  2314.                  $siStop true;
  2315.             $objetProduitEtapeCroissance =  $objetProduitEtapeCroissanceSuivant ;
  2316.             ++$i;
  2317.         }while($siStop);
  2318.         $em->flush();
  2319.         return 1;
  2320.     }
  2321.     protected function saveVarieteTransformation($em$unProduit$objetProduit$categorie$objetAbonne$siSemence=0) {
  2322.     
  2323.         $unProduit->setProduit($objetProduit);
  2324.         $unProduit->setCodeGenere($unProduit->getCodeProduit());
  2325.         $unProduit->setDescriptionProduit($unProduit->getNomProduit());
  2326.         $unProduit->setCategorie($categorie); //Produit transforme
  2327.         if($siSemence == ){
  2328.             $unProduit->setSiSemence(1);    
  2329.         }else if( $siSemence == ){
  2330.             $unProduit->setSiAgricole(1); 
  2331.         }
  2332.         $unProduit->setAbonne($objetAbonne);
  2333.         $em->persist($unProduit);
  2334.         $em->flush();
  2335.         return   $unProduit;
  2336.     }
  2337.     protected function saveProduitConditionne($em$unProduit$objetCarateristiqueProduit$categorie$objetAbonne$siSemence=0) {
  2338.     
  2339.         $unProduit->setCarateristiqueproduit($objetCarateristiqueProduit);
  2340.         $unProduit->setCodeGenere($unProduit->getCodeProduit());
  2341.         $unProduit->setDescriptionProduit($unProduit->getNomProduit());
  2342.         $unProduit->setCategorie($categorie); //Produit transforme
  2343.         if($siSemence == ){
  2344.             $unProduit->setSiSemence(1);    
  2345.         }else if( $siSemence == ){
  2346.             $unProduit->setSiAgricole(1); 
  2347.         }
  2348.         $unProduit->setAbonne($objetAbonne);
  2349.         $em->persist($unProduit);
  2350.         $em->flush();
  2351.         return   $unProduit;
  2352.     }
  2353.     public function initialiserProduitInspection(EntityManager $em$inspectionId 0) {
  2354.         try {
  2355.             $sqlrech ' UPDATE inspection_produit set etat_inspection_produit = 2 where inspection_id =:inspectionId ';
  2356.            // var_dump($sqlrech, $idProduit);exit;
  2357.             $stmt $em->getConnection()->prepare($sqlrech);
  2358.             $stmt->bindValue(':inspectionId'$inspectionIdPDO::PARAM_INT);
  2359.             $stmt->execute();
  2360.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2361.             $stmt null;
  2362.             $res null;
  2363.             var_dump($e->getMessage());
  2364.         }
  2365.         return 1;
  2366.     }
  2367.     public function initialiserOpportunite(EntityManager $em$etatOpportuniteId 0$opportuniteId 0) {
  2368.         try {
  2369.             $sqlrech ' UPDATE etat_info_opportunite set etat_data_info_opportunite = 0 where etatopportunite_id =:etatOpportuniteId AND opportunite_id =:opportuniteId ';
  2370.            // var_dump($sqlrech, $idProduit);exit;
  2371.             $stmt $em->getConnection()->prepare($sqlrech);
  2372.             $stmt->bindValue(':etatOpportuniteId'$etatOpportuniteIdPDO::PARAM_INT);
  2373.             $stmt->bindValue(':opportuniteId'$opportuniteIdPDO::PARAM_INT);
  2374.             $stmt->execute();
  2375.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2376.             $stmt null;
  2377.             $res null;
  2378.             var_dump($e->getMessage());
  2379.         }
  2380.         return 1;
  2381.     }
  2382.     public function initialiserProfilInspection(EntityManager $em$inspectionId 0) {
  2383.         try {
  2384.             $sqlrech ' UPDATE inspection_profil set etat_inspection_profil = 2 where inspection_id =:inspectionId ';
  2385.            // var_dump($sqlrech, $idProduit);exit;
  2386.             $stmt $em->getConnection()->prepare($sqlrech);
  2387.             $stmt->bindValue(':inspectionId'$inspectionIdPDO::PARAM_INT);
  2388.             $stmt->execute();
  2389.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2390.             $stmt null;
  2391.             $res null;
  2392.             var_dump($e->getMessage());
  2393.         }
  2394.         return 1;
  2395.     }
  2396.     public function genereCodeProducteurVersionAnanas(EntityManager $em$villageId$groupementId$anneeAdhesion$zoneProducteur=0$groupementRepository$producteurGroupementRepository
  2397.     ,$villeRepository$abonneVilleRepository) {
  2398.         //var_dump($villageId, $groupementId, $anneeAdhesion);exit;
  2399.        
  2400.         try {
  2401.             $objetGroupement $groupementRepository->find($groupementId);
  2402.             $listeProducteurGroupement $producteurGroupementRepository->findBy(['groupement'=>$objetGroupement]);
  2403.             $rangProducteur count($listeProducteurGroupement)+1;
  2404.             if($rangProducteur<10)
  2405.                 $rangProducteur "0".$rangProducteur;
  2406.             $objetVillage$villeRepository->find($villageId);
  2407.             $codeVillage substr($objetVillage->getNomVille(), 03);
  2408.             if($zoneProducteur != null )
  2409.                 $codeZone substr($zoneProducteur->getNomVille(), 02);
  2410.             else
  2411.                 $codeZone ="";
  2412.             $anneeAdhesion substr($anneeAdhesion22);
  2413.             
  2414.             $criteriaAbonneVille = array('abonne' => $objetGroupement->getAbonne(), 'ville'=>$objetVillage);
  2415.             $objetAbonneVille $abonneVilleRepository->findOneBy($criteriaAbonneVille);
  2416.             $objetPartenaire $objetVillage;
  2417.             if($objetAbonneVille !=null)
  2418.                 $etatVilleAbonne $objetAbonneVille->getEtatAbonneVille();
  2419.             else
  2420.                 $etatVilleAbonne "";
  2421.             //var_dump($codeVillage);exit;
  2422.             /*if($objetVillage->getTypeVille() == 5){
  2423.                 $objetPartenaire = $objetVillage->getVille()->getVille()->getVille();
  2424.             }else if($objetVillage->getTypeVille() == 4){
  2425.                 $objetPartenaire = $objetVillage->getVille()->getVille();
  2426.             }else if($objetVillage->getTypeVille() == 3){
  2427.                 $objetPartenaire = $objetVillage->getVille();
  2428.             }
  2429.             if($zoneProducteur!=0)
  2430.                 $objetZoneProducteur = $zoneProducteur;
  2431.             else
  2432.                 $objetZoneProducteur =$objetPartenaire->getVille();*/
  2433.             //var_dump($objetPartenaire->getId(),$objetPartenaire->getTypeVille(),$objetPartenaire->getCodeVille());exit;
  2434.             $codeProducteur =  "F".$anneeAdhesion." ".$codeZone." ".$etatVilleAbonne." ".$objetGroupement->getCodeGenere()." ".$rangProducteur;
  2435.            // var_dump( $codeProducteur);exit;
  2436.            //var_dump($objetPartenaire->getVille()->getVille(), $objetPartenaire->getCodeVille(), $anneeAdhesion,$codeVillage,$objetGroupement->getCodeGenere(),$rangProducteur);exit;
  2437.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2438.             var_dump($e->getMessage());
  2439.         }
  2440.         return $codeProducteur;
  2441.     }
  2442.     public function genereCodeProducteurVersionAnanas_2(EntityManager $em$villageId$groupementId$anneeAdhesion$zoneProducteur=0) {
  2443.         //var_dump($villageId, $groupementId, $anneeAdhesion);exit;
  2444.        
  2445.         try {
  2446.             $objetGroupement $em->getRepository($this->prodBundle 'Groupement')->find($groupementId);
  2447.             $listeProducteurGroupement $em->getRepository($this->prodBundle 'ProducteurGroupement')->findBy(['groupement'=>$objetGroupement]);
  2448.             $rangProducteur count($listeProducteurGroupement)+1;
  2449.             if($rangProducteur<10)
  2450.                 $rangProducteur "0".$rangProducteur;
  2451.             $objetVillage$em->getRepository($this->stockBundle 'Ville')->find($villageId);
  2452.             $codeVillage substr($objetVillage->getNomVille(), 03);
  2453.             $anneeAdhesion substr($anneeAdhesion22);
  2454.             //var_dump($objetVillage->getVille()->getVille()->getVille()->getId());exit;
  2455.             $criteriaAbonneVille = array('abonne' => $objetGroupement->getAbonne(), 'ville'=>$objetVillage);
  2456.             $objetAbonneVille $em->getRepository($this->userBundle 'AbonneVille')->findOneBy($criteriaAbonneVille);
  2457.             $objetPartenaire $objetVillage;
  2458.             
  2459.             if($objetVillage->getTypeVille() == 5){
  2460.                 $objetPartenaire $objetVillage->getVille()->getVille()->getVille();
  2461.             }else if($objetVillage->getTypeVille() == 4){
  2462.                 $objetPartenaire $objetVillage->getVille()->getVille();
  2463.             }else if($objetVillage->getTypeVille() == 3){
  2464.                 $objetPartenaire $objetVillage->getVille();
  2465.             }
  2466.             if($zoneProducteur!=0)
  2467.                 $objetZoneProducteur $zoneProducteur;
  2468.             else
  2469.                 $objetZoneProducteur =$objetPartenaire->getVille();
  2470.             //var_dump($objetPartenaire->getId(),$objetPartenaire->getTypeVille(),$objetPartenaire->getCodeVille());exit;
  2471.             $codeProducteur =  "F".$anneeAdhesion." ".$objetPartenaire->getCodeVille()." ".$objetZoneProducteur->getCodeVille()." ".$objetAbonneVille->getEtatAbonneVille()." ".$objetGroupement->getCodeGenere()." ".$rangProducteur;
  2472.             //var_dump("F",$anneeAdhesion,$objetPartenaire->getCodeVille(),$objetZoneProducteur->getCodeVille(),$objetAbonneVille->getEtatAbonneVille(),$objetGroupement->getCodeGenere(),$rangProducteur);exit;
  2473.            //var_dump($objetPartenaire->getVille()->getVille(), $objetPartenaire->getCodeVille(), $anneeAdhesion,$codeVillage,$objetGroupement->getCodeGenere(),$rangProducteur);exit;
  2474.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2475.             var_dump($e->getMessage());
  2476.         }
  2477.         return $codeProducteur;
  2478.     }
  2479.     public function genereNumeroLotCaisse(EntityManager $em$nombreCargaison,$nombreCarton$anneeAdhesion$regionId) {
  2480.         try {
  2481.             $objetVillage$em->getRepository($this->stockBundle 'Ville')->find($regionId);
  2482.             $codeVillage substr($objetVillage->getNomVille(), 02);
  2483.             $anneeAdhesion substr($anneeAdhesion22);
  2484.             //var_dump($objetVillage->getVille()->getVille()->getVille()->getId());exit
  2485.             //var_dump($objetPartenaire->getId(),$objetPartenaire->getTypeVille(),$objetPartenaire->getCodeVille());exit;
  2486.             $codeLot =  sprintf("%04d"$nombreCargaison)."-".sprintf("%05d"$nombreCarton)."-".$anneeAdhesion."-".$codeVillage."-TG" ;
  2487.             //var_dump("F",$anneeAdhesion,$objetPartenaire->getCodeVille(),$objetZoneProducteur->getCodeVille(),$objetAbonneVille->getEtatAbonneVille(),$objetGroupement->getCodeGenere(),$rangProducteur);exit;
  2488.            //var_dump($objetPartenaire->getVille()->getVille(), $objetPartenaire->getCodeVille(), $anneeAdhesion,$codeVillage,$objetGroupement->getCodeGenere(),$rangProducteur);exit;
  2489.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2490.             var_dump($e->getMessage());
  2491.         }
  2492.         return $codeLot;
  2493.     }
  2494.     public function dupliquerImageProduit(EntityManager $em$parentId$objetProduitEncours$objetAbonne) {
  2495.         //var_dump($villageId, $groupementId, $anneeAdhesion);exit;
  2496.         try {
  2497.             $objetProduit $em->getRepository($this->stockBundle 'Produit')->find($parentId);
  2498.             
  2499.             $objetImageParent $em->getRepository($this->stockBundle 'Image')->findOneBy(['produit'=>$objetProduit]);
  2500.             if($objetImageParent != null){
  2501.                 $objetImage = new Image();
  2502.                 $objetImage->setUrlImage($objetImageParent->getUrlImage());
  2503.                // $objetImage->setInspectionrempli($$objetProduit);    
  2504.                 $objetImage->setElementCodeGenere($objetProduitEncours->getCodeGenere());    
  2505.                 $objetImage->setProduit($objetProduit);    
  2506.                 $objetImage->setAbonne($objetAbonne);        
  2507.                 $objetImage->setCodeGenere("IMGV_".rand());                
  2508.                 $objetImage->setTitreImage("Produit Image");                   
  2509.                 $em->persist($objetImage);    
  2510.                 $em->flush($objetImage);
  2511.             }
  2512.            
  2513.            //var_dump($objetPartenaire->getVille()->getVille(), $objetPartenaire->getCodeVille(), $anneeAdhesion,$codeVillage,$objetGroupement->getCodeGenere(),$rangProducteur);exit;
  2514.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2515.             var_dump($e->getMessage());
  2516.         }
  2517.         return  $objetImage;
  2518.     }
  2519.     /**
  2520.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  2521.      *
  2522.      * @author armand.tevi@gmail.com
  2523.      * @copyright ADMIN 2015
  2524.      *
  2525.      * @version 1
  2526.      *
  2527.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  2528.      */
  2529.     protected function savePlante($em$codePlante$prodCodeGenere$codeGenere$parCodeGenere$utilisateurRepository,  $produitRepository,  $surfaceAnneeRepository ,  $planteRepository){
  2530.             $donnee $codePlante."#".$prodCodeGenere."#".$codeGenere."#".$parCodeGenere;
  2531.             $objetProduit$produitRepository->findOneBy(['codeGenere'=>$prodCodeGenere]);                  
  2532.             $objetSurfaceAnnee$surfaceAnneeRepository->findOneBy(['codeGenere'=>$prodCodeGenere]);                  
  2533.                   
  2534.             $objetPlante $planteRepository->findOneBy(['codePlante'=>$codePlante'produit'=>$objetProduit'surfaceannee'=>$objetSurfaceAnnee ]);
  2535.             if($objetPlante == null)
  2536.                 $objetPlante= new Plante();
  2537.                     //Enregestre ces données comme livraison                        
  2538.                     $objetPlante->setCodePlante($codePlante);
  2539.                     $objetPlante->setCodeGenere($codeGenere);
  2540.                     $objetPlante->setProduit($objetProduit);
  2541.                     $objetPlante->setAbonne($objetProduit->getAbonne());
  2542.                     $objetPlante->setSurfaceannee($objetSurfaceAnnee);
  2543.                     // $objetUtilisateur->setVille($objetVille);
  2544.                     $em->persist($objetPlante);
  2545.                // }
  2546.                 $em->flush();
  2547.             
  2548.                 $this->addHistoriqueAction($em"PlanteAdd"1$codeGenere1NUll1$donnee$utilisateurRepository);
  2549.     }
  2550.     /**
  2551.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  2552.      *
  2553.      * @author armand.tevi@gmail.com
  2554.      * @copyright ADMIN 2015
  2555.      *
  2556.      * @version 1
  2557.      *
  2558.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  2559.      */
  2560.     protected function saveUtilisateur($em$nom$prenoms$username,$password$cni$telephone$codeGenere$idVille$sexe$profilId) {
  2561.         //$objetVille= $em->getRepository($this->stockBundle . 'Ville')->find($idVille);                  
  2562.                 
  2563.                  $d = new \DateTime();
  2564.                  $an $d->format('Y');
  2565.                     $m $d->format('m');
  2566.                     $j $d->format('d');
  2567.                     $objetUtilisateur$em->getRepository($this->userBundle 'Utilisateur')->findOneBy(['codeGenere'=>$codeGenere]);
  2568.                     $objetProfil$em->getRepository($this->userBundle 'Profil')->find($profilId);
  2569.                   
  2570.                     if($objetUtilisateur == null)
  2571.                         $objetUtilisateur= new Utilisateur();
  2572.                      //Enregestre ces données comme livraison                        
  2573.                      $objetUtilisateur->setNom($nom);
  2574.                      $objetUtilisateur->setPrenoms($prenoms);
  2575.                      $objetUtilisateur->setCni($cni);
  2576.                      $objetUtilisateur->setSexe($sexe);
  2577.                      $objetUtilisateur->setUsername($username);
  2578.                      $objetUtilisateur->setPassword($password);
  2579.                      $objetUtilisateur->setCpassword($password);
  2580.                      // $objetUtilisateur->setVille($objetVille);
  2581.                      
  2582.                     $objetUtilisateur->setTel1($telephone);
  2583.                     $objetUtilisateur->setCodeGenere($codeGenere);
  2584.                     $objetUtilisateur->setAbonne($objetProfil->getAbonne());
  2585.                     $objetUtilisateur->setProfil($objetProfil);
  2586.                     $em->persist($objetUtilisateur);
  2587.                     $em->flush($objetUtilisateur);
  2588.                     
  2589.  
  2590.     }
  2591.     /**
  2592.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  2593.      *
  2594.      * @author armand.tevi@gmail.com
  2595.      * @copyright ADMIN 2015
  2596.      *
  2597.      * @version 1
  2598.      *
  2599.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  2600.      */
  2601.     protected function saveAutreInfoProducteur($em,$groupement$objetProducteur$ville 0$villeRepository,$groupementRepository$producteurGroupementRepository$zoneProducteurRepository) {
  2602.         //$objetVille= $em->getRepository($this->stockBundle . 'Ville')->find($idVille);                  
  2603.                 
  2604.             //Enregistrer le groupement
  2605.             $objetGroupement $groupementRepository->find($groupement);    
  2606.             
  2607.             if($ville !=0)
  2608.                 $objetVille $villeRepository->find($ville); 
  2609.             
  2610.             //$em->getRepository($this->stockBundle . 'Ville')->findOneBy(array('nomVille'=>$groupement));
  2611.                         
  2612.             $objetProducteurGroupement$producteurGroupementRepository->findOneBy(['producteur'=>$objetProducteur]);                   //$em->getRepository($this->stockBundle . 'Ville')->findOneBy(array('nomVille'=>$groupement));
  2613.             if($objetProducteurGroupement == null )
  2614.                 $objetProducteurGroupement= new ProducteurGroupement(); 
  2615.             $objetProducteurGroupement->setProducteur($objetProducteur);
  2616.             $objetProducteurGroupement->setGroupement($objetGroupement);
  2617.             $objetProducteurGroupement->setAbonne($objetProducteur->getAbonne());
  2618.             $em->persist($objetProducteurGroupement);    
  2619.             $em->flush($objetProducteurGroupement);
  2620.             // Mettre le producteur dans une zone
  2621.             $objetZoneProducteur$zoneProducteurRepository->findOneBy(['producteur'=>$objetProducteur]);                   //$em->getRepository($this->stockBundle . 'Ville')->findOneBy(array('nomVille'=>$groupement));
  2622.             if($objetZoneProducteur == null )
  2623.                 $objetZoneProducteur= new ZoneProducteur(); 
  2624.             $objetZoneProducteur->setProducteur($objetProducteur);
  2625.             if($ville !=0)
  2626.                 $objetZoneProducteur->setVille($objetVille );
  2627.             $objetZoneProducteur->setAbonne($objetProducteur->getAbonne());
  2628.             $em->persist($objetZoneProducteur);    
  2629.             $em->flush($objetZoneProducteur);
  2630.                     
  2631.  
  2632.     }
  2633.     protected function getInfoProduit($int) {
  2634.         
  2635.         if($int ==){
  2636.             $info "Montant";
  2637.         }else if($int ==2){
  2638.             $info "Nbre";
  2639.         }else{
  2640.             $info "Liquidité";
  2641.         }
  2642.         return $info;
  2643.     }
  2644.     protected function getInfoService($int) {
  2645.         
  2646.         if($int ==){
  2647.             $info "Dépot";
  2648.         }else if($int ==2){
  2649.             $info "Retrait";
  2650.         }else if($int ==3){
  2651.             $info "Commision";
  2652.         }else if($int ==3){
  2653.             $info "Liquidité";
  2654.         }else if($int ==3){
  2655.             $info "S.virtuel";
  2656.         }else{
  2657.             $info "Approvisionnement";  
  2658.         }
  2659.         return $info;
  2660.     }
  2661.     protected function getRealCell($nombre){
  2662.         $nombreDebut 65;
  2663.         if($nombre<=90){
  2664.             return chr($nombre);
  2665.         }else{
  2666.             $reste $nombre%91;
  2667.             //var_dump("nombre = ".$nombre, "reste = ".$reste );
  2668.             
  2669.             if($reste%26 == 0){
  2670.                 ++$nombreDebut;
  2671.                 $reste 0;
  2672.             }
  2673.             if($reste>26)
  2674.                 $reste =$reste%27;
  2675.             
  2676.             
  2677.             $nombreSuivant 65+$reste;
  2678.             //var_dump("nombre = ".$nombre, "reste = ".$reste , "SUivant = ".$nombreSuivant);
  2679.             return chr($nombreDebut).chr($nombreSuivant);
  2680.         }
  2681.     }
  2682.     protected function afficherVenteProduit($donneeProduit$i){
  2683.        
  2684.         if($i==1){
  2685.            $result =  $donneeProduit[0]['quantiteTotal'];
  2686.         }else if($i==2) {
  2687.             $result =  $donneeProduit[0]['montantTotal'];
  2688.         }else if($i==3) {
  2689.             $result =  "-";
  2690.         }
  2691.         return $result;
  2692.     }
  2693.     protected function afficherVenteService($donneeProduit$i){
  2694.     
  2695.        // var_dump();exit;
  2696.        if($donneeProduit !=null){
  2697.         if($i==1){
  2698.             $result =  $donneeProduit[0]['soldedebit'];
  2699.          }else if($i==2) {
  2700.              $result =  $donneeProduit[0]['soldecredit'] ;
  2701.          }else if($i==3) {
  2702.              $result =  "-";
  2703.          }
  2704.          else  {
  2705.              $result =  "-";
  2706.          }
  2707.          return $result;;
  2708.        }
  2709.         
  2710.     }
  2711.     protected function saveGroupement($em$groupement$objetAbonne,$groupementRepositroy$objetZoneAbonne){
  2712.         $criteriaGroupe = array('nomGroupement' => $groupement'abonne' => $objetAbonne);
  2713.         $objetGroupement $groupementRepositroy->findOneBy($criteriaGroupe);
  2714.         if($objetGroupement ==null){
  2715.             $objetGroupement = new Groupement();
  2716.         }
  2717.         $objetGroupement->setNomGroupement($groupement);
  2718.         $objetGroupement->setAbonne($objetAbonne);
  2719.         $objetGroupement->setVille($objetZoneAbonne);
  2720.         $em->persist($objetGroupement);
  2721.         $em->flush();
  2722.     }
  2723.     protected function saveZoneAbonne($em$villeProducteur$objetAbonne$villeRepositroy){
  2724.         $criteriaSup = array('nomVille' => $villeProducteur);
  2725.         $objetVille $villeRepositroy->findOneBy($criteriaSup);
  2726.         if ($objetVille  == null) {
  2727.             $objetVille = new Ville();
  2728.             $objetVille->setNomVille($villeProducteur);
  2729.             //$objetVille->setVille($villeZone);
  2730.             $objetVille->setPays(NULL);
  2731.             $objetVille->setTypeVille(7);
  2732.             $em->persist($objetVille);
  2733.         }
  2734.          
  2735.         $objetZoneAbonne = new AbonneVille();
  2736.         $objetZoneAbonne->setVille($objetVille);
  2737.         $objetZoneAbonne->setAbonne($objetAbonne);
  2738.         $objetZoneAbonne->setTypeAbonneVille(5);
  2739.         $em->persist($objetZoneAbonne);
  2740.         $em->flush();
  2741.         return  $objetVille;
  2742.     }
  2743.     protected function saveZonePaysAbonne($em$villeProducteur$objetAbonne$villeRepositroy$objetPays){
  2744.         $criteriaSup = array('nomVille' => $villeProducteur);
  2745.         $objetVille $villeRepositroy->findOneBy($criteriaSup);
  2746.         if ($objetVille  == null) {
  2747.             $objetVille = new Ville();
  2748.             $objetVille->setNomVille($villeProducteur);
  2749.             //$objetVille->setVille($villeZone);
  2750.             $objetVille->setPays($objetPays);
  2751.             $objetVille->setTypeVille(7);
  2752.             $em->persist($objetVille);
  2753.         }
  2754.          
  2755.         $objetZoneAbonne = new AbonneVille();
  2756.         $objetZoneAbonne->setVille($objetVille);
  2757.         $objetZoneAbonne->setAbonne($objetAbonne);
  2758.         $objetZoneAbonne->setTypeAbonneVille(5);
  2759.         $em->persist($objetZoneAbonne);
  2760.         $em->flush();
  2761.         return  $objetVille;
  2762.     }
  2763.     protected function saveZone($em$objetPage$objetGroupement,$objetAbonne){
  2764.         //faire une boucle sur les pages que recevoir les zones
  2765.         $criteriaSup = array('page' => $objetPage,'groupement'=>$objetGroupement);
  2766.         $objetZoneGroupement $em->getRepository($this->cmsBundle 'ZoneGroupement')->findOneBy($criteriaSup);
  2767.         foreach ($objetPage->getZones() as $objetZone) {
  2768.             $objetNZone = new \Entity\cms\ZoneGroupement();   
  2769.             $objetNZone->setTitreZone($objetZone->getTitreZone());
  2770.             $objetNZone->setDescriptionZone($objetZone->getDescriptionZone());
  2771.             $objetNZone->setEtatZone($objetZone->getEtatZone());
  2772.             $objetNZone->setTypeElement($objetZone->getTypeElement());
  2773.             if($objetZone->getTypeElement()== 2){
  2774.                 $uneRubrique $this->saveRubrique($em$objetAbonne$objetZone->getPointeVers());
  2775.                 $objetNZone->setPointeVers($uneRubrique->getId());
  2776.             }
  2777.             if($objetZone->getTypeElement()== 1){
  2778.                 $unArticle $this->saveArticle($em$objetAbonne$objetZone->getPointeVers());
  2779.                 $objetNZone->setPointeVers($unArticle->getId());
  2780.             }
  2781.            // $objetNZone->setSiSysteme($objetZone->getSiSysteme());
  2782.             $objetNZone->setTypeAffichage($objetZone->getTypeAffichage());
  2783.             $objetNZone->setStyle($objetZone->getStyle());
  2784.             $objetNZone->setAbonne($objetAbonne);
  2785.             $objetNZone->setPage($objetPage);
  2786.             $objetNZone->setGroupement($objetGroupement);
  2787.             $objetNZone->setDateAjoutZone($objetZone->getDateAjoutZone());
  2788.             $em->persist($objetNZone);
  2789.             $em->flush();
  2790.         }
  2791.         
  2792.     }
  2793.     protected function saveRubrique($em$objetAbonne$id){
  2794.         //faire une boucle sur les pages que recevoir les zones
  2795.         $objetCurrentRubrique$em->getRepository($this->cmsBundle 'Rubrique')->find($id);
  2796.         $objetRubrique = new \Entity\cms\Rubrique();   
  2797.         $objetRubrique->setDesignationRubrique($objetCurrentRubrique->getDesignationRubrique());
  2798.         $objetRubrique->setDescriptionRubrique($objetCurrentRubrique->getDescriptionRubrique());
  2799.         $objetRubrique->setAbonne($objetAbonne);
  2800.         $em->persist($objetRubrique);
  2801.         $em->flush(); 
  2802.         return $objetRubrique;
  2803.             
  2804.     }
  2805.     protected function saveArticle($em$objetAbonne$id){
  2806.         //faire une boucle sur les pages que recevoir les zones
  2807.         
  2808.         $objetCurrentArticle$em->getRepository($this->cmsBundle 'Article')->find($id);
  2809.         $objetRubrique $this->saveRubrique($em$objetAbonne$objetCurrentArticle->getRubrique()->getId());
  2810.         $objetArticle = new \Entity\cms\Article();  
  2811.         $objetArticle->setRubrique($objetRubrique);
  2812.         $objetArticle->setTitre($objetCurrentArticle->getTitre());
  2813.         $objetArticle->setContenuArticle($objetCurrentArticle->getContenuArticle());
  2814.         $objetArticle->setResumeArticle($objetCurrentArticle->getResumeArticle());
  2815.         $objetArticle->setTypeArticle($objetCurrentArticle->getTypeArticle());
  2816.         $objetArticle->setAbonne($objetAbonne);
  2817.         $em->persist($objetArticle);
  2818.         $em->flush(); 
  2819.         return $objetArticle;
  2820.             
  2821.     }
  2822.       
  2823.   
  2824.     public function getStatInspectionAction(EntityManager $em,$abonneId$inspectionId$mois$siListe=0) {
  2825.         try {
  2826.             $dateTime = new \DateTime();
  2827.             if($siListe==0)
  2828.                 $sqlrech 'SELECT  u.nom_user, u.prenoms_user, u.tel1_user, u.sexe_user,  u.date_ajout_user as date_ajout,  p.code_genere as code_producteur ';
  2829.             else
  2830.                 $sqlrech 'SELECT Count(ri.id) as total ';
  2831.             
  2832.             $sqlrech .= '
  2833.                             FROM  inspection_rempli ir
  2834.                             INNER JOIN inspection i on i.id = ir.inspection_id
  2835.                             INNER JOIN producteur p  on ir.producteur_id  = p.id
  2836.                             INNER JOIN utilisateur u on p.utilisateur_id = u.id
  2837.                             WHERE i.abonne_id =:abonneId AND YEAR(ir.date_enregistrement) =:annee  
  2838.                             AND i.id =:inspectionId AND MONTH(ir.date_enregistrement)=:mois
  2839.                             GROUP BY i.id, MONTH(ir.date_enregistrement) '//
  2840.            
  2841.             $stmt $em->getConnection()->prepare($sqlrech);
  2842.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  2843.             $stmt->bindValue(':annee'$dateTime->format('Y'), PDO::PARAM_STR);
  2844.             $stmt->bindValue(':inspectionId'$inspectionIdPDO::PARAM_INT);
  2845.             $stmt->bindValue(':mois'$moisPDO::PARAM_INT);
  2846.             
  2847.             $stmt->execute();
  2848.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  2849.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2850.             $stmt null;
  2851.             $res null;
  2852.             var_dump($e->getMessage());
  2853.         }
  2854.         return $res;
  2855.     }
  2856.     public function getStatInspectionByAgentAction(EntityManager $em,$abonneId$agentId$inspectionId) {
  2857.         try {
  2858.             $dateTime = new \DateTime();
  2859.             $sqlrech 'SELECT Count(ir.id) as total
  2860.                             FROM  inspection_rempli ir
  2861.                             INNER JOIN inspection i on i.id = ir.inspection_id
  2862.                             INNER JOIN utilisateur u on u.id = ir.utilisateur_id
  2863.                             WHERE i.abonne_id =:abonneId AND u.id =:agentId  
  2864.                             AND i.id =:inspectionId  AND ir.etat_fournisseur_producteur =:etat
  2865.                             GROUP BY u.id '//
  2866.            
  2867.             $stmt $em->getConnection()->prepare($sqlrech);
  2868.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  2869.             $stmt->bindValue(':agentId'$agentIdPDO::PARAM_INT);
  2870.             $stmt->bindValue(':inspectionId'$inspectionIdPDO::PARAM_INT);
  2871.             $stmt->bindValue(':etat'1PDO::PARAM_INT);
  2872.            
  2873.             
  2874.             $stmt->execute();
  2875.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  2876.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2877.             $stmt null;
  2878.             $res null;
  2879.             var_dump($e->getMessage());
  2880.         }
  2881.         return $res;
  2882.     }
  2883.     public function getAchatVarieteAction(EntityManager $em,$abonneId$produitId) {
  2884.         try {
  2885.             $dateTime = new \DateTime();
  2886.             $sqlrech 'SELECT Count(lc.quantite) as quantiteTotal
  2887.             
  2888.                             FROM  commande c
  2889.                             INNER JOIN lignecommande lc on lc.commande_id = c.id
  2890.                             INNER JOIN produit_abonne pa on lc.produitabonne_id  = pa.id
  2891.                             INNER JOIN produit p on pa.produit_id = p.id
  2892.                             INNER JOIN abonne a on pa.abonne_id = a.id
  2893.                             
  2894.                             WHERE a.id =:abonneId AND YEAR(c.date_commande) =:annee  AND p.id =:produitId 
  2895.                             GROUP BY p.nom_produit, MONTH(c.date_commande) '//
  2896.            
  2897.             $stmt $em->getConnection()->prepare($sqlrech);
  2898.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  2899.             $stmt->bindValue(':annee'$dateTime->format('Y'), PDO::PARAM_STR);
  2900.             $stmt->bindValue(':produitId'$produitIdPDO::PARAM_INT);
  2901.             
  2902.             $stmt->execute();
  2903.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  2904.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2905.             $stmt null;
  2906.             $res null;
  2907.             var_dump($e->getMessage());
  2908.         }
  2909.         return $res;
  2910.     }
  2911.     public function getAchatMoisAction(EntityManager $em,$abonneId) {
  2912.         try {
  2913.             $dateTime = new \DateTime();
  2914.             $sqlrech 'SELECT DISTINCT( MONTH(c.date_commande)) as mois
  2915.             
  2916.                             FROM  commande c
  2917.                             INNER JOIN lignecommande lc on lc.commande_id = c.id
  2918.                             INNER JOIN produit_abonne pa on lc.produitabonne_id  = pa.id
  2919.                             INNER JOIN produit p on pa.produit_id = p.id
  2920.                             INNER JOIN abonne a on pa.abonne_id = a.id
  2921.                             
  2922.                             WHERE a.id =:abonneId AND YEAR(c.date_commande) =:annee 
  2923.                             GROUP BY p.nom_produit, MONTH(c.date_commande) '//
  2924.            
  2925.             $stmt $em->getConnection()->prepare($sqlrech);
  2926.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  2927.             $stmt->bindValue(':annee'$dateTime->format('Y'), PDO::PARAM_STR);
  2928.             
  2929.             $stmt->execute();
  2930.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  2931.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2932.             $stmt null;
  2933.             $res null;
  2934.             var_dump($e->getMessage());
  2935.         }
  2936.         return $res;
  2937.     }
  2938.     public function getStatProducteurGroupementAction(EntityManager $em,$abonneId$groupementId) {
  2939.         try {
  2940.             $sqlrech 'SELECT Count(g.id) as total
  2941.                             FROM  groupement g
  2942.                             INNER JOIN producteur_groupement gp on gp.groupement_id = g.id
  2943.                             INNER JOIN producteur p on gp.producteur_id = p.id
  2944.                             INNER JOIN producteur_abonne pa on pa.producteur_id  = p.id
  2945.                             INNER JOIN abonne a on pa.abonne_id  = a.id
  2946.                             WHERE a.id =:abonneId  AND g.id =:groupementId 
  2947.                             GROUP BY g.id
  2948.                         '
  2949.             $stmt $em->getConnection()->prepare($sqlrech);
  2950.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  2951.             $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  2952.             $stmt->execute();
  2953.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  2954.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2955.             $stmt null;
  2956.             $res null;
  2957.             var_dump($e->getMessage());
  2958.         }
  2959.         return $res;
  2960.     }
  2961.     public function getStatProducteurEntity(EntityManager $em,$abonneId$entityId$siGroupement$partenaireId=0$typeAction=0$tabProduit=0) {
  2962.         try {
  2963.             $sqlrech 'SELECT COUNT(DISTINCT(p.id)) as total ' ;
  2964.             if($siGroupement == 1){
  2965.                 $sqlrech .= '
  2966.                             FROM  groupement g ';
  2967.                 $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.groupement_id = g.id
  2968.                                 INNER JOIN producteur p on gp.producteur_id = p.id' ;
  2969.             }else{
  2970.                 $sqlrech .= '
  2971.                             FROM  ville v ' ;
  2972.                 $sqlrech .= '   INNER JOIN zone_producteur zp on zp.ville_id = v.id
  2973.                                 INNER JOIN producteur p on zp.producteur_id = p.id' ;
  2974.             }
  2975.             
  2976.             if($typeAction != 0){
  2977.                 $sqlrech .= '   INNER JOIN producteur_abonne pa on pa.producteur_id  = p.id
  2978.                                 INNER JOIN abonne a on pa.abonne_id  = a.id
  2979.                             '
  2980.                 if($typeAction == &&  $partenaireId != 0)
  2981.                     $sqlrech .= " INNER JOIN partenaire pt  on pa.partenaire_id = pt.id ";
  2982.             }else{
  2983.                 $sqlrech .= " INNER JOIN abonne a on p.abonne_id  = a.id ";
  2984.                 
  2985.             }
  2986.             if($tabProduit != 0){
  2987.                 $sqlrech .= "  INNER JOIN surface_annee sa on sa.producteur_id  = p.id 
  2988.                                INNER JOIN produit prod on prod.id = sa.produit_id ";
  2989.             }
  2990.             if($siGroupement == 1)
  2991.                 $sqlrech .= '   WHERE a.id =:abonneId  AND g.id =:entityId  AND p.etat_prod = 1'
  2992.             else
  2993.                 $sqlrech .= '   WHERE a.id =:abonneId  AND v.id =:entityId AND p.etat_prod = 1 '
  2994.             $i 0;
  2995.             if($tabProduit !=&& count($tabProduit)!=0){         
  2996.                 // if($prod != 1){
  2997.                 $i=0;
  2998.                 foreach($tabProduit as $unProduitId){
  2999.                     if($i == 0){
  3000.                         $sqlrech .= " AND ( prod.id = :produit".$unProduitId."";
  3001.                     //var_dump($uneVille->getId());
  3002.                     }else{
  3003.                         $sqlrech .= " OR prod.id= :produit".$unProduitId."";
  3004.                     }
  3005.                     $i++;
  3006.                 //$tabProduitUser[] = $unInfoProduit->getId();            
  3007.                 }    
  3008.                 $sqlrech .= " ) ";
  3009.             }
  3010.             
  3011.             if($siGroupement == 1)
  3012.                 $sqlrech .= ' GROUP BY g.id ';  
  3013.             else
  3014.                 $sqlrech .= ' GROUP BY v.id '
  3015.             
  3016.             
  3017.             //var_dump( $sqlrech , $abonneId, $entityId);exit;
  3018.             $stmt $em->getConnection()->prepare($sqlrech);
  3019.             if($tabProduit !=0){    
  3020.                 foreach($tabProduit as $unProduitId){
  3021.                     $stmt->bindValue(":produit".$unProduitId.""$unProduitIdPDO::PARAM_INT);            
  3022.                 }
  3023.             }
  3024.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  3025.             $stmt->bindValue(':entityId'$entityIdPDO::PARAM_INT);
  3026.             $stmt->execute();
  3027.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  3028.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3029.             $stmt null;
  3030.             $res null;
  3031.             var_dump($e->getMessage());
  3032.         }
  3033.         return $res;
  3034.     }
  3035.     public function getCountStatSurfaceEntity(EntityManager $em,$abonneId$entityId$siGroupement$partenaireId=0$typeAction=0$tabProduit=0) {
  3036.         try {
  3037.             $sqlrech 'SELECT Count(DISTINCT(sa.id)) as nombreTotal ' ;
  3038.             if($siGroupement == 1){
  3039.                 $sqlrech .= '
  3040.                             FROM  groupement g ';
  3041.                 $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.groupement_id = g.id
  3042.                                 INNER JOIN producteur p on gp.producteur_id = p.id' ;
  3043.             }else{
  3044.                 $sqlrech .= '
  3045.                             FROM  ville v ' ;
  3046.                 $sqlrech .= '   INNER JOIN zone_producteur zp on zp.ville_id = v.id
  3047.                                 INNER JOIN producteur p on zp.producteur_id = p.id' ;
  3048.             }
  3049.             $sqlrech .= '   INNER JOIN surface_annee sa on sa.producteur_id  = p.id '
  3050.            
  3051.             if($typeAction != 0){
  3052.                 $sqlrech .= '   INNER JOIN producteur_abonne pa on pa.producteur_id  = p.id
  3053.                                 INNER JOIN abonne a on pa.abonne_id  = a.id '
  3054.                 if($typeAction == &&  $partenaireId != 0)
  3055.                     $sqlrech .= " INNER JOIN partenaire pt  on pa.partenaire_id = pt.id ";
  3056.             }else{
  3057.                 $sqlrech .= " INNER JOIN abonne a on p.abonne_id  = a.id ";
  3058.                 
  3059.             }
  3060.             if($tabProduit != 0){
  3061.                 $sqlrech .= "INNER JOIN produit prod on prod.id = sa.produit_id  ";
  3062.             }
  3063.             if($siGroupement == 1)
  3064.                 $sqlrech .= '   WHERE a.id =:abonneId  AND g.id =:entityId and sa.type_parcelle = 0 and sa.etat_surface_annee =1 and p.etat_prod = 1'
  3065.             else
  3066.                 $sqlrech .= '   WHERE a.id =:abonneId  AND v.id =:entityId  and sa.type_parcelle = 0 and sa.etat_surface_annee =1 and p.etat_prod = 1'
  3067.             
  3068.             
  3069.             $i 0;
  3070.             if($tabProduit !=&& count($tabProduit)!=0){         
  3071.                 // if($prod != 1){
  3072.                 $i=0;
  3073.                 foreach($tabProduit as $unProduitId){
  3074.                     if($i == 0){
  3075.                         $sqlrech .= " AND ( prod.id = :produit".$unProduitId."";
  3076.                     //var_dump($uneVille->getId());
  3077.                     }else{
  3078.                         $sqlrech .= " OR prod.id= :produit".$unProduitId."";
  3079.                     }
  3080.                     $i++;
  3081.                 //$tabProduitUser[] = $unInfoProduit->getId();            
  3082.                 }    
  3083.                 $sqlrech .= " ) ";
  3084.             }
  3085.             
  3086.             if($siGroupement == 1)
  3087.                 $sqlrech .= ' GROUP BY g.id ';  
  3088.             else
  3089.                 $sqlrech .= ' GROUP BY v.id ';  
  3090.             $stmt $em->getConnection()->prepare($sqlrech);
  3091.             //if($produitId != 0)
  3092.                 //$stmt->bindValue(':produitId', $produitId, PDO::PARAM_INT);
  3093.             if($tabProduit !=0){    
  3094.                 foreach($tabProduit as $unProduitId){
  3095.                     $stmt->bindValue(":produit".$unProduitId.""$unProduitIdPDO::PARAM_INT);            
  3096.                 }
  3097.             }
  3098.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  3099.             $stmt->bindValue(':entityId'$entityIdPDO::PARAM_INT);
  3100.             $stmt->execute();
  3101.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  3102.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3103.             $stmt null;
  3104.             $res null;
  3105.             var_dump($e->getMessage());
  3106.         }
  3107.         return $res;
  3108.     }
  3109.     public function getSumStatSurfaceEntity(EntityManager $em,$abonneId$entityId$siGroupement$partenaireId=0$typeAction=0$tabProduit=0) {
  3110.         try {
  3111.             $sqlrech 'SELECT CAST(SUM(sa.superficie) AS DECIMAL(10,2)) as surperficieTotal, CAST(SUM(sa.superficie_reelle) AS DECIMAL(10,2)) as surperficieTotalReelle  ' ;
  3112.             if($siGroupement == 1){
  3113.                 $sqlrech .= ' FROM  groupement g ';
  3114.                 $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.groupement_id = g.id
  3115.                                 INNER JOIN producteur p on gp.producteur_id = p.id' ;
  3116.             }else{
  3117.                 $sqlrech .= ' FROM  ville v ' ;
  3118.                 $sqlrech .= '   INNER JOIN zone_producteur zp on zp.ville_id = v.id
  3119.                                 INNER JOIN producteur p on zp.producteur_id = p.id' ;
  3120.             }
  3121.             $sqlrech .= '   INNER JOIN surface_annee sa on sa.producteur_id  = p.id '
  3122.             if($tabProduit != 0){
  3123.                 $sqlrech .= "  INNER JOIN produit prod on prod.id = sa.produit_id ";
  3124.             }
  3125.             if($typeAction != 0){
  3126.                 $sqlrech .= '   INNER JOIN producteur_abonne pa on pa.producteur_id  = p.id
  3127.                                 INNER JOIN abonne a on pa.abonne_id  = a.id
  3128.                             '
  3129.                 if($typeAction == &&  $partenaireId != 0)
  3130.                     $sqlrech .= " INNER JOIN partenaire pt  on pa.partenaire_id = pt.id ";
  3131.             }else{
  3132.                 $sqlrech .= " INNER JOIN abonne a on p.abonne_id  = a.id";
  3133.                 
  3134.             }
  3135.             if($siGroupement == 1)
  3136.                 $sqlrech .= '   WHERE a.id =:abonneId  AND g.id =:entityId  and sa.type_parcelle = 0 and sa.etat_surface_annee =1 and p.etat_prod = 1'
  3137.             else
  3138.                 $sqlrech .= '   WHERE a.id =:abonneId  AND v.id =:entityId and sa.type_parcelle = 0 and sa.etat_surface_annee =1 and p.etat_prod = 1'
  3139.             
  3140.             if($tabProduit !=&& count($tabProduit)!=0){         
  3141.                 // if($prod != 1){
  3142.                 $i=0;
  3143.                 foreach($tabProduit as $unProduitId){
  3144.                     if($i == 0){
  3145.                         $sqlrech .= " AND ( prod.id = :produit".$unProduitId."";
  3146.                     //var_dump($uneVille->getId());
  3147.                     }else{
  3148.                         $sqlrech .= " OR prod.id= :produit".$unProduitId."";
  3149.                     }
  3150.                     $i++;
  3151.                 //$tabProduitUser[] = $unInfoProduit->getId();            
  3152.                 }    
  3153.                 $sqlrech .= " ) ";
  3154.             }
  3155.             if($siGroupement == 1)
  3156.                 $sqlrech .= ' GROUP BY g.id ';  
  3157.             else
  3158.                 $sqlrech .= ' GROUP BY v.id '
  3159.            // if($siGroupement == 2)
  3160.                 //var_dump($sqlrech);exit;
  3161.             $stmt $em->getConnection()->prepare($sqlrech);
  3162.             if($tabProduit !=0){    
  3163.                 foreach($tabProduit as $unProduitId){
  3164.                     $stmt->bindValue(":produit".$unProduitId.""$unProduitIdPDO::PARAM_INT);            
  3165.                 }
  3166.             }
  3167.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  3168.             $stmt->bindValue(':entityId'$entityIdPDO::PARAM_INT);
  3169.             $stmt->execute();
  3170.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  3171.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3172.             $stmt null;
  3173.             $res null;
  3174.             var_dump($e->getMessage());
  3175.         }
  3176.         return $res;
  3177.     }
  3178.     public function getStatStockGroupementAction(EntityManager $em,$abonneId$groupementId) {
  3179.         try {
  3180.             $sqlrech 'SELECT Count(g.id) as total
  3181.                             FROM lignecommande lc
  3182.                             INNER JOIN livrer l on l.lignecommande_id = lc.id
  3183.                             INNER JOIN  info_livrer il on il.id = l.infolivrer_id
  3184.                             INNER JOIN producteur p on lc.producteur_id = p.id
  3185.                             INNER JOIN producteur_groupement gp on gp.groupement_id = p.id
  3186.                             LEFT JOIN groupement g on gp.groupement_id = g.id
  3187.                             INNER JOIN producteur_abonne pa on pa.producteur_id  = p.id
  3188.                             INNER JOIN abonne a on pa.abonne_id  = a.id
  3189.                             WHERE a.id =:abonneId  AND g.id =:groupementId 
  3190.                             GROUP BY g.id
  3191.                         ' ;         
  3192.             $stmt $em->getConnection()->prepare($sqlrech);
  3193.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  3194.             $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  3195.             $stmt->execute();
  3196.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  3197.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3198.             $stmt null;
  3199.             $res null;
  3200.             var_dump($e->getMessage());
  3201.         }
  3202.         return $res;
  3203.     }
  3204.     public function getStatProducteurZoneAction(EntityManager $em,$abonneId$groupementId) {
  3205.         
  3206.             try {
  3207.                 $sqlrech 'SELECT Count(g.id) as total
  3208.                                 FROM  groupement g
  3209.                                 INNER JOIN producteur_groupement gp on gp.groupement_id = g.id
  3210.                                 INNER JOIN producteur p on gp.producteur_id = p.id
  3211.                                 INNER JOIN producteur_abonne pa on pa.producteur_id  = p.id
  3212.                                 INNER JOIN abonne a on pa.abonne_id  = a.id
  3213.                                 WHERE a.id =:abonneId  AND g.id =:groupementId 
  3214.                                 GROUP BY g.id
  3215.                             '
  3216.                 $stmt $em->getConnection()->prepare($sqlrech);
  3217.                 $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  3218.                 $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  3219.                 $stmt->execute();
  3220.                 $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  3221.             } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3222.                 $stmt null;
  3223.                 $res null;
  3224.                 var_dump($e->getMessage());
  3225.             }
  3226.             return $res;
  3227.     }
  3228.    
  3229.     public function getStatStockParcelleAction(EntityManager $em,$abonneId$groupementId$zoneId) {
  3230.         try {
  3231.             $sqlrech 'SELECT Count(sa.id) as total
  3232.                             FROM surface_annee sa
  3233.                             INNER JOIN produit p on sa.produit_id = p.id
  3234.                             INNER JOIN produit_abonne pa on pa.produit_id  = p.id
  3235.                             INNER JOIN abonne a on pa.abonne_id  = a.id
  3236.                             WHERE a.id =:abonneId  
  3237.                             GROUP BY p.id
  3238.                         ' ;         
  3239.             $stmt $em->getConnection()->prepare($sqlrech);
  3240.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  3241.             $stmt->execute();
  3242.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  3243.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3244.             $stmt null;
  3245.             $res null;
  3246.             var_dump($e->getMessage());
  3247.         }
  3248.         return $res;
  3249.     }
  3250.     public function getStatGeolocalisationAction(EntityManager $em,$abonneId$groupementId$zoneId$siP=0$partenaireId=0$typeAction=0$siListe=0) {
  3251.         try {
  3252.             if($siListe==0)
  3253.                 $sqlrech 'SELECT  u.nom_user, u.prenoms_user, u.tel1_user, u.sexe_user,  u.date_ajout_user as date_ajout,  p.code_genere as code_producteur, sa.code_genere as code_surface, sa.superficie, sa.superficie_reelle';
  3254.             else
  3255.                 $sqlrech 'SELECT Count(sa.id) as total ';
  3256.             $sqlrech .= '
  3257.                             FROM surface_annee sa
  3258.                             INNER JOIN produit pr on sa.produit_id = pr.id
  3259.                              ';
  3260.                 if($groupementId != || $zoneId !=0)
  3261.                     $sqlrech .= " INNER JOIN producteur p  on sa.producteur_id  = p.id
  3262.                                   INNER JOIN utilisateur u on p.utilisateur_id = u.id
  3263.                 ";
  3264.                 if($groupementId != 0){
  3265.                     $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.producteur_id = p.id
  3266.                                     INNER JOIN groupement g on gp.groupement_id = g.id' ;
  3267.                 }
  3268.                 if($zoneId != 0){
  3269.                     $sqlrech .= '   INNER JOIN zone_producteur zp on zp.producteur_id = p.id
  3270.                                     INNER JOIN ville v on zp.ville_id = v.id' ;
  3271.                 }
  3272.                 if($typeAction != 0){
  3273.                     $sqlrech .= " INNER JOIN surface_abonne sab on sab.surfaceannee_id  = sa.id ";
  3274.                     $sqlrech .= " INNER JOIN abonne a on sab.abonne_id =  a.id ";
  3275.                     if($typeAction == &&  $partenaireId != 0)
  3276.                         $sqlrech .= " INNER JOIN partenaire pt on sab.partenaire_id = pt.id ";
  3277.                 }else{
  3278.                     $sqlrech .= " INNER JOIN abonne a on sa.abonne_id  = a.id";
  3279.                 }
  3280.                 $sqlrech .= " WHERE  sa.id ";
  3281.                 if($siP==0)
  3282.                     $sqlrech .= ' IN';
  3283.                 else
  3284.                     $sqlrech .= ' NOT IN';
  3285.                 $sqlrech .= '     (
  3286.                         SELECT DISTINCT(surfaceannee_id) FROM localisation WHERE 1=1 and type_localisation = 1
  3287.                     ) 
  3288.                     
  3289.                 ' ;         
  3290.                 if($typeAction == &&  $partenaireId != 0)
  3291.                     $sqlrech .= " AND  pt.id =:partenaireId  ";
  3292.                 if($groupementId != )
  3293.                     $sqlrech .= " AND  g.id =:groupementId  ";
  3294.                 if($zoneId != )
  3295.                     $sqlrech .= " AND  v.id =:zoneId  ";
  3296.                 
  3297.                 if($typeAction == || $typeAction == 1)
  3298.                     $sqlrech .= " AND  a.id =:abonneId  ";
  3299.                     //var_dump($sqlrech);exit;
  3300.                 //INNER JOIN produit_abonne pa on pa.produit_id  = p.id
  3301.                 $stmt $em->getConnection()->prepare($sqlrech);
  3302.                 if($typeAction == &&  $partenaireId != 0)
  3303.                     $stmt->bindValue(':partenaireId'$partenaireIdPDO::PARAM_INT);
  3304.                 
  3305.                 if($groupementId != )
  3306.                     $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  3307.                 if($zoneId != )
  3308.                     $stmt->bindValue(':zoneId'$zoneIdPDO::PARAM_INT);
  3309.                 if($typeAction == || $typeAction == 1)
  3310.                     $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  3311.             $stmt->execute();
  3312.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  3313.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3314.             $stmt null;
  3315.             $res null;
  3316.             var_dump($e->getMessage());
  3317.         }
  3318.         return $res;
  3319.     }
  3320.     public function getStatPolygonAction(EntityManager $em,$abonneId$groupementId$zoneId$siP=0$partenaireId=0$typeAction=0$siListe=0) {
  3321.         
  3322.         try {
  3323.             if($siListe==0)
  3324.                 $sqlrech 'SELECT  u.nom_user, u.prenoms_user, u.tel1_user, u.sexe_user,  u.date_ajout_user as date_ajout,  p.code_genere as code_producteur, sa.code_genere as code_surface, sa.superficie, sa.superficie_reelle';
  3325.             else
  3326.                 $sqlrech 'SELECT Count(sa.id) as total ';
  3327.             $sqlrech .= '
  3328.                             FROM surface_annee sa
  3329.                             INNER JOIN produit pr on sa.produit_id = pr.id
  3330.                              ';
  3331.                 if($groupementId != || $zoneId !=0)
  3332.                     $sqlrech .= " INNER JOIN producteur p  on sa.producteur_id  = p.id
  3333.                                   INNER JOIN utilisateur u on p.utilisateur_id = u.id ";
  3334.                 if($groupementId != 0){
  3335.                     $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.producteur_id = p.id
  3336.                                     INNER JOIN groupement g on gp.groupement_id = g.id' ;
  3337.                 }
  3338.                 if($zoneId != 0){
  3339.                     $sqlrech .= '   INNER JOIN zone_producteur zp on zp.producteur_id = p.id
  3340.                                     INNER JOIN ville v on zp.ville_id = v.id' ;
  3341.                 }
  3342.                 if($typeAction != 0){
  3343.                     $sqlrech .= " INNER JOIN surface_abonne sab on sab.surfaceannee_id  = sa.id ";
  3344.                     $sqlrech .= " INNER JOIN abonne a on sab.abonne_id =  a.id ";
  3345.                     if($typeAction == &&  $partenaireId != 0)
  3346.                         $sqlrech .= " INNER JOIN partenaire pt on sab.partenaire_id = pt.id ";
  3347.                 }else{
  3348.                     $sqlrech .= " INNER JOIN abonne a on sa.abonne_id  = a.id";
  3349.                 }
  3350.                 $sqlrech .= " WHERE  sa.id ";
  3351.                 if($siP==0)
  3352.                     $sqlrech .= ' IN';
  3353.                 else
  3354.                     $sqlrech .= ' NOT IN';
  3355.                 $sqlrech .= '     (
  3356.                         SELECT DISTINCT(surfaceannee_id) FROM localisation WHERE 1=1 and type_localisation = 1 and     tab_polygone is null
  3357.                     )   
  3358.                 ' ;         
  3359.                 if($typeAction == &&  $partenaireId != 0)
  3360.                     $sqlrech .= " AND  pt.id =:partenaireId  ";
  3361.                 if($groupementId != )
  3362.                     $sqlrech .= " AND  g.id =:groupementId  ";
  3363.                 if($zoneId != )
  3364.                     $sqlrech .= " AND  v.id =:zoneId  ";
  3365.                 
  3366.                 if($typeAction == || $typeAction == 1)
  3367.                     $sqlrech .= " AND  a.id =:abonneId  ";
  3368.                     //var_dump($sqlrech);exit;
  3369.                 //INNER JOIN produit_abonne pa on pa.produit_id  = p.id
  3370.                 $stmt $em->getConnection()->prepare($sqlrech);
  3371.                 if($typeAction == &&  $partenaireId != 0)
  3372.                     $stmt->bindValue(':partenaireId'$partenaireIdPDO::PARAM_INT);
  3373.                 
  3374.                 if($groupementId != )
  3375.                     $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  3376.                 if($zoneId != )
  3377.                     $stmt->bindValue(':zoneId'$zoneIdPDO::PARAM_INT);
  3378.                 if($typeAction == || $typeAction == 1)
  3379.                     $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  3380.             $stmt->execute();
  3381.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  3382.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3383.             $stmt null;
  3384.             $res null;
  3385.             var_dump($e->getMessage());
  3386.         }
  3387.         return $res;
  3388.     }
  3389.     public function getStatGeolocalisationTotalAction(EntityManager $em,$abonneId$groupementId$zoneId$siP=0$partenaireId=0$typeAction=0) {
  3390.         try {
  3391.             $sqlrech 'SELECT Count(sa.id) as total
  3392.                             FROM surface_annee sa
  3393.                             INNER JOIN produit pr on sa.produit_id = pr.id
  3394.                             
  3395.                              ';
  3396.                 if($groupementId != || $zoneId !=0)
  3397.                 $sqlrech .= " INNER JOIN producteur p  on sa.producteur_id  = p.id";
  3398.                 if($groupementId != 0){
  3399.                     $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.producteur_id = p.id
  3400.                                     INNER JOIN groupement g on gp.groupement_id = g.id' ;
  3401.                 }
  3402.                 if($zoneId != 0){
  3403.                     $sqlrech .= '   INNER JOIN zone_producteur zp on zp.producteur_id = p.id
  3404.                                     INNER JOIN ville v on zp.ville_id = v.id' ;
  3405.                 }
  3406.                     if($typeAction != 0){
  3407.                         $sqlrech .= " INNER JOIN surface_abonne sab on sab.surfaceannee_id  = sa.id ";
  3408.                         $sqlrech .= " INNER JOIN abonne a on  sab.abonne_id =  a.id ";
  3409.                         if($typeAction == &&  $partenaireId != 0)
  3410.                             $sqlrech .= " INNER JOIN partenaire pt on sab.partenaire_id = pt.id ";
  3411.                     }else{
  3412.                         $sqlrech .= " INNER JOIN abonne a on sa.abonne_id  = a.id";
  3413.                     }
  3414.             /*if($siP==0)
  3415.                 $sqlrech .= ' IN';
  3416.             else
  3417.                 $sqlrech .= ' NOT IN';
  3418.             $sqlrech .= '     (
  3419.                     SELECT DISTINCT(surfaceannee_id) FROM localisation WHERE 1=1 and type_localisation = 1
  3420.                 ) 
  3421.                 
  3422.             ' ; */       
  3423.             $sqlrech .= " WHERE a.id =:abonneId  ";
  3424.             if($typeAction == &&  $partenaireId != 0)
  3425.                 $sqlrech .= " AND  pt.id =:partenaireId  ";
  3426.                 
  3427.             if($groupementId != )
  3428.                 $sqlrech .= " AND  g.id =:groupementId  ";
  3429.             if($zoneId != )
  3430.                 $sqlrech .= " AND  v.id =:zoneId  ";
  3431.             //INNER JOIN produit_abonne pa on pa.produit_id  = p.id
  3432.             $stmt $em->getConnection()->prepare($sqlrech);
  3433.             if($typeAction == &&  $partenaireId != 0)
  3434.                 $stmt->bindValue(':partenaireId'$partenaireIdPDO::PARAM_INT);
  3435.             
  3436.             if($groupementId != )
  3437.                 $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  3438.             if($zoneId != )
  3439.                 $stmt->bindValue(':zoneId'$zoneIdPDO::PARAM_INT);
  3440.             
  3441.             if($typeAction == || $typeAction == 1)
  3442.                 $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  3443.             $stmt->execute();
  3444.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  3445.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3446.             $stmt null;
  3447.             $res null;
  3448.             var_dump($e->getMessage());
  3449.         }
  3450.         return $res;
  3451.     }
  3452.     public function getStatInspectionParcelleAction(EntityManager $em,$abonneId$groupementId$zoneId$inspectionId$siP=0$partenaireId=0$typeAction=0$siListe=1) {
  3453.         try {
  3454.             if($siListe==0)
  3455.                 $sqlrech 'SELECT  u.nom_user, u.prenoms_user, u.tel1_user, u.sexe_user,  u.date_ajout_user as date_ajout,  p.code_genere as code_producteur, sa.code_genere as code_surface, sa.superficie, sa.superficie_reelle';
  3456.             else
  3457.                 $sqlrech 'SELECT Count(sa.id) as total ';
  3458.             $sqlrech .= '
  3459.                             FROM surface_annee sa
  3460.                         '
  3461.                 //if($groupementId != 0 || $zoneId !=0)
  3462.                 $sqlrech .= " INNER JOIN producteur p  on sa.producteur_id  = p.id
  3463.                                 INNER JOIN utilisateur u on p.utilisateur_id = u.id
  3464.                                 ";
  3465.                 if($groupementId != 0){
  3466.                     $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.producteur_id = p.id
  3467.                                     INNER JOIN groupement g on gp.groupement_id = g.id' ;
  3468.                 }
  3469.                 
  3470.                 if($zoneId != 0){
  3471.                     $sqlrech .= '   INNER JOIN zone_producteur zp on zp.producteur_id = p.id
  3472.                                     INNER JOIN ville v on zp.ville_id = v.id' ;
  3473.                 }
  3474.                 if($typeAction != 0){
  3475.                     $sqlrech .= " INNER JOIN surface_abonne sab on sab.surfaceannee_id  = sa.id ";
  3476.                     $sqlrech .= " INNER JOIN abonne a on  sab.abonne_id =  a.id ";
  3477.                     if($typeAction == &&  $partenaireId != 0)
  3478.                         $sqlrech .= " INNER JOIN partenaire pt on sab.partenaire_id = pt.id ";
  3479.                 }else{
  3480.                     $sqlrech .= " INNER JOIN abonne a on sa.abonne_id  = a.id";
  3481.                 }
  3482.             
  3483.                 $sqlrech .= " WHERE  sa.id ";
  3484.                 if($siP==0)
  3485.                     $sqlrech .= ' IN';
  3486.                 else
  3487.                     $sqlrech .= ' NOT IN';
  3488.                 $sqlrech .= '     (
  3489.                         SELECT surfaceannee_id FROM inspection_rempli WHERE inspection_id =:inspectionId AND surfaceannee_id is not null
  3490.                     )
  3491.                 ' ;  
  3492.                 if($typeAction == &&  $partenaireId != 0)
  3493.                     $sqlrech .= " AND  pt.id =:partenaireId  ";
  3494.                 
  3495.                 if($groupementId != )
  3496.                     $sqlrech .= " AND  g.id =:groupementId  ";
  3497.                 if($zoneId != )
  3498.                     $sqlrech .= " AND  v.id =:zoneId  ";
  3499.                 if($typeAction == || $typeAction == 1)
  3500.                     $sqlrech .= " AND  a.id =:abonneId  ";
  3501.                 //INNER JOIN produit_abonne pa on pa.produit_id  = p.id
  3502.                 $stmt $em->getConnection()->prepare($sqlrech);
  3503.                 
  3504.                 //var_dump($sqlrech, $zoneId);exit;
  3505.                 if($typeAction == &&  $partenaireId != 0)
  3506.                     $stmt->bindValue(':partenaireId'$partenaireIdPDO::PARAM_INT);
  3507.                 if($typeAction == || $typeAction == 1)
  3508.                     $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  3509.                 
  3510.                 if($groupementId != )
  3511.                     $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  3512.                 if($zoneId != )
  3513.                     $stmt->bindValue(':zoneId'$zoneIdPDO::PARAM_INT);
  3514.             
  3515.                 $stmt->bindValue(':inspectionId'$inspectionIdPDO::PARAM_INT);
  3516.                 $stmt->execute();
  3517.                 $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  3518.             } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3519.                 $stmt null;
  3520.                 $res null;
  3521.                 var_dump($e->getMessage());
  3522.             }
  3523.             return $res;
  3524.     }
  3525.     function siVide($value){
  3526.         if($value == "")
  3527.             return "_____________________________";
  3528.         else
  3529.             return $value;
  3530.     }
  3531.     public function genereStockProduitConditionne($em$codeCommande$montant$objetProduit$objetPrix$quantite,$infoLivrerRepository$ligneCommandeRepository$livrerRepository,$objetUtilisateur) {
  3532.         
  3533.         $autoObjetCommande $this->saveCommande($em$codeCommande,  $montantnull$objetUtilisateur);
  3534.         $autoObjetLivraison $this->saveLivraison($em$autoObjetCommandenull,$infoLivrerRepository) ;
  3535.         $this->validateLigneCommandeInterne($em$codeCommande$autoObjetLivraison$autoObjetCommande$objetProduit$objetPrix$quantite0$ligneCommandeRepository$livrerRepository);
  3536.         //$this->manageStock($em, $objetProduit->getId(),$quantite, 1);
  3537.     }
  3538.     public function creerTabMenu($em,$idEtabl$abonneIdMenuRepository $menuRepository){
  3539.         $listeMenu $menuRepository->getAllMenuActif($abonneId);
  3540.         $i=0;
  3541.         $tabMenu = array();
  3542.         foreach($listeMenu as $unMenu){
  3543.             $tab explode('|'$unMenu->getContenuMenu());
  3544.             $tabMenu[$i]['lien'] = $tab[0];
  3545.             if(count($tab) >1)
  3546.                 $tabMenu[$i]['id'] = $tab[1];
  3547.             else
  3548.                 $tabMenu[$i]['id'] ="";
  3549.             $tabMenu[$i]['titre'] = $unMenu->getTitre();
  3550.             $tabMenu[$i]['type']  = $unMenu->getTypeMenu();
  3551.             $i++;
  3552.         }
  3553.         return $tabMenu
  3554.     } 
  3555.     public function creerTabMenuReact($em,$idEtabl$abonneIdMenuRepository $menuRepository){
  3556.         $listeMenu $menuRepository->getAllMenuAvecSousMenuActif($abonneId);
  3557.         $i=0;
  3558.         $tabMenu = array();
  3559.         foreach($listeMenu as $unMenu){
  3560.             $tab explode('|'$unMenu->getContenuMenu());
  3561.             $tabMenu[$i]['lien'] = $this->getInfoMenu($tab[0]);
  3562.             if(count($tab) >1)
  3563.                 $tabMenu[$i]['id'] = $tab[1];
  3564.             else
  3565.                 $tabMenu[$i]['id'] ="";
  3566.             $tabMenu[$i]['titre'] = $unMenu->getTitre();
  3567.             $tabMenu[$i]['type']  = $unMenu->getTypeMenu();
  3568.             $sousMenu $menuRepository->getSousAllMenuActif($unMenu->getId());
  3569.             $tabMenu[$i]['sousMenu']  = $this->getMenuForme($sousMenu);
  3570.             $i++;
  3571.         }
  3572.         return $tabMenu
  3573.     } 
  3574.     
  3575.     public function getMenuForme($listeMenu){
  3576.         $i=0;
  3577.         $tabMenu = array();
  3578.         foreach($listeMenu as $unMenu){
  3579.             $tab explode('|'$unMenu->getContenuMenu());
  3580.             $tabMenu[$i]['lien'] = $this->getInfoMenu($tab[0]);
  3581.             if(count($tab) >1)
  3582.                 $tabMenu[$i]['id'] = $tab[1];
  3583.             else
  3584.                 $tabMenu[$i]['id'] ="";
  3585.             $tabMenu[$i]['titre'] = $unMenu->getTitre();
  3586.             $tabMenu[$i]['type']  = $unMenu->getTypeMenu();
  3587.             $i++;
  3588.         }
  3589.         return $tabMenu
  3590.     } 
  3591.     public function getInfoMenu($menu){
  3592.         if($menu=="app_admin_info_page"){
  3593.             $infoMenu "";
  3594.         }else if($menu=="app_admin_details_article"){
  3595.             $infoMenu '/articles';
  3596.         }else if($menu=="app_admin_details_rubrique"){
  3597.             $infoMenu "/details";
  3598.         }else if($menu=="app_admin_catalogue_page"){
  3599.             $infoMenu "/catalogue";
  3600.         }else if($menu=="app_admin_carte_page"){
  3601.             $infoMenu "/info/carte";
  3602.         }else if($menu=="admin_projet_get_liste_public"){
  3603.             $infoMenu "/get/liste/projet/public";
  3604.         }
  3605.         return $infoMenu
  3606.     } 
  3607.     
  3608.     
  3609.     protected function saveDefautPageTemplate($em$objetTemplate,$objetAbonne$pageRepository){
  3610.         //faire une boucle sur les pages que recevoir les zones
  3611.         $criteriaSup = array('template' => $objetTemplate,'abonne' => $objetAbonne);
  3612.         $objetPage $pageRepository->findOneBy($criteriaSup);
  3613.         
  3614.         if ($objetPage == null ) {
  3615.             
  3616.             $objetNPage = new Page();   
  3617.             $objetNPage->setTitrePage("Accueil");
  3618.             $objetNPage->setTwigPage("index.html.twig");
  3619.             $objetNPage->setDescriptionPage("Gestion de la page d'accueil de l'abonne : ".$objetAbonne->getNom());
  3620.             $objetNPage->setSiPageAccueil(1);
  3621.             $objetNPage->setAbonne($objetAbonne);
  3622.             $objetNPage->setTemplate($objetTemplate);
  3623.             $em->persist($objetNPage);
  3624.             $em->flush();  
  3625.         }
  3626.         
  3627.     }
  3628.     protected function getListeAbonne($em,$objetAbonne ,$abonneRepository){
  3629.         if($objetAbonne->getSiPrincipale() == 2)
  3630.             $listeAbonne$abonneRepository->findBy(array("partenaire"=>$objetAbonne->getpartenaire()));
  3631.         else
  3632.             $listeAbonne = array();
  3633.         return  $listeAbonne;
  3634.     }
  3635.          /**
  3636.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  3637.      *
  3638.      * @author armand.tevi@gmail.com
  3639.      * @copyright ADMIN 2015
  3640.      *
  3641.      * @version 1
  3642.      *
  3643.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  3644.      */
  3645.     protected function insertSurfaceAnneeHistorique($em$objetSurfaceAnnee$objetAnneeCampagne,$surfaceAnneeHistoriqueRepository) {
  3646.         //$objetVille= $em->getRepository($this->stockBundle . 'Ville')->find($idVille);   
  3647.         $criteriaHistorique = array('surfaceannee' => $objetSurfaceAnnee'anneecampagne'=>$objetAnneeCampagne);
  3648.         
  3649.         $objetSurfaceAnneeHistorique =  $surfaceAnneeHistoriqueRepository->findOneBy($criteriaHistorique);               
  3650.         if( $objetSurfaceAnneeHistorique == null)
  3651.             $objetSurfaceAnneeHistorique = new SurfaceAnneeHistorique;
  3652.    
  3653.         $objetSurfaceAnneeHistorique->setSurfaceannee($objetSurfaceAnnee);
  3654.         $objetSurfaceAnneeHistorique->setAnneecampagne($objetAnneeCampagne);
  3655.         $objetSurfaceAnneeHistorique->setAbonne($objetSurfaceAnnee->getAbonne());
  3656.         $em->persist($objetSurfaceAnneeHistorique);
  3657.         $em->flush();
  3658.  
  3659.     }
  3660.     protected function infoSigne($signe){
  3661.         $infoSigne "";
  3662.         switch ($signe) {
  3663.             case 1:
  3664.                 $infoSigne ">";
  3665.                 break;
  3666.             case 2:
  3667.                 $infoSigne =">=";
  3668.                 break;
  3669.             case 3:
  3670.                 $infoSigne "<";
  3671.                 break;
  3672.             case 4:
  3673.                 $infoSigne "<=";
  3674.                 break; 
  3675.         }
  3676.         return $infoSigne;  
  3677.     }
  3678.     public function initialiserInspectionRempliProducteur(EntityManager $em$producteurId 0$inspectionId0) {
  3679.         try {
  3680.             $sqlrech ' UPDATE inspection_rempli set etat_fournisseur_producteur = 2  WHERE producteur_id =:producteurId  AND inspection_id =:inspectionId ';
  3681.            // var_dump($sqlrech, $idProduit);exit;
  3682.             $stmt $em->getConnection()->prepare($sqlrech);
  3683.             $stmt->bindValue(':producteurId'$producteurIdPDO::PARAM_INT);
  3684.             $stmt->bindValue(':inspectionId'$inspectionIdPDO::PARAM_INT);
  3685.             $stmt->execute();
  3686.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3687.             $stmt null;
  3688.             $res null;
  3689.             var_dump($e->getMessage());
  3690.         }
  3691.         return 1;
  3692.     }
  3693.     public function initialiserProgrammeInspection(EntityManager $em$typeProgramme 0$etatProgramme=) {
  3694.         try {
  3695.             $sqlrech ' UPDATE programme_inspection set etat_programme_inspection = 0  WHERE programme_id in ( SELECT id FROM programme WHERE type_programme =:typeProgramme and etat_programme =:etatProgramme )';
  3696.            
  3697.             $stmt $em->getConnection()->prepare($sqlrech);
  3698.             $stmt->bindValue(':typeProgramme'$typeProgrammePDO::PARAM_INT);
  3699.             $stmt->bindValue(':etatProgramme'$etatProgrammePDO::PARAM_INT);
  3700.             $stmt->execute();
  3701.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3702.             $stmt null;
  3703.             $res null;
  3704.             var_dump($e->getMessage());
  3705.         }
  3706.         return 1;
  3707.     }
  3708.     public function initialiserProgramme(EntityManager $em$typeProgramme 0) {
  3709.         try {
  3710.             $sqlrech ' UPDATE programme set etat_programme = 0  WHERE type_programme =:typeProgramme ';
  3711.            // var_dump($sqlrech, $idProduit);exit;
  3712.             $stmt $em->getConnection()->prepare($sqlrech);
  3713.             $stmt->bindValue(':typeProgramme'$typeProgrammePDO::PARAM_INT);
  3714.             $stmt->execute();
  3715.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3716.             $stmt null;
  3717.             $res null;
  3718.             var_dump($e->getMessage());
  3719.         }
  3720.         return 1;
  3721.     }
  3722.     public function initialiserInspectionRempliSurface(EntityManager $em$surfaceId 0$inspectionId0) {
  3723.         try {
  3724.             $sqlrech ' UPDATE inspection_rempli set etat_fournisseur_producteur = 2  where surfaceannee_id =:surfaceId AND inspection_id =:inspectionId ';
  3725.            // var_dump($sqlrech, $idProduit);exit;
  3726.             $stmt $em->getConnection()->prepare($sqlrech);
  3727.             $stmt->bindValue(':surfaceId'$surfaceIdPDO::PARAM_INT);
  3728.             $stmt->bindValue(':inspectionId'$inspectionIdPDO::PARAM_INT);
  3729.             $stmt->execute();
  3730.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3731.             $stmt null;
  3732.             $res null;
  3733.             var_dump($e->getMessage());
  3734.         }
  3735.         return 1;
  3736.     }
  3737.     public function getInfoProducteurAnniversaireAction(EntityManager $em,$abonneId) {
  3738.         try {
  3739.             $dateTime = new \DateTime();
  3740.             $sqlrech 'SELECT u.id,u.nom_user as nom, u.prenoms_user as prenoms ,   u.email_user, u.date_naissance as dateNaissance, p.code_genere
  3741.             
  3742.                             FROM  producteur p
  3743.                             INNER JOIN utilisateur u on p.utilisateur_id = u.id
  3744.                         
  3745.                             INNER JOIN abonne a on p.abonne_id = a.id
  3746.                             
  3747.                             WHERE a.id =:abonneId AND MONTH(u.date_naissance) =:mois  AND DAY(u.date_naissance) =:jour  
  3748.                              '//
  3749.            
  3750.            //var_dump($sqlrech, $dateTime->format('m'), $dateTime->format('d'));exit;
  3751.             $stmt $em->getConnection()->prepare($sqlrech);
  3752.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  3753.             $stmt->bindValue(':mois'$dateTime->format('m'), PDO::PARAM_STR);
  3754.             $stmt->bindValue(':jour'$dateTime->format('d'), PDO::PARAM_STR);
  3755.             $stmt->execute();
  3756.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  3757.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3758.             $stmt null;
  3759.             $res null;
  3760.             var_dump($e->getMessage());
  3761.         }
  3762.         return $res;
  3763.     }
  3764.     public function getTonnageByAnnee($abonneId$commandeRepository,$produitId$type$surfaceId$producteurId$typeCulture$infoAnnee ) {
  3765.         $tab = array();
  3766.         $infoAnneePasse =0;
  3767.         if($infoAnnee!=0)
  3768.             $infoAnneePasse =  $infoAnnee-1;
  3769.         
  3770.         $totalInfoAnnee =  $commandeRepository->getCountInfoCommandeByAnnee($nomcol=0$datefin=0$datedeb=0$ville=0$util=0$silivre=0$numcom=0$produitId$type,$typeLimite 0$nbParPage 20$pageActuelle 1,$abonneId,$retrait=0$clientId 0$siCredit=0,$surfaceId$anneeId=0,$producteurId$typeCulture$infoAnnee);
  3771.         $totalInfoAnneePasse =  $commandeRepository->getCountInfoCommandeByAnnee($nomcol=0$datefin=0$datedeb=0$ville=0$util=0$silivre=0$numcom=0$produitId$type,$typeLimite 0$nbParPage 20$pageActuelle 1,$abonneId,$retrait=0$clientId 0$siCredit=0,$surfaceId$anneeId=0,$producteurId$typeCulture$infoAnneePasse);
  3772.         //(0,0,0,0,0,0,0,0,6,0,20,1,$sessionData['abonneId'], 0,0,0,$listeObjetSurface[0]->getId(),$infoAnneeId); 
  3773.         $tab = [$totalInfoAnnee$totalInfoAnneePasse]; 
  3774.         
  3775.         return  $tab
  3776.     }
  3777.     public function getFinanceByAnnee($em$operationManager,$produitId$type$surfaceId$producteurId$typeCompe$infoAnnee$sens ) {
  3778.         $tab = array();
  3779.         $infoAnneePasse =0;
  3780.         if($infoAnnee!=0)
  3781.             $infoAnneePasse =  $infoAnnee-1;
  3782.         
  3783.         $totalInfoAnnee =  $operationManager->soldeCaisseProducteurDate($em,$idCaisse=0,$datedeb=0$datefin=0$idprod=0,$idab=0,$compte='0'$producteurId$fournisseurId=0,$sens$typeCompe$infoAnnee) ; 
  3784.         $totalInfoAnneePasse =  $operationManager->soldeCaisseProducteurDate($em,$idCaisse=0,$datedeb=0$datefin=0$idprod=0,$idab=0,$compte='0'$producteurId$fournisseurId=0,$sens$typeCompe$infoAnneePasse) ; 
  3785.         //(0,0,0,0,0,0,0,0,6,0,20,1,$sessionData['abonneId'], 0,0,0,$listeObjetSurface[0]->getId(),$infoAnneeId); 
  3786.         $tab = [$totalInfoAnnee$totalInfoAnneePasse]; 
  3787.         
  3788.         return  $tab
  3789.     }
  3790.     /**
  3791.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  3792.      *
  3793.      * @author armand.tevi@gmail.com
  3794.      * @copyright ADMIN 2015
  3795.      *
  3796.      * @version 1
  3797.      *
  3798.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  3799.      */
  3800.     protected function saveInfoDeplacer($em$objetLigneCommande$entrepot,  $quantite$numeroLot$dateEnvoi$typeDeplacement) {
  3801.         $em->getConnection()->beginTransaction();
  3802.         //(
  3803.         try {
  3804.             $objetInfoDeplacer = new InfoDeplacer();
  3805.             $objetInfoDeplacer->setLigneCommande($objetLigneCommande);
  3806.             $objetInfoDeplacer->setEntrepot($entrepot);
  3807.             $objetInfoDeplacer->setQuantite($quantite);
  3808.             $objetInfoDeplacer->setNumeroLot($numeroLot);
  3809.             $objetInfoDeplacer->setDateLivraison($dateEnvoi);
  3810.             $objetInfoDeplacer->setTypeDeplacement($typeDeplacement);
  3811.             // $montantCommande = (int) $montantCommande + (int) $montant;
  3812.             $em->persist($objetInfoDeplacer);
  3813.             $em->flush();
  3814.             $em->getConnection()->commit();
  3815.         } catch (\Exception $e) {
  3816.             $em->getConnection()->rollback();
  3817.             $em->close();
  3818.             throw $e;
  3819.         }
  3820.         return  $objetInfoDeplacer;
  3821.     
  3822. }
  3823. function traiteFonctionDonneeImage($em$JSONData$parameters$surfaceAnneeRepository$inspectionRempliRepository$producteurRepository$imageRepository$type)
  3824.     { ///Revoir comment aj()outer l'abonne
  3825.         if($type == 2)
  3826.             $listImage $JSONData;
  3827.         else
  3828.             $listImage json_decode($JSONDatatrue);
  3829.         $em->getConnection()->beginTransaction();
  3830.         //$donnee = $unProducteur["nom"] ."#". $unProducteur["prenoms"] ."#".$unProducteur["telephone"] ."#". $unProducteur["idVille"] ."#".$unProducteur["codeGenere"]  ."#".$unProducteur["idutil"] ."#".$unProducteur["sexe"]."#".$unProducteur["cni"]  ;
  3831.         $codeGenere "0001";
  3832.         if ($listImage  != null) {
  3833.             foreach ($listImage as $uneImage) {
  3834.                 //$votreImage = base64_decode($parameters['image'.$uneImage["id"]]);
  3835.                 $file_path =   __DIR__ '/../../../public/';
  3836.                 $dossier "producteur/";
  3837.                 
  3838.                 if(array_key_exists('image' $uneImage["id"], $parameters)){
  3839.                     if($type == 2)
  3840.                         $urlImage $parameters['path'];
  3841.                     else
  3842.                         $urlImage  $parameters['image' $uneImage["id"]];
  3843.                     if ($uneImage["typeImage"] == 2) {
  3844.                         $media str_replace('data:audio/mpeg;base64,Base64EncodedMP3Data'''$urlImage);
  3845.                         $media str_replace(' ''+'$media);
  3846.                         $nameImage "audio_" uniqid() . "_" $uneImage["id"] . '.mp3';
  3847.                     } else {
  3848.                         $media str_replace('data:image/png;base64,'''$urlImage);
  3849.                         $media str_replace(' ''+'$media);
  3850.                         $nameImage "signature_" uniqid() . "_" $uneImage["id"] . '.png';
  3851.                     }
  3852.                 
  3853.                     // Create Image path with Image name and Extension
  3854.                     $file $file_path $dossier $nameImage;
  3855.                     // Decode the Base64 encoded Image
  3856.                     if ($uneImage["typeImage"] == 2)
  3857.                         $data base64_decode($urlImage);
  3858.                     else
  3859.                         $data base64_decode($media);
  3860.                     // Save Image in the Image Directory
  3861.                     $success file_put_contents($file$data);
  3862.                     //$file_path = $file_path . base64_decode( $_FILES['image'.$uneImage["id"]]['name']);
  3863.                     $objetImage null;
  3864.                     if ($uneImage["typeImage"] != 3)
  3865.                         $objetImage $imageRepository->findOneBy(array("titreImage" => $uneImage["codeGenere"]));
  3866.                     if ($objetImage == null) {
  3867.                         $objetImage = new Image();
  3868.                         $objetImage->setUrlImage($dossier $nameImage);
  3869.                         if ($uneImage["typeImage"] == 3) {
  3870.                             $objetSurfaceAnnee $surfaceAnneeRepository->findOneBy(array("codeGenere" => $uneImage['prodCodeGenere']));
  3871.                             if ($objetSurfaceAnnee != null)
  3872.                                 $objetImage->setSurfaceannee($objetSurfaceAnnee);
  3873.                         }
  3874.                         if ($uneImage["typeImage"] == 10) {
  3875.                             $objetProducteur $producteurRepository->findOneBy(array("codeGenere" => $uneImage['prodCodeGenere']));
  3876.                             if ($objetProducteur != null)
  3877.                                 $objetImage->setProducteur($objetProducteur);
  3878.                         } else {
  3879.                             $objetInspectionRempli $inspectionRempliRepository->findOneBy(array("codeGenere" => $uneImage['prodCodeGenere']));
  3880.                             if ($objetInspectionRempli != null)
  3881.                                 $objetImage->setInspectionrempli($objetInspectionRempli);
  3882.                         }
  3883.                         $objetImage->setCodeGenere($uneImage["prodCodeGenere"]);
  3884.                         $objetImage->setElementCodeGenere($uneImage["prodCodeGenere"]);
  3885.                         $objetImage->setTitreImage($uneImage["codeGenere"]);
  3886.                         $em->persist($objetImage);
  3887.                         $em->flush($objetImage);
  3888.                     }
  3889.                 }
  3890.             }
  3891.         }
  3892.         $em->getConnection()->commit();
  3893.     }
  3894.     function getChatBatInspection($em,$abonneId$inspectionId ){
  3895.             $i=0;  
  3896.             $tabDonnee = [1,2,3,4,5,6,7,8,9,10,11,12];
  3897.             $tabDonneeInspection = array();
  3898.             $tabDonneeMois= array();
  3899.             $infoInspection = array();
  3900.             
  3901.             //var_dump(1);exit; 
  3902.             foreach ($tabDonnee as $uneDonneeMois  ) {
  3903.                 
  3904.                 $infoInspection =$this->getStatInspectionAction($em,$abonneId$inspectionId$uneDonneeMois)  ;
  3905.                 
  3906.                 $tabDonneeMois[$i]= $this->traiteInfoMois($uneDonneeMois);
  3907.                 if(count($infoInspection)!=)
  3908.                     $tabDonneeInspection[$i] =  $infoInspection[0]['total'];   
  3909.                 else
  3910.                     $tabDonneeInspection[$i] =  0;
  3911.                 $i++;
  3912.                
  3913.             }
  3914.             return [$tabDonneeMois$tabDonneeInspection];
  3915.     }
  3916.     public function getStatSuivrelocalisationAction(EntityManager $em,$abonneId$groupementId$zoneId$siP=0$partenaireId=0$typeAction=0$siListe=0$avecLocalisation=0$agentId 0) {
  3917.         try {
  3918.             if($siListe==0)
  3919.                 $sqlrech 'SELECT DISTINCT(sa.id) as parcelle_id, u.nom_user, u.prenoms_user, u.tel1_user, u.sexe_user,  u.date_ajout_user as date_ajout,  p.code_genere as code_producteur, sa.code_genere as code_surface,  sa.superficie, sa.superficie_reelle, pr.nom_produit, p.id as producteur_id';
  3920.             else
  3921.                 $sqlrech 'SELECT Count(DISTINCT(sa.id)) as total ';
  3922.             $sqlrech .= '
  3923.                             FROM surface_annee sa
  3924.                             INNER JOIN produit pr on sa.produit_id = pr.id
  3925.                              ';
  3926.                 /*if($groupementId != 0 || $zoneId !=0)*/
  3927.                     $sqlrech .= " INNER JOIN producteur p  on sa.producteur_id  = p.id
  3928.                                   INNER JOIN utilisateur u on p.utilisateur_id = u.id
  3929.                 ";
  3930.                 if($groupementId != 0){
  3931.                     $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.producteur_id = p.id
  3932.                                     INNER JOIN groupement g on gp.groupement_id = g.id' ;
  3933.                 }
  3934.                 if($zoneId != 0){
  3935.                     $sqlrech .= '   INNER JOIN zone_producteur zp on zp.producteur_id = p.id
  3936.                                     INNER JOIN ville v on zp.ville_id = v.id' ;
  3937.                 }
  3938.                 if($typeAction != 0){
  3939.                     $sqlrech .= " INNER JOIN surface_abonne sab on sab.surfaceannee_id  = sa.id ";
  3940.                     $sqlrech .= " INNER JOIN abonne a on sab.abonne_id =  a.id ";
  3941.                     if($typeAction == &&  $partenaireId != 0)
  3942.                         $sqlrech .= " INNER JOIN partenaire pt on sab.partenaire_id = pt.id ";
  3943.                 }else{
  3944.                     $sqlrech .= " INNER JOIN abonne a on sa.abonne_id  = a.id";
  3945.                 }
  3946.                 if($avecLocalisation == 0){
  3947.                     $sqlrech .= " LEFT JOIN localisation l ON l.surfaceannee_id = sa.id ";
  3948.                 }else if($avecLocalisation == 1){
  3949.                     $sqlrech .= " INNER JOIN localisation l ON l.surfaceannee_id = sa.id 
  3950.                                 INNER JOIN utilisateur ut on ut.id = l.utilisateur_id ";
  3951.                 }
  3952.                 $sqlrech .= " WHERE sa.etat_surface_annee =1 ";
  3953.                 if($siP==0//on a pas touché la parcelle mais pas de localisation recu !
  3954.                     $sqlrech .= ' AND sa.superficie_reelle IS NOT NULL AND l.surfaceannee_id is null ';
  3955.                 elseif($siP==1//Pas d'activité de localisation sur la parcelle sur la parcelle
  3956.                     $sqlrech .= ' AND sa.superficie_reelle IS  NULL AND l.surfaceannee_id IS NOT NULL ';
  3957.                 elseif($siP==2)//Données surface Parcelle null mais on a les valeurs sur les points de localisation mais on n'a pas de point de localisation
  3958.                     $sqlrech .= " AND ( sa.superficie_reelle ='null' OR sa.superficie_reelle = '0' ) AND l.tab_polygone = '0' ";
  3959.                 elseif($siP==3//Parcelle null mais on a les valeurs sur les points de localisation
  3960.                     $sqlrech .= " AND ( sa.superficie_reelle !='null' AND sa.superficie_reelle !='0' AND sa.superficie_reelle IS  NOT NULL  ) AND (l.tab_polygone != '0' AND l.tab_polygone != '')  ";
  3961.                 elseif($siP==4//Parcelle null mais on a les valeurs sur les points de localisation
  3962.                     $sqlrech .= " AND ( sa.superficie_reelle ='null' OR sa.superficie_reelle ='0' OR sa.superficie_reelle IS  NULL ) AND (l.tab_polygone != '0' AND l.tab_polygone != '')  ";
  3963.                 elseif($siP==5//Parcelle null mais on a les valeurs sur les points de localisation
  3964.                     $sqlrech .= " AND ( sa.superficie_reelle !='null' AND sa.superficie_reelle !='0' AND sa.superficie_reelle IS  NOT NULL ) AND (l.tab_polygone = '0' OR l.tab_polygone = '')  ";
  3965.                 elseif($siP==6//Parcelle null mais on a les valeurs sur les points de localisation
  3966.                     $sqlrech .= " AND ( sa.superficie_reelle ='null' OR sa.superficie_reelle ='0' ) AND (l.tab_polygone = '0' OR l.tab_polygone = '')  ";
  3967.                 else
  3968.                     $sqlrech .= ' ';        
  3969.                 if($typeAction == &&  $partenaireId != 0)
  3970.                     $sqlrech .= " AND  pt.id =:partenaireId  ";
  3971.                 if($groupementId != )
  3972.                     $sqlrech .= " AND  g.id =:groupementId  ";
  3973.                 if($typeAction == || $typeAction == 1)
  3974.                     $sqlrech .= " AND  a.id =:abonneId  ";
  3975.                 if($agentId != )
  3976.                     $sqlrech .= " AND  ut.id =:agentId  ";
  3977.                 if($zoneId != )
  3978.                     $sqlrech .= " AND  v.id =:zoneId  ";
  3979.                 //var_dump($sqlrech);
  3980.                 //INNER JOIN produit_abonne pa on pa.produit_id  = p.id
  3981.                 $stmt $em->getConnection()->prepare($sqlrech);
  3982.                 if($typeAction == &&  $partenaireId != 0)
  3983.                     $stmt->bindValue(':partenaireId'$partenaireIdPDO::PARAM_INT);
  3984.                 
  3985.                 if($groupementId != )
  3986.                     $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  3987.                 if($agentId != )
  3988.                     $stmt->bindValue(':agentId'$agentIdPDO::PARAM_INT);
  3989.                 if($zoneId != )
  3990.                     $stmt->bindValue(':zoneId'$zoneIdPDO::PARAM_INT);
  3991.                 if($typeAction == || $typeAction == 1)
  3992.                     $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  3993.             $stmt->execute();
  3994.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  3995.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3996.             $stmt null;
  3997.             $res null;
  3998.             var_dump($e->getMessage());
  3999.         }
  4000.         return $res;
  4001.     }
  4002.     public function getStatSuivreSurfaceAction(EntityManager $em,$abonneId$groupementId$zoneId$siP=0$partenaireId=0$typeAction=0$siListe=0$avecLocalisation=0$agentId 0$limite=5$siInfoOrderBy=2) {
  4003.         try {
  4004.             if($siListe==0)
  4005.                 $sqlrech 'SELECT DISTINCT(sa.id) as parcelle_id, u.nom_user, u.prenoms_user, u.tel1_user, u.sexe_user,  u.date_ajout_user as date_ajout,  p.code_genere as code_producteur, sa.code_genere as code_surface,  sa.superficie, sa.superficie_reelle, pr.nom_produit, p.id as producteur_id';
  4006.             else
  4007.                 $sqlrech 'SELECT Count(DISTINCT(sa.id)) as total ';
  4008.             $sqlrech .= '
  4009.                             FROM surface_annee sa
  4010.                             INNER JOIN produit pr on sa.produit_id = pr.id
  4011.                             
  4012.                              ';
  4013.                 /*if($groupementId != 0 || $zoneId !=0)*/
  4014.                     $sqlrech .= 
  4015.                                   INNER JOIN producteur p  on sa.producteur_id  = p.id
  4016.                                   INNER JOIN utilisateur u on p.utilisateur_id = u.id
  4017.                 ";
  4018.                 if($groupementId != 0){
  4019.                     $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.producteur_id = p.id
  4020.                                     INNER JOIN groupement g on gp.groupement_id = g.id' ;
  4021.                 }
  4022.                 if($zoneId != 0){
  4023.                     $sqlrech .= '   INNER JOIN zone_producteur zp on zp.producteur_id = p.id
  4024.                                     INNER JOIN ville v on zp.ville_id = v.id' ;
  4025.                 }
  4026.                 if($typeAction != 0){
  4027.                     $sqlrech .= " INNER JOIN producteur_abonne pab on pab.producteur_id  = p.id ";
  4028.                     $sqlrech .= " INNER JOIN abonne a on pab.abonne_id =  a.id ";
  4029.                     if($typeAction == &&  $partenaireId != 0)
  4030.                         $sqlrech .= " INNER JOIN partenaire pt on pab.partenaire_id = pt.id ";
  4031.                 }else{
  4032.                     $sqlrech .= " INNER JOIN abonne a on p.abonne_id  = a.id";
  4033.                 }
  4034.                 
  4035.                 $sqlrech .= " WHERE   p.etat_prod =1 ";
  4036.                       
  4037.                 if($typeAction == &&  $partenaireId != 0)
  4038.                     $sqlrech .= " AND  pt.id =:partenaireId  ";
  4039.                 if($groupementId != )
  4040.                     $sqlrech .= " AND  g.id =:groupementId  ";
  4041.                 if($agentId != )
  4042.                     $sqlrech .= " AND  ut.id =:agentId  ";
  4043.                 if($zoneId != )
  4044.                     $sqlrech .= " AND  v.id =:zoneId  ";
  4045.                 
  4046.                 if($typeAction == || $typeAction == 1)
  4047.                     $sqlrech .= " AND  a.id =:abonneId  ";
  4048.                
  4049.                 if($limite !=0)
  4050.                     $sqlrech .= " LIMIT ".$limite ;
  4051.                 //var_dump($sqlrech);
  4052.                 //INNER JOIN produit_abonne pa on pa.produit_id  = p.id
  4053.                 $stmt $em->getConnection()->prepare($sqlrech);
  4054.                 if($typeAction == &&  $partenaireId != 0)
  4055.                     $stmt->bindValue(':partenaireId'$partenaireIdPDO::PARAM_INT);
  4056.                 
  4057.                 if($groupementId != )
  4058.                     $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  4059.                 if($agentId != )
  4060.                     $stmt->bindValue(':agentId'$agentIdPDO::PARAM_INT);
  4061.                 if($zoneId != )
  4062.                     $stmt->bindValue(':zoneId'$zoneIdPDO::PARAM_INT);
  4063.                 if($typeAction == || $typeAction == 1)
  4064.                     $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  4065.             $stmt->execute();
  4066.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  4067.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  4068.             $stmt null;
  4069.             $res null;
  4070.             var_dump($e->getMessage());
  4071.         }
  4072.         return $res;
  4073.     }
  4074.     public function getStatStatsSurfaceAction(EntityManager $em,$abonneId$groupementId$zoneId$siP=0$partenaireId=0$typeAction=0$siListe=0$avecLocalisation=0$agentId 0$limite=5$siSigne=1$supTotal) {
  4075.         try {
  4076.             if($siListe==0)
  4077.                 $sqlrech 'SELECT DISTINCT(sa.id) as parcelle_id, u.nom_user, u.prenoms_user, u.tel1_user, u.sexe_user,  u.date_ajout_user as date_ajout,  p.code_genere as code_producteur, sa.code_genere as code_surface,  sa.superficie, sa.superficie_reelle, pr.nom_produit, p.id as producteur_id';
  4078.             else
  4079.                 $sqlrech 'SELECT Count(DISTINCT(sa.id)) as total ';
  4080.             $sqlrech .= '
  4081.                             FROM surface_annee sa
  4082.                             INNER JOIN produit pr on sa.produit_id = pr.id
  4083.                             
  4084.                              ';
  4085.                 /*if($groupementId != 0 || $zoneId !=0)*/
  4086.                     $sqlrech .= 
  4087.                                   INNER JOIN producteur p  on sa.producteur_id  = p.id
  4088.                                   INNER JOIN utilisateur u on p.utilisateur_id = u.id
  4089.                 ";
  4090.                 if($groupementId != 0){
  4091.                     $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.producteur_id = p.id
  4092.                                     INNER JOIN groupement g on gp.groupement_id = g.id' ;
  4093.                 }
  4094.                 if($zoneId != 0){
  4095.                     $sqlrech .= '   INNER JOIN zone_producteur zp on zp.producteur_id = p.id
  4096.                                     INNER JOIN ville v on zp.ville_id = v.id' ;
  4097.                 }
  4098.                 if($typeAction != 0){
  4099.                     $sqlrech .= " INNER JOIN producteur_abonne pab on pab.producteur_id  = p.id ";
  4100.                     $sqlrech .= " INNER JOIN abonne a on pab.abonne_id =  a.id ";
  4101.                     if($typeAction == &&  $partenaireId != 0)
  4102.                         $sqlrech .= " INNER JOIN partenaire pt on pab.partenaire_id = pt.id ";
  4103.                 }else{
  4104.                     $sqlrech .= " INNER JOIN abonne a on p.abonne_id  = a.id";
  4105.                 }
  4106.                 
  4107.                 $sqlrech .= " WHERE  p.etat_prod =1 ";
  4108.                       
  4109.                 if($typeAction == &&  $partenaireId != 0)
  4110.                     $sqlrech .= " AND  pt.id =:partenaireId  ";
  4111.                 if($groupementId != )
  4112.                     $sqlrech .= " AND  g.id =:groupementId  ";
  4113.                 if($agentId != )
  4114.                     $sqlrech .= " AND  ut.id =:agentId  ";
  4115.                 if($zoneId != )
  4116.                     $sqlrech .= " AND  v.id =:zoneId  ";
  4117.                 if($typeAction == || $typeAction == 1)
  4118.                     $sqlrech .= " AND  a.id =:abonneId  ";
  4119.                 if ($siSigne == 1)
  4120.                     $sqlrech .= " AND sa.superficie < 1 ";
  4121.                 elseif ($siSigne == 2)
  4122.                     $sqlrech .= " AND sa.superficie >= 1 AND sa.superficie <= :supTotal ";
  4123.                 elseif ($siSigne == 3)
  4124.                     $sqlrech .= " AND sa.superficie >= :supTotal";
  4125.                 if($limite !=0)
  4126.                     $sqlrech .= " LIMIT ".$limite ;
  4127.                 //var_dump($sqlrech);exit;
  4128.                 //INNER JOIN produit_abonne pa on pa.produit_id  = p.id
  4129.                 $stmt $em->getConnection()->prepare($sqlrech);
  4130.                 if($typeAction == &&  $partenaireId != 0)
  4131.                     $stmt->bindValue(':partenaireId'$partenaireIdPDO::PARAM_INT);
  4132.                 
  4133.                 if($groupementId != )
  4134.                     $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  4135.                 if($agentId != )
  4136.                     $stmt->bindValue(':agentId'$agentIdPDO::PARAM_INT);
  4137.                 if($zoneId != )
  4138.                     $stmt->bindValue(':zoneId'$zoneIdPDO::PARAM_INT);
  4139.                 if ($siSigne != 1){
  4140.                     if($supTotal != )
  4141.                         $stmt->bindValue(':supTotal'$supTotalPDO::PARAM_INT);
  4142.                 }
  4143.                 if($typeAction == || $typeAction == 1)
  4144.                     $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  4145.             $stmt->execute();
  4146.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  4147.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  4148.             $stmt null;
  4149.             $res null;
  4150.             var_dump($e->getMessage());
  4151.         }
  4152.         return $res;
  4153.     }
  4154.     public function getStatMinMaxSurfaceAction(EntityManager $em,$abonneId$groupementId$zoneId$siP=0$partenaireId=0$typeAction=0$siListe=0$avecLocalisation=0$agentId 0$limite=5) {
  4155.         
  4156.         try {
  4157.             if($siListe==0)
  4158.                 $sqlrech 'SELECT MIN(sa.superficie) as superficie_min,  MAX(sa.superficie) as superficie_max, AVG(sa.superficie) as superficie_moyen ';
  4159.             else
  4160.                 $sqlrech 'SELECT Count(DISTINCT(sa.id)) as total ';
  4161.             $sqlrech .= '
  4162.                             FROM surface_annee sa
  4163.                             INNER JOIN produit pr on sa.produit_id = pr.id
  4164.                             
  4165.                              ';
  4166.                 /*if($groupementId != 0 || $zoneId !=0)*/
  4167.                     $sqlrech .= 
  4168.                                   INNER JOIN producteur p  on sa.producteur_id  = p.id
  4169.                                   INNER JOIN utilisateur u on p.utilisateur_id = u.id
  4170.                 ";
  4171.                 if($groupementId != 0){
  4172.                     $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.producteur_id = p.id
  4173.                                     INNER JOIN groupement g on gp.groupement_id = g.id' ;
  4174.                 }
  4175.                 if($zoneId != 0){
  4176.                     $sqlrech .= '   INNER JOIN zone_producteur zp on zp.producteur_id = p.id
  4177.                                     INNER JOIN ville v on zp.ville_id = v.id' ;
  4178.                 }
  4179.                 if($typeAction != 0){
  4180.                     $sqlrech .= " INNER JOIN producteur_abonne pab on pab.producteur_id  = p.id ";
  4181.                     $sqlrech .= " INNER JOIN abonne a on pab.abonne_id =  a.id ";
  4182.                     if($typeAction == &&  $partenaireId != 0)
  4183.                         $sqlrech .= " INNER JOIN partenaire pt on pab.partenaire_id = pt.id ";
  4184.                 }else{
  4185.                     $sqlrech .= " INNER JOIN abonne a on p.abonne_id  = a.id";
  4186.                 }
  4187.                 
  4188.                 $sqlrech .= " WHERE     p.etat_prod =1 ";
  4189.                       
  4190.                 if($typeAction == &&  $partenaireId != 0)
  4191.                     $sqlrech .= " AND  pt.id =:partenaireId  ";
  4192.                 if($groupementId != )
  4193.                     $sqlrech .= " AND  g.id =:groupementId  ";
  4194.                 if($agentId != )
  4195.                     $sqlrech .= " AND  ut.id =:agentId  ";
  4196.                 if($zoneId != )
  4197.                     $sqlrech .= " AND  v.id =:zoneId  ";
  4198.                 if($typeAction == || $typeAction == 1)
  4199.                     $sqlrech .= " AND  a.id =:abonneId  ";
  4200.                 if($limite !=0)
  4201.                     $sqlrech .= " LIMIT ".$limite ;
  4202.                 //var_dump($sqlrech);
  4203.                 //INNER JOIN produit_abonne pa on pa.produit_id  = p.id
  4204.                 $stmt $em->getConnection()->prepare($sqlrech);
  4205.                 if($typeAction == &&  $partenaireId != 0)
  4206.                     $stmt->bindValue(':partenaireId'$partenaireIdPDO::PARAM_INT);
  4207.                 
  4208.                 if($groupementId != )
  4209.                     $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  4210.                 if($agentId != )
  4211.                     $stmt->bindValue(':agentId'$agentIdPDO::PARAM_INT);
  4212.                 if($zoneId != )
  4213.                     $stmt->bindValue(':zoneId'$zoneIdPDO::PARAM_INT);
  4214.                
  4215.                 
  4216.                 if($typeAction == || $typeAction == 1)
  4217.                     $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  4218.             $stmt->execute();
  4219.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  4220.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  4221.             $stmt null;
  4222.             $res null;
  4223.             var_dump($e->getMessage());
  4224.         }
  4225.         return $res;
  4226.     }
  4227.     public function getStatSuivreProducteurAction(EntityManager $em,$abonneId$groupementId$zoneId$siP=0$partenaireId=0$typeAction=0$siListe=0$avecLocalisation=0$agentId 0$limite=5$siInfoOrderBy=2) {
  4228.         try {
  4229.             if($siListe==0)
  4230.                 $sqlrech 'SELECT DISTINCT(p.id) as producteur, u.nom_user, u.prenoms_user, u.tel1_user, u.sexe_user,  u.date_ajout_user as date_ajout,  p.code_genere as code_producteur ';
  4231.             else
  4232.                 $sqlrech 'SELECT Count(DISTINCT(p.id)) as total ';
  4233.             $sqlrech .= '
  4234.                             FROM producteur p
  4235.                             
  4236.                              ';
  4237.                 /*if($groupementId != 0 || $zoneId !=0)*/
  4238.                     $sqlrech .= 
  4239.                                   INNER JOIN utilisateur u on p.utilisateur_id = u.id
  4240.                 ";
  4241.                 if($groupementId != 0){
  4242.                     $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.producteur_id = p.id
  4243.                                     INNER JOIN groupement g on gp.groupement_id = g.id' ;
  4244.                 }
  4245.                 if($zoneId != 0){
  4246.                     $sqlrech .= '   INNER JOIN zone_producteur zp on zp.producteur_id = p.id
  4247.                                     INNER JOIN ville v on zp.ville_id = v.id' ;
  4248.                 }
  4249.                 if($typeAction != 0){
  4250.                     $sqlrech .= " INNER JOIN producteur_abonne pab on pab.producteur_id  = p.id ";
  4251.                     $sqlrech .= " INNER JOIN abonne a on pab.abonne_id =  a.id ";
  4252.                     if($typeAction == &&  $partenaireId != 0)
  4253.                         $sqlrech .= " INNER JOIN partenaire pt on pab.partenaire_id = pt.id ";
  4254.                 }else{
  4255.                     $sqlrech .= " INNER JOIN abonne a on p.abonne_id  = a.id";
  4256.                 }
  4257.                 
  4258.                 $sqlrech .= " WHERE  p.etat_prod =1 ";
  4259.                      
  4260.                 if($typeAction == || $typeAction == 1)
  4261.                     $sqlrech .= " AND  a.id =:abonneId  ";
  4262.                 if($typeAction == &&  $partenaireId != 0)
  4263.                     $sqlrech .= " AND  pt.id =:partenaireId  ";
  4264.                 if($groupementId != )
  4265.                     $sqlrech .= " AND  g.id =:groupementId  ";
  4266.                 if($agentId != )
  4267.                     $sqlrech .= " AND  ut.id =:agentId  ";
  4268.                 if($zoneId != )
  4269.                     $sqlrech .= " AND  v.id =:zoneId  ";
  4270.                 if ($siInfoOrderBy == 1)
  4271.                     $sqlrech .= " ORDER BY p.date_visite DESC ";
  4272.                 elseif ($siInfoOrderBy == 2)
  4273.                     $sqlrech .= " ORDER BY p.date_publication DESC ";
  4274.                 if($limite !=0)
  4275.                     $sqlrech .= " LIMIT ".$limite ;
  4276.                 //var_dump($sqlrech);
  4277.                 //INNER JOIN produit_abonne pa on pa.produit_id  = p.id
  4278.                 $stmt $em->getConnection()->prepare($sqlrech);
  4279.                 if($typeAction == &&  $partenaireId != 0)
  4280.                     $stmt->bindValue(':partenaireId'$partenaireIdPDO::PARAM_INT);
  4281.                 
  4282.                 if($groupementId != )
  4283.                     $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  4284.                 if($agentId != )
  4285.                     $stmt->bindValue(':agentId'$agentIdPDO::PARAM_INT);
  4286.                 if($zoneId != )
  4287.                     $stmt->bindValue(':zoneId'$zoneIdPDO::PARAM_INT);
  4288.                 if($typeAction == || $typeAction == 1)
  4289.                     $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  4290.             $stmt->execute();
  4291.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  4292.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  4293.             $stmt null;
  4294.             $res null;
  4295.             var_dump($e->getMessage());
  4296.         }
  4297.         return $res;
  4298.     }
  4299.     public function getInfoAgeAction(EntityManager $em,$abonneId$groupementId$zoneId$siP=0$partenaireId=0$typeAction=0$siListe=0$avecLocalisation=0$agentId 0) {
  4300.         try {
  4301.             $sqlrech '
  4302.                 SELECT 
  4303.                     MIN(TIMESTAMPDIFF(YEAR, u.date_naissance, CURDATE())) AS age_minimal,
  4304.                     MAX(TIMESTAMPDIFF(YEAR, u.date_naissance, CURDATE())) AS age_maximal
  4305.             ';
  4306.             
  4307.             $sqlrech .= '
  4308.                             FROM surface_annee sa
  4309.                             INNER JOIN produit pr on sa.produit_id = pr.id
  4310.                              ';
  4311.             /*if($groupementId != 0 || $zoneId !=0)*/
  4312.             $sqlrech .= " INNER JOIN producteur p  on sa.producteur_id  = p.id
  4313.                                 INNER JOIN utilisateur u on p.utilisateur_id = u.id
  4314.                 ";
  4315.             if($groupementId != 0){
  4316.                 $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.producteur_id = p.id
  4317.                                 INNER JOIN groupement g on gp.groupement_id = g.id' ;
  4318.             }
  4319.             if($zoneId != 0){
  4320.                 $sqlrech .= '   INNER JOIN zone_producteur zp on zp.producteur_id = p.id
  4321.                                 INNER JOIN ville v on zp.ville_id = v.id' ;
  4322.             }
  4323.             if($typeAction != 0){
  4324.                 $sqlrech .= " INNER JOIN surface_abonne sab on sab.surfaceannee_id  = sa.id ";
  4325.                 $sqlrech .= " INNER JOIN abonne a on sab.abonne_id =  a.id ";
  4326.                 if($typeAction == &&  $partenaireId != 0)
  4327.                     $sqlrech .= " INNER JOIN partenaire pt on sab.partenaire_id = pt.id ";
  4328.             }else{
  4329.                 $sqlrech .= " INNER JOIN abonne a on sa.abonne_id  = a.id";
  4330.             }
  4331.             if($avecLocalisation == 0){
  4332.                 $sqlrech .= " LEFT JOIN localisation l ON l.surfaceannee_id = sa.id ";
  4333.             }else if($avecLocalisation == 1){
  4334.                 $sqlrech .= " INNER JOIN localisation l ON l.surfaceannee_id = sa.id 
  4335.                             INNER JOIN utilisateur ut on ut.id = l.utilisateur_id ";
  4336.             }
  4337.             $sqlrech .= " WHERE  sa.etat_surface_annee =1 ";
  4338.                   
  4339.             if($typeAction == &&  $partenaireId != 0)
  4340.                 $sqlrech .= " AND  pt.id =:partenaireId  ";
  4341.             if($groupementId != )
  4342.                 $sqlrech .= " AND  g.id =:groupementId  ";
  4343.             if($typeAction == || $typeAction == 1)
  4344.                 $sqlrech .= " AND  a.id =:abonneId  ";
  4345.             if($agentId != )
  4346.                 $sqlrech .= " AND  ut.id =:agentId  ";
  4347.             if($zoneId != )
  4348.                 $sqlrech .= " AND  v.id =:zoneId  ";
  4349.             //var_dump($sqlrech);
  4350.             //INNER JOIN produit_abonne pa on pa.produit_id  = p.id
  4351.             $stmt $em->getConnection()->prepare($sqlrech);
  4352.             if($typeAction == &&  $partenaireId != 0)
  4353.                 $stmt->bindValue(':partenaireId'$partenaireIdPDO::PARAM_INT);
  4354.             
  4355.             if($groupementId != )
  4356.                 $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  4357.             if($agentId != )
  4358.                 $stmt->bindValue(':agentId'$agentIdPDO::PARAM_INT);
  4359.             if($zoneId != )
  4360.                 $stmt->bindValue(':zoneId'$zoneIdPDO::PARAM_INT);
  4361.             if($typeAction == || $typeAction == 1)
  4362.                 $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  4363.             $stmt->execute();
  4364.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  4365.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  4366.             $stmt null;
  4367.             $res null;
  4368.             var_dump($e->getMessage());
  4369.         }
  4370.         return $res;
  4371.     }
  4372.     
  4373.     public function getListeInfoGroupementZoneAction(EntityManager $em,$abonneId$groupementId$zoneId$siInfoOrderBy=0$partenaireId=0$typeAction=0$siListe=0$avecLocalisation=0$agentId 0) {
  4374.         try {
  4375.             if($siListe==0)
  4376.                 $sqlrech 'SELECT Count(DISTINCT(g.id)) as total_groupement ';
  4377.             else
  4378.                 $sqlrech 'SELECT Count(DISTINCT(v.id)) as total_zone ';
  4379.             $sqlrech .= '
  4380.                             FROM surface_annee sa
  4381.                             INNER JOIN produit pr on sa.produit_id = pr.id
  4382.                              ';
  4383.             $sqlrech .= " INNER JOIN producteur p  on sa.producteur_id  = p.id
  4384.                                 INNER JOIN utilisateur u on p.utilisateur_id = u.id
  4385.             ";
  4386.             
  4387.             $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.producteur_id = p.id
  4388.                             INNER JOIN groupement g on gp.groupement_id = g.id' ;
  4389.             
  4390.             
  4391.             $sqlrech .= '   INNER JOIN zone_producteur zp on zp.producteur_id = p.id
  4392.                             INNER JOIN ville v on zp.ville_id = v.id' ;
  4393.             
  4394.             if($typeAction != 0){
  4395.                 $sqlrech .= " INNER JOIN surface_abonne sab on sab.surfaceannee_id  = sa.id ";
  4396.                 $sqlrech .= " INNER JOIN abonne a on sab.abonne_id =  a.id ";
  4397.                 if($typeAction == &&  $partenaireId != 0)
  4398.                     $sqlrech .= " INNER JOIN partenaire pt on sab.partenaire_id = pt.id ";
  4399.             }else{
  4400.                 $sqlrech .= " INNER JOIN abonne a on sa.abonne_id  = a.id";
  4401.             }
  4402.             $sqlrech .= " WHERE   sa.etat_surface_annee =1 ";
  4403.                     
  4404.             if($typeAction == &&  $partenaireId != 0)
  4405.                 $sqlrech .= " AND  pt.id =:partenaireId  ";
  4406.             if($groupementId != )
  4407.                 $sqlrech .= " AND  g.id =:groupementId  ";
  4408.             if($agentId != )
  4409.                 $sqlrech .= " AND  ut.id =:agentId  ";
  4410.             if($zoneId != )
  4411.                 $sqlrech .= " AND  v.id =:zoneId  ";
  4412.             
  4413.             if($typeAction == || $typeAction == 1)
  4414.                 $sqlrech .= " AND  a.id =:abonneId  ";
  4415.             $stmt $em->getConnection()->prepare($sqlrech);
  4416.             if($typeAction == &&  $partenaireId != 0)
  4417.                 $stmt->bindValue(':partenaireId'$partenaireIdPDO::PARAM_INT);
  4418.             
  4419.             if($groupementId != )
  4420.                 $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  4421.             if($agentId != )
  4422.                 $stmt->bindValue(':agentId'$agentIdPDO::PARAM_INT);
  4423.             if($zoneId != )
  4424.                 $stmt->bindValue(':zoneId'$zoneIdPDO::PARAM_INT);
  4425.             if($typeAction == || $typeAction == 1)
  4426.                 $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  4427.             $stmt->execute();
  4428.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  4429.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  4430.             $stmt null;
  4431.             $res null;
  4432.             var_dump($e->getMessage());
  4433.         }
  4434.         return $res;
  4435.     }
  4436.     public function  getGroupementZoneByParcelleAction(EntityManager $em,$abonneId$groupementId$zoneId$siP=0$partenaireId=0$typeAction=0$siListe=0$avecLocalisation=0$agentId 0$limite=5$siInfoOrderBy=2) {
  4437.         try {
  4438.             
  4439.             if($siListe==0)
  4440.                 $sqlrech " SELECT g.id AS id,
  4441.                     CONCAT(g.nom_groupement,'-[',a.nom,']') AS nom_groupement,
  4442.                     COUNT(DISTINCT sa.id) AS nombre_parcelles ";
  4443.             else
  4444.                 $sqlrech " SELECT v.id AS id,
  4445.                     CONCAT(v.nom_ville,'-[',a.nom,']') AS nom_ville,
  4446.                     COUNT(DISTINCT sa.id) AS nombre_parcelles ";
  4447.             $sqlrech .= '
  4448.                             FROM surface_annee sa
  4449.                             INNER JOIN produit pr on sa.produit_id = pr.id
  4450.                             
  4451.                             
  4452.                              ';
  4453.                 /*if($groupementId != 0 || $zoneId !=0)*/
  4454.                     $sqlrech .= 
  4455.                                 INNER JOIN producteur p  on sa.producteur_id  = p.id
  4456.                                 INNER JOIN utilisateur u on p.utilisateur_id = u.id
  4457.                 ";
  4458.                 if($siListe ==or $groupementId != 0){
  4459.                     $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.producteur_id = p.id
  4460.                                     INNER JOIN groupement g on gp.groupement_id = g.id' ;
  4461.                 }
  4462.                 if($siListe ==or $zoneId != ){
  4463.                     $sqlrech .= '   INNER JOIN zone_producteur zp on zp.producteur_id = p.id
  4464.                                     INNER JOIN ville v on zp.ville_id = v.id' ;
  4465.                 }
  4466.                 if($typeAction != 0){
  4467.                     $sqlrech .= " INNER JOIN producteur_abonne pab on pab.producteur_id  = p.id ";
  4468.                     $sqlrech .= " INNER JOIN abonne a on pab.abonne_id =  a.id ";
  4469.                     if($typeAction == &&  $partenaireId != 0)
  4470.                         $sqlrech .= " INNER JOIN partenaire pt on pab.partenaire_id = pt.id ";
  4471.                 }else{
  4472.                     $sqlrech .= " INNER JOIN abonne a on p.abonne_id  = a.id";
  4473.                 }
  4474.                 
  4475.                 $sqlrech .= " WHERE  p.etat_prod =1 ";
  4476.                       
  4477.                 if($typeAction == &&  $partenaireId != 0)
  4478.                     $sqlrech .= " AND  pt.id =:partenaireId  ";
  4479.                 if($groupementId != )
  4480.                     $sqlrech .= " AND  g.id =:groupementId  ";
  4481.                 if($agentId != )
  4482.                     $sqlrech .= " AND  ut.id =:agentId  ";
  4483.                 if($zoneId != )
  4484.                     $sqlrech .= " AND  v.id =:zoneId  ";
  4485.                 if($typeAction == || $typeAction == 1)
  4486.                     $sqlrech .= " AND  a.id =:abonneId  ";
  4487.                 if($siListe !=or ($groupementId != 0  or  $zoneId != 0))
  4488.                     $sqlrech .= " GROUP  BY "
  4489.                 if($siListe ==or  $groupementId != )
  4490.                     $sqlrech .= " g.id, g.nom_groupement ";    
  4491.                 if(($siListe ==and  $zoneId != 0) or($groupementId != and $siListe ==1) )
  4492.                     $sqlrech .= ", "
  4493.                 if($siListe ==or $zoneId != )
  4494.                     $sqlrech .= " v.id, v.nom_ville "
  4495.                 
  4496.                 $sqlrech .= " ORDER BY  nombre_parcelles DESC " ;
  4497.                 if($limite !=0)
  4498.                     $sqlrech .= " LIMIT ".$limite ;
  4499.               
  4500.                //var_dump($sqlrech);exit;
  4501.                 //INNER JOIN produit_abonne pa on pa.produit_id  = p.id
  4502.                 $stmt $em->getConnection()->prepare($sqlrech);
  4503.                 if($typeAction == &&  $partenaireId != 0)
  4504.                     $stmt->bindValue(':partenaireId'$partenaireIdPDO::PARAM_INT);
  4505.                 
  4506.                 if($groupementId != )
  4507.                     $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  4508.                 if($agentId != )
  4509.                     $stmt->bindValue(':agentId'$agentIdPDO::PARAM_INT);
  4510.                 if($zoneId != )
  4511.                     $stmt->bindValue(':zoneId'$zoneIdPDO::PARAM_INT);
  4512.                 if($typeAction == || $typeAction == 1)
  4513.                     $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  4514.             $stmt->execute();
  4515.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  4516.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  4517.             $stmt null;
  4518.             $res null;
  4519.             var_dump($e->getMessage());
  4520.         }
  4521.         return $res;
  4522.     }
  4523.     public function getGroupementZoneByProducteurAction(EntityManager $em,$abonneId$groupementId$zoneId$siP=0$partenaireId=0$typeAction=0$siListe=0$avecLocalisation=0$agentId 0$limite=5$siInfoOrderBy=2) {
  4524.         try {
  4525.             
  4526.             
  4527.             if($siListe==0)
  4528.                 $sqlrech " SELECT g.id AS id,
  4529.                    CONCAT(g.nom_groupement,'-[',a.nom,']') AS nom_groupement,
  4530.                     COUNT(DISTINCT p.id) AS nombre_producteurs ";
  4531.             else
  4532.                 $sqlrech " SELECT v.id AS id,
  4533.                    CONCAT(v.nom_ville,'-[',a.nom,']') AS nom_ville,
  4534.                     COUNT(DISTINCT p.id) AS nombre_producteurs ";
  4535.             $sqlrech .= '
  4536.                             FROM producteur p
  4537.                             
  4538.                              ';
  4539.                 /*if($groupementId != 0 || $zoneId !=0)*/
  4540.                     $sqlrech .= 
  4541.                                   INNER JOIN utilisateur u on p.utilisateur_id = u.id
  4542.                 ";
  4543.                 if($siListe ==or $groupementId != 0){
  4544.                     $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.producteur_id = p.id
  4545.                                     INNER JOIN groupement g on gp.groupement_id = g.id' ;
  4546.                 }
  4547.                 if($siListe ==or $zoneId != 0){
  4548.                     $sqlrech .= '   INNER JOIN zone_producteur zp on zp.producteur_id = p.id
  4549.                                     INNER JOIN ville v on zp.ville_id = v.id' ;
  4550.                 }
  4551.                 if($typeAction != 0){
  4552.                     $sqlrech .= " INNER JOIN producteur_abonne pab on pab.producteur_id  = p.id ";
  4553.                     $sqlrech .= " INNER JOIN abonne a on pab.abonne_id =  a.id ";
  4554.                     if($typeAction == &&  $partenaireId != 0)
  4555.                         $sqlrech .= " INNER JOIN partenaire pt on pab.partenaire_id = pt.id ";
  4556.                 }else{
  4557.                     $sqlrech .= " INNER JOIN abonne a on p.abonne_id  = a.id";
  4558.                 }
  4559.                 
  4560.                 $sqlrech .= " WHERE   p.etat_prod =1 ";
  4561.                       
  4562.                 if($typeAction == &&  $partenaireId != 0)
  4563.                     $sqlrech .= " AND  pt.id =:partenaireId  ";
  4564.                 if($groupementId != )
  4565.                     $sqlrech .= " AND  g.id =:groupementId  ";
  4566.                 if($agentId != )
  4567.                     $sqlrech .= " AND  ut.id =:agentId  ";
  4568.                 if($zoneId != )
  4569.                     $sqlrech .= " AND  v.id =:zoneId  ";
  4570.                 if($typeAction == || $typeAction == 1)
  4571.                     $sqlrech .= " AND  a.id =:abonneId  ";
  4572.                 if($siListe ==0)
  4573.                     $sqlrech .= " GROUP BY g.id, g.nom_groupement ";    
  4574.                 if($siListe ==1)
  4575.                     $sqlrech .= " GROUP BY v.id, v.nom_ville "
  4576.                 
  4577.                 $sqlrech .= " ORDER BY  nombre_producteurs DESC " ;
  4578.                 if($limite !=0)
  4579.                     $sqlrech .= " LIMIT ".$limite ;
  4580.               
  4581.                 //INNER JOIN produit_abonne pa on pa.produit_id  = p.id
  4582.                 $stmt $em->getConnection()->prepare($sqlrech);
  4583.                 if($typeAction == &&  $partenaireId != 0)
  4584.                     $stmt->bindValue(':partenaireId'$partenaireIdPDO::PARAM_INT);
  4585.                 
  4586.                 if($groupementId != )
  4587.                     $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  4588.                 if($agentId != )
  4589.                     $stmt->bindValue(':agentId'$agentIdPDO::PARAM_INT);
  4590.                 if($zoneId != )
  4591.                     $stmt->bindValue(':zoneId'$zoneIdPDO::PARAM_INT);
  4592.                 if($typeAction == || $typeAction == 1)
  4593.                     $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  4594.             $stmt->execute();
  4595.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  4596.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  4597.             $stmt null;
  4598.             $res null;
  4599.             var_dump($e->getMessage());
  4600.         }
  4601.         return $res;
  4602.     }
  4603.     public function getStatGeneralStockAction(EntityManager $em$abonneId$siListe$groupementId$zoneId$siP=0$typeAction$partenaireId,$agentId$typeinfo$siSomme=0,$siMoyen =0) {
  4604.         try {
  4605.             if($siMoyen==1){
  4606.                 $sqlrech ' SELECT AVG(il.nbre_total_libre) as moyen ';
  4607.             }else{
  4608.                 if($siP==0){
  4609.                     if($siSomme == 0)
  4610.                         $sqlrech ' SELECT Count(il.id) as total ';
  4611.                     else
  4612.                         $sqlrech ' SELECT SUM(il.nbre_total_libre) as total ';
  4613.                 }else{
  4614.                     $sqlrech ' SELECT il.id, il.nbre_total_libre, il.ref_bon_livraison, il.date_livraison ';
  4615.                 }
  4616.             }
  4617.             if($typeinfo == 1){
  4618.                 $sqlrech .= '
  4619.                                 FROM lignecommande lc
  4620.                                 INNER JOIN livrer l on l.lignecommande_id = lc.id
  4621.                                 INNER JOIN  info_livrer il on il.id = l.infolivrer_id
  4622.                                 INNER JOIN producteur p on lc.producteur_id = p.id 
  4623.                             ' 
  4624.             }else{
  4625.                 $sqlrech .= '
  4626.                                 FROM lignecommande lc
  4627.                                 INNER JOIN livrer l on l.lignecommande_id = lc.id
  4628.                                 INNER JOIN  info_livrer il on il.id = l.infolivrer_id
  4629.                                
  4630.                             ' 
  4631.             }
  4632.             
  4633.             if($typeinfo == 1){
  4634.                 if($siListe ==0){
  4635.                     $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.producteur_id = p.id
  4636.                                     INNER JOIN groupement g on gp.groupement_id = g.id' ;
  4637.                 }
  4638.                 if($siListe ==1){
  4639.                     $sqlrech .= '   INNER JOIN zone_producteur zp on zp.producteur_id = p.id
  4640.                                     INNER JOIN ville v on zp.ville_id = v.id' ;
  4641.                 }
  4642.                 if($typeAction != 0){
  4643.                     $sqlrech .= " INNER JOIN producteur_abonne pab on pab.producteur_id  = p.id ";
  4644.                     $sqlrech .= " INNER JOIN abonne a on pab.abonne_id =  a.id ";
  4645.                     if($typeAction == &&  $partenaireId != 0)
  4646.                         $sqlrech .= " INNER JOIN partenaire pt on pab.partenaire_id = pt.id ";
  4647.                 }else{
  4648.                     $sqlrech .= " INNER JOIN abonne a on lc.abonne_id  = a.id ";
  4649.                 }
  4650.                 
  4651.             }else{
  4652.                 $sqlrech .= " INNER JOIN abonne a on il.abonne_id  = a.id ";
  4653.             }
  4654.             $sqlrech .= " WHERE  1=1 AND  il.etat_info_livrer =1 ";
  4655.             if($abonneId != )
  4656.                 $sqlrech .= " AND  a.id =:abonneId  ";
  4657.             if($typeinfo == 1){
  4658.                 if($typeAction == &&  $partenaireId != 0)
  4659.                     $sqlrech .= " AND  pt.id =:partenaireId  ";
  4660.                 if($groupementId != )
  4661.                     $sqlrech .= " AND  g.id =:groupementId  ";
  4662.                 if($agentId != )
  4663.                     $sqlrech .= " AND  ut.id =:agentId  ";
  4664.                 if($zoneId != )
  4665.                     $sqlrech .= " AND  v.id =:zoneId  ";
  4666.                 if($siListe ==or $groupementId != )
  4667.                     $sqlrech .= " GROUP BY g.id, g.nom_groupement ";    
  4668.                 if($siListe ==or $zoneId != )
  4669.                     $sqlrech .= " GROUP BY v.id, v.nom_ville "
  4670.             }
  4671.             
  4672.                     
  4673.                 $stmt $em->getConnection()->prepare($sqlrech);
  4674.                 if($typeAction == &&  $partenaireId != 0)
  4675.                     $stmt->bindValue(':partenaireId'$partenaireIdPDO::PARAM_INT);
  4676.                 
  4677.                 if($groupementId != )
  4678.                     $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  4679.                 if($agentId != )
  4680.                     $stmt->bindValue(':agentId'$agentIdPDO::PARAM_INT);
  4681.                 if($zoneId != )
  4682.                     $stmt->bindValue(':zoneId'$zoneIdPDO::PARAM_INT);
  4683.                 if($typeAction == || $typeAction == 1)
  4684.                     $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  4685.     
  4686.                 //var_dump($sqlrech);exit;
  4687.                 $stmt->execute();
  4688.                 $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  4689.         
  4690.             } catch (\Symfony\Component\Form\Exception\Exception $e) {
  4691.             $stmt null;
  4692.             $res null;
  4693.             //var_dump($e->getMessage());
  4694.         }
  4695.         return $res;
  4696.     }
  4697.     public function getGroupementZoneByAchatAction(EntityManager $em,$abonneId$groupementId$zoneId$siP=0$partenaireId=0$typeAction=0$siListe=0$siPrix=0$agentId 0$limite=5$siInfoOrderBy=2) {
  4698.         try {
  4699.             $infoPrix ="";
  4700.             if($siPrix== 1)
  4701.                 $infoPrix =", SUM(il.nbre_total_libre * pri.info_prix) as prix_total  ";
  4702.             
  4703.             if($siListe==0)
  4704.                 $sqlrech " SELECT g.id AS id,
  4705.                     CONCAT(g.nom_groupement,'-[', a.nom,']') AS nom_groupement,
  4706.                     COUNT(DISTINCT p.id) AS nombre_producteurs, SUM(il.nbre_total_libre) as total  ".$infoPrix;
  4707.             else
  4708.                 $sqlrech " SELECT v.id AS id,
  4709.                     CONCAT(v.nom_ville,'-[', a.nom,']') AS nom_ville,
  4710.                     COUNT(DISTINCT p.id) AS nombre_producteurs, SUM(il.nbre_total_libre) as total  ".$infoPrix;
  4711.             
  4712.             $sqlrech .= '
  4713.                             FROM lignecommande lc ';
  4714.             if($siPrix== 1)
  4715.                 $sqlrech .= '
  4716.                     INNER JOIN prix_rigueur pri on pri.id =  lc.prixrigueur_id ';
  4717.             $sqlrech .= '                 INNER JOIN livrer l on l.lignecommande_id = lc.id
  4718.                             INNER JOIN  info_livrer il on il.id = l.infolivrer_id
  4719.                             INNER JOIN producteur p on lc.producteur_id = p.id 
  4720.                             
  4721.                              ';
  4722.                     $sqlrech .= 
  4723.                                   INNER JOIN utilisateur u on p.utilisateur_id = u.id
  4724.                 ";
  4725.                 if($siListe ==or $groupementId != 0){
  4726.                     $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.producteur_id = p.id
  4727.                                     INNER JOIN groupement g on gp.groupement_id = g.id' ;
  4728.                 }
  4729.                 if($siListe ==or $zoneId != ){
  4730.                     $sqlrech .= '   INNER JOIN zone_producteur zp on zp.producteur_id = p.id
  4731.                                     INNER JOIN ville v on zp.ville_id = v.id' ;
  4732.                 }
  4733.                 if($typeAction != 0){
  4734.                     $sqlrech .= " INNER JOIN producteur_abonne pab on pab.producteur_id  = p.id ";
  4735.                     $sqlrech .= " INNER JOIN abonne a on pab.abonne_id =  a.id ";
  4736.                     if($typeAction == &&  $partenaireId != 0)
  4737.                         $sqlrech .= " INNER JOIN partenaire pt on pab.partenaire_id = pt.id ";
  4738.                 }else{
  4739.                     $sqlrech .= " INNER JOIN abonne a on p.abonne_id  = a.id";
  4740.                 }
  4741.                 
  4742.                 $sqlrech .= " WHERE   p.etat_prod =1 ";
  4743.                       
  4744.                 if($typeAction == &&  $partenaireId != 0)
  4745.                     $sqlrech .= " AND  pt.id =:partenaireId  ";
  4746.                 if($groupementId != )
  4747.                     $sqlrech .= " AND  g.id =:groupementId  ";
  4748.                 if($agentId != )
  4749.                     $sqlrech .= " AND  ut.id =:agentId  ";
  4750.                 if($zoneId != )
  4751.                     $sqlrech .= " AND  v.id =:zoneId  ";
  4752.                 
  4753.                 if($typeAction == || $typeAction == 1)
  4754.                     $sqlrech .= " AND  a.id =:abonneId  ";
  4755.                 if($siListe ==or $groupementId != )
  4756.                     $sqlrech .= " GROUP BY g.id, g.nom_groupement ";    
  4757.                 if($siListe ==or $zoneId != )
  4758.                     $sqlrech .= " GROUP BY v.id, v.nom_ville "
  4759.                 $sqlrech .= " ORDER BY  nombre_producteurs DESC " ;
  4760.                 if($limite !=0)
  4761.                     $sqlrech .= " LIMIT ".$limite ;
  4762.               
  4763.                 //INNER JOIN produit_abonne pa on pa.produit_id  = p.id
  4764.                 $stmt $em->getConnection()->prepare($sqlrech);
  4765.                 if($typeAction == &&  $partenaireId != 0)
  4766.                     $stmt->bindValue(':partenaireId'$partenaireIdPDO::PARAM_INT);
  4767.                 
  4768.                 if($groupementId != )
  4769.                     $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  4770.                 if($agentId != )
  4771.                     $stmt->bindValue(':agentId'$agentIdPDO::PARAM_INT);
  4772.                 if($zoneId != )
  4773.                     $stmt->bindValue(':zoneId'$zoneIdPDO::PARAM_INT);
  4774.                 if($typeAction == || $typeAction == 1)
  4775.                     $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  4776.             $stmt->execute();
  4777.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  4778.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  4779.             $stmt null;
  4780.             $res null;
  4781.             var_dump($e->getMessage());
  4782.         }
  4783.         return $res;
  4784.     }
  4785.     public function getStatlocalisationAction(EntityManager $em,$abonneId$groupementId$zoneId$siP=0$partenaireId=0$typeAction=0$siListe=0$agentId=0) {
  4786.         try {
  4787.                 if($siListe==0){
  4788.                     $sqlrech 'SELECT  u.nom_user, u.prenoms_user, u.tel1_user, u.sexe_user,  u.date_ajout_user as date_ajout,  p.code_genere as code_producteur, sa.code_genere as code_surface, sa.superficie, sa.superficie_reelle';
  4789.                 }elseif($siListe==1){
  4790.                     $sqlrech 'SELECT Count(DISTINCT sa.id) as total ';
  4791.                 }elseif($siListe==2){
  4792.                     $sqlrech " SELECT g.id as id,
  4793.                         CONCAT(g.nom_groupement,'-[', a.nom,']') AS nom_groupement,
  4794.                         COUNT(DISTINCT sa.id) AS nombre_parcelle";
  4795.                 }elseif($siListe==3){
  4796.                     $sqlrech " SELECT v.id  as id,
  4797.                         CONCAT(v.nom_ville,'-[', a.nom,']') AS nom_ville,
  4798.                         COUNT(DISTINCT sa.id) AS nombre_parcelle ";
  4799.                 }elseif($siListe==4){
  4800.                     $sqlrech ' SELECT a.id AS id, a.nom AS nom_projet,
  4801.                         COUNT(DISTINCT sa.id) AS nombre_parcelle ';
  4802.                 }elseif($siListe==5){
  4803.                     $sqlrech ' SELECT ag.nom_user, ag.id, ag.prenoms_user, 
  4804.                         COUNT(DISTINCT sa.id) AS nombre_parcelle';
  4805.                 }
  4806.                 $sqlrech .= '
  4807.                                 FROM localisation l
  4808.                                 
  4809.                                 INNER JOIN surface_annee sa on l.surfaceannee_id = sa.id
  4810.                                 INNER JOIN produit pr on sa.produit_id = pr.id
  4811.                                 INNER JOIN utilisateur ag on ag.id = l.utilisateur_id 
  4812.                             ';
  4813.                 
  4814.                     $sqlrech .= " INNER JOIN producteur p  on sa.producteur_id  = p.id
  4815.                                   INNER JOIN utilisateur u on p.utilisateur_id = u.id
  4816.                 ";
  4817.                 if($siListe ==){
  4818.                     $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.producteur_id = p.id
  4819.                                     INNER JOIN groupement g on gp.groupement_id = g.id' ;
  4820.                 }
  4821.                 if($siListe ==){
  4822.                     $sqlrech .= '   INNER JOIN zone_producteur zp on zp.producteur_id = p.id
  4823.                                     INNER JOIN ville v on zp.ville_id = v.id' ;
  4824.                 }
  4825.                 if($typeAction != 0){
  4826.                     $sqlrech .= " INNER JOIN surface_abonne sab on sab.surfaceannee_id  = sa.id ";
  4827.                     $sqlrech .= " INNER JOIN abonne a on sab.abonne_id =  a.id ";
  4828.                     if($typeAction == &&  $partenaireId != 0)
  4829.                         $sqlrech .= " INNER JOIN partenaire pt on sab.partenaire_id = pt.id ";
  4830.                 }else{
  4831.                     $sqlrech .= " INNER JOIN abonne a on sa.abonne_id  = a.id";
  4832.                 }
  4833.                 $sqlrech .= " WHERE 1=1 AND l.type_localisation = 1 ";
  4834.                       
  4835.                 if($typeAction == || $typeAction == 1)
  4836.                     $sqlrech .= " AND  a.id =:abonneId  ";
  4837.                 if($typeAction == &&  $partenaireId != 0)
  4838.                     $sqlrech .= " AND  pt.id =:partenaireId  ";
  4839.                 if($groupementId != )
  4840.                     $sqlrech .= " AND  g.id =:groupementId  ";
  4841.                 if($agentId != )
  4842.                     $sqlrech .= " AND  ut.id =:agentId  ";
  4843.                 if($zoneId != )
  4844.                     $sqlrech .= " AND  v.id =:zoneId  ";
  4845.                 if($siListe ==or $groupementId != )
  4846.                     $sqlrech .= " GROUP BY g.id, g.nom_groupement ";    
  4847.                 if($siListe ==or $zoneId != )
  4848.                     $sqlrech .= " GROUP BY v.id, v.nom_ville "
  4849.                 if($siListe ==)
  4850.                     $sqlrech .= " GROUP BY ag.id "
  4851.                 if($siListe==4)
  4852.                     $sqlrech .= " GROUP BY a.id "
  4853.                 
  4854.                 $stmt $em->getConnection()->prepare($sqlrech);
  4855.                 //var_dump($sqlrech, $abonneId, $groupementId, $zoneId, $siP, $partenaireId, $typeAction, $siListe, $agentId);exit;
  4856.                 if($typeAction == &&  $partenaireId != 0)
  4857.                     $stmt->bindValue(':partenaireId'$partenaireIdPDO::PARAM_INT);
  4858.                 
  4859.                 if($agentId != )
  4860.                     $stmt->bindValue(':agentId'$agentIdPDO::PARAM_INT);
  4861.                 if($groupementId != )
  4862.                     $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  4863.                 if($zoneId != )
  4864.                     $stmt->bindValue(':zoneId'$zoneIdPDO::PARAM_INT);
  4865.                 if($typeAction == || $typeAction == 1)
  4866.                     $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  4867.             $stmt->execute();
  4868.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  4869.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  4870.             $stmt null;
  4871.             $res null;
  4872.             var_dump($e->getMessage());
  4873.         }
  4874.         return $res;
  4875.     }
  4876.     function completerZero($numero) {
  4877.         return str_pad($numero4'0'STR_PAD_LEFT);
  4878.     }
  4879.     public function prepareGeoJsonLocal($jsonString)
  4880.     {
  4881.         $data json_decode($jsonStringtrue); // ton tableau [{"latitude":"..","longitude":".."}, ...]
  4882.         $coordinates = [];
  4883.         foreach ($data as $point) {
  4884.             $coordinates[] = [
  4885.                 (float) $point['longitude'], // GeoJSON = [lon, lat]
  4886.                 (float) $point['latitude']
  4887.             ];
  4888.         }
  4889.         // Fermer le polygone (ajouter le premier point à la fin si nécessaire)
  4890.         if ($coordinates[0] !== end($coordinates)) {
  4891.             $coordinates[] = $coordinates[0];
  4892.         }
  4893.         $geojson = [
  4894.             "type" => "FeatureCollection",
  4895.             "features" => [
  4896.                 [
  4897.                     "type" => "Feature",
  4898.                     "geometry" => [
  4899.                         "type" => "Polygon",
  4900.                         "coordinates" => [ $coordinates ]
  4901.                     ]
  4902.                 ]
  4903.             ]
  4904.         ];
  4905.         return json_encode($geojsonJSON_PRETTY_PRINT);
  4906.     }
  4907.     
  4908.     
  4909. }