src/ControllerModel/user/paramUtilTrait.php line 665

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\stock\EtatInfoOpportunite;
  62. use App\Entity\stock\Opportunite;
  63. use App\Entity\prod\SurfaceAnneeHistorique;
  64. use App\Entity\prod\GroupementAbonne;
  65. use App\Entity\inspection\InspectionAbonne;
  66. use App\Entity\stock\InfoDeplacer;
  67. use App\Entity\stock\ZoneAbonne;
  68. use App\Repository\prod\SurfaceAnneeHistoriqueRepository;
  69. use PDO;
  70. use DateInterval;
  71. Trait paramUtilTrait {
  72.     /**
  73.      * @var string
  74.      * Nom du Bundle
  75.      */
  76.     protected $stockBundle 'adminStockBundle:';
  77.     protected $stockBundleSlash 'stock/';
  78.     protected $moduleTitre '';
  79.     protected $moduleDesc '';
  80.     private  $produitAbonneRepository;
  81.     private  $surfaceAbonneRepository;
  82.     private  $producteurAbonneRepository;
  83.     private  $fournisseurAbonneRepository;
  84.     private  $groupementAbonneRepository;
  85.     private  $abonneVilleRepository;
  86.     private  $inspectionAbonneRepository;
  87.     /**
  88.      * @var string
  89.      * Nom du Bundle
  90.      */
  91.     public function __construct(InfoLivrerRepository $infoLivrerRepositoryTranslatorInterface $translatorSurfaceAnneeHistoriqueRepository $surfaceAnneeHistoriqueRepository,
  92.     SurfaceAbonneRepository $surfaceAbonneRepositoryProduitAbonneRepository $produitAbonneRepositoryProducteurAbonneRepository $producteurAbonneRepository
  93.     FournisseurAbonneRepository $fournisseurAbonneRepositoryGroupementAbonneRepository $groupementAbonneRepository,AbonneVilleRepository $abonneVilleRepository,
  94.     InspectionAbonneRepository $inspectionAbonneRepository)
  95.     {
  96.         //parent::__construct();
  97.         $this->infoLivrerRepository $infoLivrerRepository;
  98.         $this->translator $translator;
  99.         $this->surfaceAnneeHistoriqueRepository =  $surfaceAnneeHistoriqueRepository;
  100.         $this->surfaceAnneeHistoriqueRepository =  $surfaceAnneeHistoriqueRepository;
  101.         $this->produitAbonneRepository =$produitAbonneRepository;
  102.         $this->surfaceAbonneRepository=$surfaceAbonneRepository;
  103.         $this->producteurAbonneRepository=$producteurAbonneRepository;
  104.         $this->fournisseurAbonneRepository=$fournisseurAbonneRepository;
  105.         $this->groupementAbonneRepository=$groupementAbonneRepository;
  106.         $this->abonneVilleRepository=$abonneVilleRepository;
  107.         $this->inspectionAbonneRepository=$inspectionAbonneRepository;
  108.         //$this->infoLivrerRepository = 
  109.         //var_dump(1);exit;
  110.     }
  111.     protected $gmaoBundle 'adminGmaoBundle:';
  112.     public function gmaoBundleSlash($typePresentation){
  113.         if($typePresentation == )
  114.             return 'template_1/gmao/';
  115.         elseif($typePresentation == )
  116.             return 'template_2/gmao/';
  117.         else
  118.             return 'gmao/';
  119.     }
  120.     protected $gmaoBundleSlash 'gmao/';
  121.     protected $paramBundle 'adminParamBundle:';
  122.     
  123.     public function paramBundleSlash($typePresentation){
  124.         if($typePresentation == )
  125.             return 'template_1/param/';
  126.         elseif($typePresentation == )
  127.             return 'template_2/param/';
  128.         else
  129.             return 'param/';
  130.     }
  131.     protected $cmsBundle 'adminCmsBundle:';
  132.     
  133.     public function cmsBundleSlash($typePresentation){
  134.         if($typePresentation == )
  135.             return 'template_1/cms/';
  136.         elseif($typePresentation == )
  137.             return 'template_2/cms/';
  138.         else
  139.             return 'cms/';
  140.     }
  141.     protected $trackBundle 'adminTrackBundle:';
  142.     
  143.     public function trackBundleSlash($typePresentation){
  144.         if($typePresentation == )
  145.             return 'template_1/track/';
  146.         elseif($typePresentation == )
  147.             return 'template_2/track/';
  148.         else
  149.             return 'track/';
  150.     }
  151.     
  152.     protected $aVenteBundle 'AppBundle:';
  153.     protected $userBundle 'App\\Entity\\user\\';
  154.   
  155.     protected $prodBundle 'adminProdBundle:';
  156.     
  157.     public function prodBundleSlash($typePresentation){
  158.         if($typePresentation == )
  159.             return 'template_1/prod/';
  160.         elseif($typePresentation == )
  161.             return 'template_2/prod/';
  162.         else
  163.             return 'prod/';
  164.     }
  165.     public function stockBundleSlash($typePresentation){
  166.         if($typePresentation == )
  167.             return 'template_1/stock/';
  168.         elseif($typePresentation == )
  169.             return 'template_2/stock/';
  170.         else
  171.             return 'stock/';
  172.     }
  173.     protected $siteBundle 'adminSiteBundle:'
  174.     protected $siteBundleSlash 'site/';
  175.     protected $inspectionBundle 'adminInspectionBundle:'
  176.     
  177.     public function inspectionBundleSlash($typePresentation){
  178.         if($typePresentation == )
  179.             return 'template_1/inspection/';
  180.         elseif($typePresentation == )
  181.             return 'template_2/inspection/';
  182.         else
  183.             return 'inspection/';
  184.     }
  185.     protected $clientBundle 'adminClientBundle:'
  186.     
  187.     public function clientBundleSlash($typePresentation){
  188.         if($typePresentation == )
  189.             return 'template_1/client/';
  190.         elseif($typePresentation == )
  191.             return 'template_2/client/';
  192.         else
  193.             return 'client/';
  194.     }
  195.     protected $assoBundle 'adminAssoBundle:'
  196.     
  197.     public function assoBundleSlash($typePresentation){
  198.         if($typePresentation == )
  199.             return 'template_1/asso/';
  200.         elseif($typePresentation == )
  201.             return 'template_2/asso/';
  202.         else
  203.             return 'asso/';
  204.     }
  205.     protected $bailleurBundle 'adminBailleurBundle:'
  206.    
  207.     public function bailleurBundleSlash($typePresentation){
  208.         if($typePresentation == )
  209.             return 'template_1/bailleur/';
  210.         elseif($typePresentation == )
  211.             return 'template_2/bailleur/';
  212.         else
  213.             return 'bailleur/';
  214.     }
  215.     public function userBundleSlash($typePresentation){
  216.         if($typePresentation == )
  217.             return 'template_1/user/';
  218.         elseif($typePresentation == )
  219.             return 'template_2/user/';
  220.         else
  221.             return 'user/';
  222.     }
  223.     public function getInfoPartenaire($em$objetAbonne){
  224.         $data =array();
  225.         if($objetAbonne->getSiPrincipale() == ){
  226.             $data['typeAction'] = $objetAbonne->getSiPrincipale();
  227.             $data['partenaireId'] = $objetAbonne->getPartenaire()->getId();
  228.         }else if ($objetAbonne->getSiPrincipale() == 1){
  229.             $data['typeAction'] = $objetAbonne->getSiPrincipale();
  230.             $data['partenaireId'] = $objetAbonne->getPartenaire()->getId();
  231.         }else{
  232.             $data['typeAction'] = $objetAbonne->getSiPrincipale() ;
  233.             $data['partenaireId'] = 0;
  234.         }
  235.         return $data;
  236.     }
  237.     public function setUpdateAbonnePartenaire($em$objetAbonne$objetPartenaire$objetClasse$typeObjet$siPrincipale=1$surfaceAbonneRepository$produitAbonneRepository,  $producteurAbonneRepository
  238.      $fournisseurAbonneRepository,  $groupementAbonneRepository$abonneVilleRepository,
  239.      $inspectionAbonneRepository){
  240.         
  241.         $data =array();
  242.         if($typeObjet == ){
  243.             $objetAbonnePartenaire $produitAbonneRepository->findOneBy(['abonne'=>$objetAbonne'produit'=>$objetClasse]);
  244.             if($objetAbonnePartenaire == null)
  245.                 $objetAbonnePartenaire = new  ProduitAbonne();
  246.             $objetAbonnePartenaire->setProduit($objetClasse);
  247.         }else if ($typeObjet == 2){
  248.             $objetAbonnePartenaire $producteurAbonneRepository->findOneBy(['abonne'=>$objetAbonne'producteur'=>$objetClasse]);
  249.             if($objetAbonnePartenaire == null)
  250.                 $objetAbonnePartenaire = new  ProducteurAbonne();
  251.             $objetAbonnePartenaire->setProducteur($objetClasse);
  252.         }else if ($typeObjet == 3){
  253.             $objetAbonnePartenaire $surfaceAbonneRepository->findOneBy(['abonne'=>$objetAbonne'surfaceannee'=>$objetClasse]);
  254.             if($objetAbonnePartenaire == null)
  255.                 $objetAbonnePartenaire = new SurfaceAbonne();
  256.             $objetAbonnePartenaire->setSurfaceannee($objetClasse);
  257.            
  258.         }else if ($typeObjet == 4){
  259.             $objetAbonnePartenaire $fournisseurAbonneRepository->findOneBy(['abonne'=>$objetAbonne'fournisseur'=>$objetClasse]);
  260.             if($objetAbonnePartenaire == null)
  261.                 $objetAbonnePartenaire = new FournisseurAbonne();
  262.             $objetAbonnePartenaire->setFournisseur($objetClasse);
  263.         }else if ($typeObjet == 5){
  264.             $objetAbonnePartenaire $groupementAbonneRepository->findOneBy(['abonne'=>$objetAbonne'groupement'=>$objetClasse]);
  265.             if($objetAbonnePartenaire == null)
  266.                 $objetAbonnePartenaire = new GroupementAbonne();
  267.             $objetAbonnePartenaire->setGroupement($objetClasse);
  268.         }else if ($typeObjet == 6){
  269.             $objetAbonnePartenaire $abonneVilleRepository->findOneBy(['abonne'=>$objetAbonne'ville'=>$objetClasse]);
  270.             if($objetAbonnePartenaire == null)
  271.                 $objetAbonnePartenaire = new AbonneVille();
  272.             $objetAbonnePartenaire->setVille($objetClasse);
  273.         }else if ($typeObjet == 7){
  274.             $objetAbonnePartenaire $inspectionAbonneRepository->findOneBy(['abonne'=>$objetAbonne'inspection'=>$objetClasse]);
  275.             if($objetAbonnePartenaire == null)
  276.                 $objetAbonnePartenaire = new InspectionAbonne();
  277.             $objetAbonnePartenaire->setInspection($objetClasse);
  278.         }
  279.         $objetAbonnePartenaire->setAbonne($objetAbonne);
  280.         $objetAbonnePartenaire->setPartenaire($objetPartenaire);
  281.         $objetAbonnePartenaire->setSiPrincipale($siPrincipale);
  282.         $em->persist($objetAbonnePartenaire);
  283.         $em->flush();
  284.         return 1;
  285.     }
  286.     public function setAbonnePartenaire($em$objetAbonne$objetPartenaire$objetClasse$typeObjet$siPrincipale=1){
  287.         
  288.         $data =array();
  289.         if($typeObjet == ){
  290.             $objetAbonnePartenaire $this->produitAbonneRepository->findOneBy(['abonne'=>$objetAbonne'produit'=>$objetClasse]);
  291.             if($objetAbonnePartenaire == null)
  292.                 $objetAbonnePartenaire = new  ProduitAbonne();
  293.             $objetAbonnePartenaire->setProduit($objetClasse);
  294.         }else if ($typeObjet == 2){
  295.             $objetAbonnePartenaire $this->producteurAbonneRepository->findOneBy(['abonne'=>$objetAbonne'producteur'=>$objetClasse]);
  296.             if($objetAbonnePartenaire == null)
  297.                 $objetAbonnePartenaire = new  ProducteurAbonne();
  298.             $objetAbonnePartenaire->setProducteur($objetClasse);
  299.         }else if ($typeObjet == 3){
  300.             $objetAbonnePartenaire $this->surfaceAbonneRepository->findOneBy(['abonne'=>$objetAbonne'surfaceannee'=>$objetClasse]);
  301.             if($objetAbonnePartenaire == null)
  302.                 $objetAbonnePartenaire = new SurfaceAbonne();
  303.             $objetAbonnePartenaire->setSurfaceannee($objetClasse);
  304.            
  305.         }else if ($typeObjet == 4){
  306.             $objetAbonnePartenaire $this->fournisseurAbonneRepository->findOneBy(['abonne'=>$objetAbonne'fournisseur'=>$objetClasse]);
  307.             if($objetAbonnePartenaire == null)
  308.                 $objetAbonnePartenaire = new FournisseurAbonne();
  309.             $objetAbonnePartenaire->setFournisseur($objetClasse);
  310.         }else if ($typeObjet == 5){
  311.             $objetAbonnePartenaire $this->groupementAbonneRepository->findOneBy(['abonne'=>$objetAbonne'groupement'=>$objetClasse]);
  312.             if($objetAbonnePartenaire == null)
  313.                 $objetAbonnePartenaire = new GroupementAbonne();
  314.             $objetAbonnePartenaire->setGroupement($objetClasse);
  315.         }else if ($typeObjet == 6){
  316.             $objetAbonnePartenaire $this->abonneVilleRepository->findOneBy(['abonne'=>$objetAbonne'ville'=>$objetClasse]);
  317.             if($objetAbonnePartenaire == null)
  318.                 $objetAbonnePartenaire = new AbonneVille();
  319.             $objetAbonnePartenaire->setVille($objetClasse);
  320.         }else if ($typeObjet == 7){
  321.             $objetAbonnePartenaire $this->inpectionAbonneRepository->findOneBy(['abonne'=>$objetAbonne'inspection'=>$objetClasse]);
  322.             if($objetAbonnePartenaire == null)
  323.                 $objetAbonnePartenaire = new InspectionAbonne();
  324.             $objetAbonnePartenaire->setInspection($objetClasse);
  325.         }
  326.         $objetAbonnePartenaire->setAbonne($objetAbonne);
  327.         $objetAbonnePartenaire->setPartenaire($objetPartenaire);
  328.         $objetAbonnePartenaire->setSiPrincipale($siPrincipale);
  329.         $em->persist($objetAbonnePartenaire);
  330.         $em->flush();
  331.         return 1;
  332.     }
  333.     /**
  334.      * @var string
  335.      *      Nom du Bundle
  336.      */
  337.     protected $messagerieBundle 'adminMessagerieBundle:';
  338.     // use \Symfony\Component\DependencyInjection\ContainerAwareTrait;
  339.     public function infosConnecte(Request $requestLoginManager $loginManagerParamRepository $paramRepositor,ConnexionRepository $connexionRepositoryActionRepository $actionRepository ) {
  340.         //$this->updateMessageNonLu();
  341.         //
  342.         $sessionData $loginManager->getSessionData(LoginManager::SESSION_DATA_NAME);
  343.         $status $loginManager->isConnecte('',$paramRepositor,$connexionRepository,$actionRepository );
  344. //        $banque = $loginManager->getBanque();
  345.         $request->attributes->set('isConnecte'$status['isConnecte']);
  346.         $request->attributes->set('isUser'$status['isUser']);
  347.         $request->attributes->set('logoUrl'ParametreController::DEFAULT_LOGO_NAME);
  348.         $request->attributes->set('nbMessageNonLu'0);
  349. //        $request->attributes->set('infos', $banque);
  350. //        if($banque instanceof  Banque){
  351. //            $request->attributes->set('logoUrl',$banque->getUrlLogo());
  352. //        }
  353.         if (($sessionData != NULL) && (is_array($sessionData)) && ($status['isConnecte'])) {
  354.             if (array_key_exists('nbMessageNonLu'$sessionData)) {
  355.                 $request->attributes->set('nbMessageNonLu'$sessionData['nbMessageNonLu']);
  356.             }
  357.             if (array_key_exists('nomTableConnecte'$sessionData)) {
  358.                 $request->attributes->set('nomTableConnecte'$sessionData['nomTableConnecte']);
  359.             }
  360.             if (array_key_exists('isUser'$sessionData)) {
  361.                 $request->attributes->set('isUser'$sessionData['isUser']);
  362.             }
  363.             if (array_key_exists('isAbonne'$sessionData)) {
  364.                 $request->attributes->set('isAbonne'$sessionData['isAbonne']);
  365.             }
  366.             if (array_key_exists('id'$sessionData)) {
  367.                 $request->attributes->set('id'$sessionData['id']);
  368.             }
  369.             if (array_key_exists('prenoms'$sessionData)) {
  370.                 $request->attributes->set('prenoms'$sessionData['prenoms']);
  371.             }
  372.             if (array_key_exists('nom'$sessionData)) {
  373.                 $request->attributes->set('nom'$sessionData['nom']);
  374.             }
  375.             if (array_key_exists('sexe'$sessionData)) {
  376.                 $request->attributes->set('sexe'$sessionData['sexe']);
  377.             }
  378.             if (array_key_exists('idConnexion'$sessionData)) {
  379.                 $request->attributes->set('idConnexion'$sessionData['idConnexion']);
  380.             }
  381.             if (array_key_exists('username'$sessionData)) {
  382.                 $request->attributes->set('username'$sessionData['username']);
  383.             }
  384.             if (array_key_exists('idProfil'$sessionData)) {
  385.                 $request->attributes->set('idProfil'$sessionData['idProfil']);
  386.             }
  387.             if (array_key_exists('libelleProfil'$sessionData)) {
  388.                 $request->attributes->set('libelleProfil'$sessionData['libelleProfil']);
  389.             }
  390.             if (array_key_exists('codeProfil'$sessionData)) {
  391.                 $request->attributes->set('codeProfil'$sessionData['codeProfil']);
  392.             }
  393.             $this->data['tabIdActions'] = array();
  394.             if (array_key_exists('tabIdActions'$sessionData)) {
  395.                 $request->attributes->set('tabIdActions'$sessionData['tabIdActions']);
  396.                 $this->data['tabIdActions'] = $sessionData['tabIdActions'];
  397.             }
  398.             if (array_key_exists('locale'$sessionData)) {
  399.                 $request->attributes->set('locale'$sessionData['locale']);
  400.                 $this->data['locale'] = $sessionData['locale'];
  401.                 $request->setLocale($sessionData['locale']);
  402.             } else {
  403.                 $locale $loginManager->getLocale();
  404.                 $request->attributes->set('locale'$locale);
  405.                 $this->data['locale'] = $locale;
  406.                 $request->setLocale($locale);
  407.             }
  408.             if ($status['isUser']) {
  409. //                $profilsAbonne = $loginManager->getAllProfilAbonne();
  410.             }
  411.         }
  412. //        $this->data['profilsAbonne'] = $profilsAbonne;
  413.         return $sessionData;
  414.     }
  415.     /**
  416.      * Récupération du service de gestion des logs;
  417.      * @return LogManager
  418.      */
  419.     private function getLogManager() {
  420.         return $this->get('logManager');
  421.     }
  422.     /**
  423.      * Retourne le nom d'une classe à partir de l'espace de nom complet de la classe
  424.      * @param type $nameSpace
  425.      * @return type
  426.      */
  427.     public function getNomClassRun($nameSpace) {
  428.         $nom '';
  429.         if (strlen($nameSpace) > 0) {
  430.             $tab explode("\\"$nameSpace);
  431.             $taille count($tab);
  432.             if ($taille 0) {
  433.                 $nom $tab[$taille 1];
  434.             }
  435.         }
  436.         return $nom;
  437.     }
  438.     public function gestionDroitUtil($request$nomAction$descAction$module$moduledescript LoginManager $loginManager,ParamRepository $paramRepositor,ConnexionRepository $connexionRepository,ActionRepository $actionRepository,
  439.     ModuleRepository $moduleRepository,ControleurRepository $controleurRepository,ProfilRepository $profilRepository) {
  440.         /*
  441.          * Préparation du message de log 
  442.          */
  443.         $this->logMessage .= ' [ ' $nomAction ' ] ';
  444.         /*
  445.          * Service de gestion des droits
  446.          */
  447.         //
  448.         /*
  449.          * Informations de session
  450.          */
  451.         $sessionData $this->infosConnecte($request$loginManager$paramRepositor,$connexionRepository$actionRepository);
  452.         /*
  453.          * Locale en cours
  454.          */
  455.         $locale $loginManager->getLocale();
  456.         $this->data['locale'] = $locale;
  457.         /*
  458.          * On vérifie si l'utilisateur est connecté
  459.          */
  460.         $status $loginManager->isConnecte($nomAction,$paramRepositor,$connexionRepository$actionRepository);
  461.         if ($status['isConnecte']) {
  462.             /*
  463.              * Au cas ou l'utilisateur est connecté on vérifie s'il nest pas innactif. S'il est innactif
  464.              * on garde en mémoire flash la route actuelle pour effectuer une redirection lors de la prochaine connexion
  465.              */
  466.             if ($status['isInnactif']) {
  467.                 $routeName $request->get('_route');
  468.                 $routeParams $request->get('_route_params');
  469.                 $this->get('session')->getFlashBag()->add('restoreUrl'$this->generateUrl($routeName$routeParams));
  470.                 $this->get('session')->getFlashBag()->add('ina'$this->translator->trans("site.long.periode"));
  471.                 return 1// $this->redirect($this->generateUrl('app_logout'));
  472.             }
  473.             /*
  474.              * Seuls les utilisateurs admins ont le droit d'acceder à cette action
  475.              */
  476.             if (!$status['isUser']) {
  477.                 return 1//$this->redirect($this->generateUrl('app_logout'));
  478.             }
  479.         } else {
  480.             return 1//return $this->redirect($this->generateUrl('app_logout'));
  481.         }
  482.         /*
  483.          * Gestion des droits
  484.          */
  485.         if (!$loginManager->getOrSetActions($module$moduledescript$this->getNomClassRun(__CLASS__), $this->description$nomAction$descAction$sessionData['idProfil'], $moduleRepository$controleurRepository$actionRepository$profilRepository$moduleRepository$controleurRepository$actionRepository$profilRepository)) {
  486.             $this->logMessage .= ' [ TENTATIVE DE VIOLATION DE DROITS ] ';
  487.             $this->get('session')->getFlashBag()->add('access'"Vous n'avez pas le droit d'accéder à cette page");
  488.             return 2//$this->redirect($this->generateUrl('app_admin_user_access_refuse'));
  489.         }
  490.         return 0;
  491.     }
  492.     public function getRefCommande(EntityManager $em$type 0$an 0$mois 0$entite 'COMMANDE'$taille 5$four=0) {
  493.         $res '';
  494.         $cp $this->getcompteur($em$type$an$mois$entite$taille$four);
  495.         ( array_key_exists('compteur'$cp)) ? $cp $cp['compteur'] : $cp '';
  496.         ($type === 1) ? $res .= 'CDF' $res .= 'CDC';
  497.         if ($four == 2) {
  498.             $val "K";
  499.         } else {
  500.             $val "C";
  501.         }
  502.         return $val "" str_pad($cp30STR_PAD_LEFT) . '/' $this->traiteInfoMois($mois) . '/' $an;
  503.     }
  504.     
  505.     public function getRefCommandeSoja(EntityManager $em$type 0$an 0$mois 0$entite 'COMMANDE'$taille 5$four=0) {
  506.         $res '';
  507.         $cp $this->getcompteur($em$type$an$mois$entite$taille$four);
  508.         ( array_key_exists('compteur'$cp)) ? $cp $cp['compteur'] : $cp '';
  509.         ($type === 1) ? $res .= 'CDF' $res .= 'CDC';
  510.         if ($four == 2) {
  511.             $val "S";
  512.         } else {
  513.             $val "S";
  514.         }
  515.         $toutInfoLivrer $em->getRepository($this->stockBundle 'InfoLivrer')->findAll();
  516.         return $val "" count($toutInfoLivrer ) . '/' $this->traiteInfoMois($mois) . '/' $an;
  517.     }
  518.     public function reinitialiserRef(EntityManager $em$type 0$an 0$mois 0$entite 'COMMANDE'$taille 5$four=0) {
  519.         $res '';
  520.         $cp $this->reinitialiser($em$type$an$mois$entite$taille$four);
  521.         return $cp;
  522.     }
  523.     function traiteInfoMois($mois) {
  524.         switch ($mois) {
  525.             case :
  526.                 return "JAN";
  527.             case :
  528.                 return "FEV";
  529.             case :
  530.                 return "MAR";
  531.             case :
  532.                 return "AVR";
  533.             case :
  534.                 return "MAI";
  535.             case :
  536.                 return "JUIN";
  537.             case :
  538.                 return "JUIL";
  539.             case :
  540.                 return "AOU";
  541.             case :
  542.                 return "SEP";
  543.             case 10 :
  544.                 return "OCT";
  545.             case 11 :
  546.                 return "NOV";
  547.             case 12 :
  548.                 return "DEC";
  549.         }
  550.     }
  551.     public function getRefLivrer(EntityManager $em$type 0$an 0$mois 0$entite 'COMMANDE'$taille 5$jour "") {
  552.         $res '';
  553.         $cp $this->getcompteur($em$type$an$mois$entite$taille,0);
  554.         ( array_key_exists('compteur'$cp)) ? $cp $cp['compteur'] : $cp rand(0,999999);
  555.         ($type === 1) ? $res .= 'REC' $res .= 'LIV';
  556.        
  557.         return $res '-' substr($an, -2) . $mois $jour '-' $cp;
  558.     }
  559.     public function getcompteur(EntityManager $em$type 0$an 0$mois 0$entite 'COMMANDE'$taille 5$four) {
  560.         try {
  561.             $sqlrech ' SELECT getcompteur(:p_type ,:p_an ,:p_mois ,:p_entite ,:p_taille, :four) as compteur; ';
  562.             $stmt $em->getConnection()->prepare($sqlrech);
  563.             $stmt->bindValue(':p_type'$typePDO::PARAM_INT);
  564.             $stmt->bindValue(':p_an'$anPDO::PARAM_INT);
  565.             $stmt->bindValue(':p_mois'$moisPDO::PARAM_INT);
  566.             $stmt->bindValue(':p_entite'$entitePDO::PARAM_STR);
  567.             $stmt->bindValue(':p_taille'$taillePDO::PARAM_INT);
  568.             $stmt->bindValue(':four'$fourPDO::PARAM_INT);
  569.         
  570.             $result $stmt->executeQuery()->fetchAllAssociative();
  571.             //$stmt->execute();
  572.             //var_dump($stmt);exit;
  573.             $res $result;//$stmt->fetch(PDO::FETCH_ASSOC);
  574.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  575.             $stmt null;
  576.             $res nnull;
  577.             var_dump($e->getMessage());
  578.         }
  579.         return $res;
  580.     }
  581.     public function manageStock(EntityManager $em$id 0$quantite 0$action 0) {
  582.        /* try {
  583.             $sqlrech = ' SELECT getcompteur(:p_id ,:p_quantite,:p_action) as compteur; ';
  584.             $stmt = $em->getConnection()->prepare($sqlrech);
  585.             $stmt->bindValue(':p_id', $id, PDO::PARAM_INT);
  586.             $stmt->bindValue(':p_quantite', $quantite, PDO::PARAM_INT);
  587.             $stmt->bindValue(':p_action', $action, PDO::PARAM_INT);
  588.             $stmt->execute();
  589.             $res = $stmt->fetch(PDO::FETCH_ASSOC);
  590.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  591.             $stmt = null;
  592.             $res = nnull;
  593.             var_dump($e->getMessage());
  594.         }*/
  595.         return 1;
  596.     }
  597.     public function reinitialiser(EntityManager $em$type 0$an 0$mois 0$entite 'COMMANDE'$taille 5$four) {
  598.         try {
  599.             $sqlrech ' SELECT reinitiation(:p_type ,:p_an ,:p_mois ,:p_entite ,:p_taille, :four) as compteur; ';
  600.             $stmt $em->getConnection()->prepare($sqlrech);
  601.             $stmt->bindValue(':p_type'$typePDO::PARAM_INT);
  602.             $stmt->bindValue(':p_an'$anPDO::PARAM_INT);
  603.             $stmt->bindValue(':p_mois'$moisPDO::PARAM_INT);
  604.             $stmt->bindValue(':p_entite'$entitePDO::PARAM_STR);
  605.             $stmt->bindValue(':p_taille'$taillePDO::PARAM_INT);
  606.             $stmt->bindValue(':four'$fourPDO::PARAM_INT);
  607.             $stmt->execute();
  608.             $res $stmt->executeQuery()->fetchAllAssociative();//$stmt->fetch(PDO::FETCH_ASSOC);
  609.             
  610.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  611.             $stmt null;
  612.             $res null;
  613.             var_dump($e->getMessage());
  614.         }
  615.         return $res;
  616.     }
  617.     public function getNumMvt(EntityManager $em$type 0$an 0$mois 0$entite 'COMMANDE'$taille 5) {
  618.         $res '';
  619.         $cp $this->getcompteur($em$type$an$mois$entite$taille1);
  620.         ( array_key_exists('compteur'$cp)) ? $cp $cp['compteur'] : $cp '';
  621.         ($type === 1) ? $res .= 'MVT' $res .= 'MVT';
  622.         return $res '' substr($an, -2) . $mois '' $cp;
  623.     }
  624.     public function initialiserAncienPrixZero(EntityManager $em$idProduit 0) {
  625.         try {
  626.             $sqlrech ' UPDATE prix_rigueur set etat_prix = 0 where produit_id =:produitId ';
  627.            // var_dump($sqlrech, $idProduit);exit;
  628.             $stmt $em->getConnection()->prepare($sqlrech);
  629.             $stmt->bindValue(':produitId'$idProduitPDO::PARAM_INT);
  630.             $stmt->execute();
  631.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  632.             $stmt null;
  633.             $res null;
  634.             var_dump($e->getMessage());
  635.         }
  636.         return 1;
  637.     }
  638.     public function initialiserLesAncienPolygon(EntityManager $em$surfaceanneeId0$typeLocalisation) {
  639.         try {
  640.             $sqlrech ' UPDATE localisation set etat_localisation = 2 where surfaceannee_id =:surfaceanneeId AND type_localisation =:typeLocalisation ';
  641.            // var_dump($sqlrech, $idProduit);exit;
  642.             $stmt $em->getConnection()->prepare($sqlrech);
  643.             $stmt->bindValue(':surfaceanneeId'$surfaceanneeIdPDO::PARAM_INT);
  644.             $stmt->bindValue(':typeLocalisation'$typeLocalisationPDO::PARAM_INT);
  645.             $stmt->execute();
  646.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  647.             $stmt null;
  648.             $res null;
  649.             var_dump($e->getMessage());
  650.         }
  651.         return 1;
  652.     }
  653.     public function initialiserSeTrouver(EntityManager $em$fournisseurId 0) {
  654.         try {
  655.             $sqlrech ' UPDATE se_trouver set etat_se_trouver = 0 where fournisseur_id =:fournisseurId ';
  656.            // var_dump($sqlrech, $idProduit);exit;
  657.             $stmt $em->getConnection()->prepare($sqlrech);
  658.             $stmt->bindValue(':fournisseurId'$fournisseurIdPDO::PARAM_INT);
  659.             $stmt->execute();
  660.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  661.             $stmt null;
  662.             $res null;
  663.             var_dump($e->getMessage());
  664.         }
  665.         return 1;
  666.     }
  667.     public function initialiserInspectionRempli(EntityManager $em$inspectionId 0$surfaceAnneeId=0) {
  668.         try {
  669.             $sqlrech ' UPDATE inspection_rempli set etat_fournisseur_producteur = 0 where surfaceannee_id =:surfaceAnneeId AND inspection_id =:inspectionId ';
  670.            // var_dump($sqlrech, $idProduit);exit;
  671.             $stmt $em->getConnection()->prepare($sqlrech);
  672.             $stmt->bindValue(':inspectionId'$inspectionIdPDO::PARAM_INT);
  673.             $stmt->bindValue(':surfaceAnneeId'$surfaceAnneeIdPDO::PARAM_INT);
  674.             $stmt->execute();
  675.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  676.             $stmt null;
  677.             $res null;
  678.             var_dump($e->getMessage());
  679.         }
  680.         return 1;
  681.     }
  682.     public function updatePageTemplate(EntityManager $em$abonneId$ancienTemplate 0$nouveauTemplate) {
  683.         try {
  684.             $sqlrech ' UPDATE page set template_id =:nouveauTemplate  where template_id =:ancienTemplate and abonne_id =:abonneId ';
  685.            // var_dump($sqlrech, $idProduit);exit;
  686.             $stmt $em->getConnection()->prepare($sqlrech);
  687.             $stmt->bindValue(':nouveauTemplate'$nouveauTemplatePDO::PARAM_INT);
  688.             $stmt->bindValue(':ancienTemplate'$ancienTemplatePDO::PARAM_INT);
  689.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  690.             $stmt->execute();
  691.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  692.             $stmt null;
  693.             $res null;
  694.             var_dump($e->getMessage());
  695.         }
  696.         return 1;
  697.     }
  698.     public function updateParcelle(EntityManager $em$abonneId$producteurId =0) {
  699.         try {
  700.             $sqlrech ' UPDATE surface_annee set etat_surface_annee =:etatSupprime  where producteur_id =:producteurId and abonne_id =:abonneId ';
  701.            // var_dump($sqlrech, $idProduit);exit;
  702.             $stmt $em->getConnection()->prepare($sqlrech);
  703.             $stmt->bindValue(':etatSupprime'2PDO::PARAM_INT);
  704.             $stmt->bindValue(':producteurId'$producteurIdPDO::PARAM_INT);
  705.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  706.             $stmt->execute();
  707.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  708.             $stmt null;
  709.             $res null;
  710.             var_dump($e->getMessage());
  711.         }
  712.         return 1;
  713.     }
  714.     public function initialiserToutIspectionApresAjour(EntityManager $em$abonneId 0$type=0) {
  715.         try {
  716.             $sqlrech ' UPDATE inspection set si_apres_ajout = 0 where abonne_id =:abonneId  and type_inspection =:typeinspection';
  717.            // var_dump($sqlrech, $idProduit);exit;
  718.             $stmt $em->getConnection()->prepare($sqlrech);
  719.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  720.             $stmt->bindValue(':typeinspection'$typePDO::PARAM_INT);
  721.             $stmt->execute();
  722.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  723.             $stmt null;
  724.             $res null;
  725.             var_dump($e->getMessage());
  726.         }
  727.         return 1;
  728.     }
  729.     public function initialiserInspectionSuivant(EntityManager $em$abonneId 0$inspectionId=0) {
  730.         try {
  731.             $sqlrech ' UPDATE inspection set si_apres_ajout = 0 where abonne_id =:abonneId  and id =:inspectionId';
  732.            // var_dump($sqlrech, $idProduit);exit;
  733.             $stmt $em->getConnection()->prepare($sqlrech);
  734.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  735.             $stmt->bindValue(':inspectionId'$inspectionIdPDO::PARAM_INT);
  736.             $stmt->execute();
  737.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  738.             $stmt null;
  739.             $res null;
  740.             var_dump($e->getMessage());
  741.         }
  742.         return 1;
  743.     }
  744.     public function supprimerSurfaceAnnee(EntityManager $em) {
  745.         try {
  746.             $sqlrech ' UPDATE 
  747.             producteur p, surface_annee s  SET s.etat_surface_annee = 2
  748.             WHERE  p.id = s.producteur_id  and  p.etat_prod = 2 ';
  749.            // var_dump($sqlrech, $idProduit);exit;
  750.             $stmt $em->getConnection()->prepare($sqlrech);
  751.             //$stmt->bindValue(':produitId', $idProduit, PDO::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.    
  761.     public function supprimerInspectionRempliSurface(EntityManager $em) {
  762.         try {
  763.             $sqlrech ' UPDATE 
  764.             surface_annee s, inspection_rempli r SET r.etat_fournisseur_producteur = 2
  765.             WHERE  s.id = r.surfaceannee_id  and  s.etat_surface_annee = 2
  766.             ';
  767.            // var_dump($sqlrech, $idProduit);exit;
  768.             $stmt $em->getConnection()->prepare($sqlrech);
  769.             //$stmt->bindValue(':produitId', $idProduit, PDO::PARAM_INT);
  770.             $stmt->execute();
  771.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  772.             $stmt null;
  773.             $res null;
  774.             var_dump($e->getMessage());
  775.         }
  776.         return 1;
  777.     }
  778.     public function supprimerInspectionRempliProducteur(EntityManager $em) {
  779.         try {
  780.             $sqlrech ' UPDATE 
  781.             producteur p, inspection_rempli r SET r.etat_fournisseur_producteur = 2
  782.             WHERE  p.id = r.surfaceannee_id  and  p.etat_prod = 2
  783.             ';
  784.            // var_dump($sqlrech, $idProduit);exit;
  785.             $stmt $em->getConnection()->prepare($sqlrech);
  786.             //$stmt->bindValue(':produitId', $idProduit, PDO::PARAM_INT);
  787.             $stmt->execute();
  788.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  789.             $stmt null;
  790.             $res null;
  791.             var_dump($e->getMessage());
  792.         }
  793.         return 1;
  794.     }
  795.     public function initialiserSuiviHistoriqueCommande(EntityManager $em$oldId=0$lnewId=0$produitId=0) {
  796.         try {
  797.             $sqlrech ' UPDATE lignecommande set suivi_historique = :lnewId where suivi_historique = :oldId and produit_id =:produitId  ';
  798.            // var_dump($sqlrech, $idProduit);exit;
  799.             $stmt $em->getConnection()->prepare($sqlrech);
  800.             $stmt->bindValue(':oldId'$oldIdPDO::PARAM_INT);
  801.             $stmt->bindValue(':lnewId'$lnewIdPDO::PARAM_INT);
  802.             $stmt->bindValue(':produitId'$produitIdPDO::PARAM_INT);
  803.             $stmt->execute();
  804.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  805.             $stmt null;
  806.             $res null;
  807.             var_dump($e->getMessage());
  808.         }
  809.         return 1;
  810.     }
  811.     public function initialiserCommandeSuivant(EntityManager $em$oldId=0$produitId=0$ligneCommandeId) {
  812.         try {
  813.             $sqlrech ' UPDATE lignecommande set suivant_commande = :ligneCommandeId where suivi_historique = :oldId and produit_id =:produitId  ';
  814.            // var_dump($sqlrech, $idProduit);exit;
  815.             $stmt $em->getConnection()->prepare($sqlrech);
  816.             $stmt->bindValue(':oldId'$oldIdPDO::PARAM_INT);
  817.             $stmt->bindValue(':ligneCommandeId'$ligneCommandeIdPDO::PARAM_INT);
  818.             $stmt->bindValue(':produitId'$produitIdPDO::PARAM_INT);
  819.             $stmt->execute();
  820.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  821.             $stmt null;
  822.             $res null;
  823.             var_dump($e->getMessage());
  824.         }
  825.         return 1;
  826.     }
  827.     public function deleteCommandeTmp(EntityManager $em$clientId 0) {
  828.         try {
  829.             $sqlrech ' DELETE  FROM commandetmp  where client_id =:clientId ';
  830.            // var_dump($sqlrech, $idProduit);exit;
  831.             $stmt $em->getConnection()->prepare($sqlrech);
  832.             $stmt->bindValue(':clientId'$clientIdPDO::PARAM_INT);
  833.             $stmt->execute();
  834.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  835.             $stmt null;
  836.             $res null;
  837.             var_dump($e->getMessage());
  838.         }
  839.         //var_dump($clientId );exit;
  840.         return 1;
  841.     }
  842.     public function deleteLigneCommandeTmp(EntityManager $em$clientId 0) {
  843.         try {
  844.             $sqlrech ' DELETE FROM lignecommandetmp  where client_id =:clientId ';
  845.            // var_dump($sqlrech, $idProduit);exit;
  846.             $stmt $em->getConnection()->prepare($sqlrech);
  847.             $stmt->bindValue(':clientId'$clientIdPDO::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 initialiserVille(EntityManager $em) {
  857.         try {
  858.             $sqlrech ' UPDATE ville set etat_ville= 3  ';
  859.            // var_dump($sqlrech, $idProduit);exit;
  860.             $stmt $em->getConnection()->prepare($sqlrech);
  861.             
  862.             $stmt->execute();
  863.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  864.             $stmt null;
  865.             $res null;
  866.             var_dump($e->getMessage());
  867.         }
  868.         return 1;
  869.     }
  870.     
  871.      public function initialisePreparationPayement(EntityManager $em) {
  872.         try {
  873.             $sqlrech ' UPDATE info_livrer set etat_payement = 0';
  874.             $stmt $em->getConnection()->prepare($sqlrech);
  875.             
  876.             $stmt->execute();
  877.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  878.             $stmt null;
  879.             $res null;
  880.             var_dump($e->getMessage());
  881.         }
  882.         return 1;
  883.     }
  884.        
  885.     public function initialiserAnneeCampagne(EntityManager $em$idProduit 0){
  886.         try {        
  887.                 $sqlrech ' UPDATE annee_campagne set etat_annee = 0 where produit_id = :produitId ';           
  888.                 $stmt $em->getConnection()->prepare($sqlrech);
  889.                 $stmt->bindValue(':produitId'$idProduitPDO::PARAM_INT);
  890.                 $stmt->execute();
  891.                 //var_dump(1);exit;
  892.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  893.                 $stmt null;
  894.                 $res null;
  895.                 var_dump($e->getMessage()) ;
  896.         } 
  897.         
  898.        return 1;
  899.     } 
  900.     public function initialiserInventaire(EntityManager $em$idProduit 0){
  901.         try {        
  902.                 $sqlrech ' UPDATE inventaire set etat_inventaire = 0 where produit_id = :produitId ';           
  903.                 $stmt $em->getConnection()->prepare($sqlrech);
  904.                 $stmt->bindValue(':produitId'$idProduitPDO::PARAM_INT);
  905.                 $stmt->execute();
  906.                 //var_dump(1);exit;
  907.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  908.                 $stmt null;
  909.                 $res null;
  910.                 var_dump($e->getMessage()) ;
  911.         } 
  912.         
  913.        return 1;
  914.     } 
  915.     
  916.     
  917.     
  918.     
  919.     public function initialiserAncienConteneurZero(EntityManager $em) {
  920.         try {
  921.             $sqlrech ' UPDATE conteneur set etat_conteneur = 0  ';
  922.             $stmt $em->getConnection()->prepare($sqlrech);
  923.             $stmt->execute();
  924.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  925.             $stmt null;
  926.             $res null;
  927.             var_dump($e->getMessage());
  928.         }
  929.         return 1;
  930.     }
  931.     public function calculerStatCommande($listeCommande) {
  932.         foreach ($listeCommande as $uneCommande) {
  933.             $statTab['quantiteTotal'] = $statTab['quantiteTotal'] + $uneCommande->getLignecommandes()[0]->getQuantite();
  934.             $statTab['quantiteTotalLivre'] = $statTab['quantiteTotalLivre'] + $uneCommande->getLignecommandes()[0]->getQuantiteLivre();
  935.             // 
  936.             // var_dump($uneCommande->getLignecommandes()[0]->getId());
  937.         }
  938.         $statTab['pourcentage'] = intval(($statTab['quantiteTotalLivre'] / $statTab['quantiteTotal']) * 100);
  939.         return $statTab;
  940.     }
  941.     function traiterDateFormat($date) {
  942.         $tabDate = array();
  943.         $tabdateWithHour explode(' ',  $date);
  944.         $tabDate array_reverse(explode('-'str_replace("/""-"$tabdateWithHour[0])));
  945. //        $tabDateOrd[0]=$tabDate[0];
  946. //        $tabDateOrd[1]=$tabDate[2];
  947. //        $tabDateOrd[2]=$tabDate[1];
  948. //        var_dump($tabDate);exit;
  949.         return $tabDate;
  950.     }
  951.    
  952.     function getDateFormat($date) {
  953.         $tabDate = array();
  954.         $tabdateWithHour explode(' ',  $date);
  955.         $tabDate array_reverse(explode('-'str_replace("/""-"$tabdateWithHour[0])));
  956. //        $tabDateOrd[0]=$tabDate[0];
  957. //        $tabDateOrd[1]=$tabDate[2];
  958. //        $tabDateOrd[2]=$tabDate[1];
  959. //        var_dump($tabDate);exit;
  960.         return $tabDate[0]."-".$tabDate[1]."-".$tabDate[2]." ".$tabdateWithHour[1] ;
  961.     }
  962.     function affichageCorrectDate($date) {
  963.         $tabDate = array();
  964.         $tabDate array_reverse(explode('-'$date));
  965.         $tabDateOrd[0] = $tabDate[1];
  966.         $tabDateOrd[1] = $tabDate[2];
  967.         $tabDateOrd[2] = $tabDate[0];
  968.         //var_dump($tabDateOrd);exit;
  969.         return implode("/"$tabDateOrd);
  970.     }
  971.     function dateDuPremierDuMois($dateJour) {
  972.         $datedebMois $dateJour->format("m");
  973.         $datedebYear $dateJour->format("Y");
  974.         return new \DateTime($datedebMois "/01/" $datedebYear);
  975.     }
  976.     public function bloquerFournisseur($em$montantRestant$montantSessionData$id$fournisseurRepository) {
  977.         if ($montantRestant $montantSessionData) {
  978.             $objetFournisseur $fournisseurRepository->find($id);
  979.             $objetFournisseur->setEtatFournisseur(TypeEtat::INACTIF);
  980.             $em->persist($objetFournisseur);
  981.             $em->flush();
  982.             return true;
  983.         } else {
  984.             return false;
  985.         }
  986.     }
  987.     public function activerFournisseur($em$montantRestant$montantSessionData$id$fournisseurRepository) {
  988.         if ($montantRestant $montantSessionData) {
  989.             $objetFournisseur $fournisseurRepository->find($id);
  990.             $objetFournisseur->setEtatFournisseur(TypeEtat::ACTIF);
  991.             $em->persist($objetFournisseur);
  992.             $em->flush();
  993.             return true;
  994.         } else {
  995.             return false;
  996.         }
  997.     }
  998.     public function genereLigneSuivieLivraison($em$zone$montant$typeOperation$institule$objetOperation$objetInfoLivrer) {
  999.         $objetSuivieLivraison = new SuivieLivraison();
  1000.         $objetSuivieLivraison->setInfolivrer($objetInfoLivrer);
  1001.         $objetSuivieLivraison->setOperation($objetOperation);
  1002.         $objetSuivieLivraison->setTypeoperation($typeOperation);
  1003.         $objetSuivieLivraison->setMontant($montant);
  1004.         $objetSuivieLivraison->setInstitule($institule);
  1005.         $objetSuivieLivraison->setVille($zone);
  1006.         $em->persist($objetSuivieLivraison);
  1007.         $em->flush();
  1008.         return true;
  1009.     }
  1010.     public function getParamLivraisonDate($em$idParamSystDateRepository $paramSystDateRepository) {
  1011.         $unParam $paramSystDateRepository->find($id);
  1012.         if($unParam !=null){
  1013.             $dateChoisi $unParam->getDateParam();
  1014.         }else{
  1015.             $dateChoisi = new \DateTime(); 
  1016.         }
  1017.         
  1018.         return $dateChoisi->format("d/m/Y");
  1019.     }
  1020.     public function traiteCommande($em$tempIds$prixLimiteCacao$typeaction 1$fournisseurRepository,$commandeRepository ) {
  1021.         $oneOk false;
  1022.         $rep = array();
  1023.         $rep['quantiteTotal'] = 1;
  1024.         $rep['quantiteTotalLivre'] = 1;
  1025.         $rep['montantTotal'] = 1;
  1026.         $rep['montantTotalLivre'] = 1;
  1027.         $detailFournisseur $fournisseurRepository->find($tempIds);
  1028.         $rep['nomFournisseur'] = $detailFournisseur->getNomFournisseur();
  1029.         $rep['id'] = $detailFournisseur->getId();
  1030.         $rep['contactFournisseur'] = $detailFournisseur->getContactFournisseur();
  1031.         $listeCommande $commandeRepository->getUtilisateurCommande($tempIds);
  1032.         $quantite 0;
  1033.         $quantiteLivre 0;
  1034.         $prix 0;
  1035.         foreach ($listeCommande as $uneCommande) {
  1036.             if($uneCommande->getLignecommandes()[0] != null){
  1037.                 $quantite $uneCommande->getLignecommandes()[0]->getQuantite();
  1038.                 $quantiteLivre  $uneCommande->getLignecommandes()[0]->getQuantiteLivre();
  1039.                 $prix $uneCommande->getLignecommandes()[0]->getPrixRigueur()->getInfoPrixRigueur();
  1040.             }
  1041.             $rep['quantiteTotal'] = $rep['quantiteTotal'] + $quantite;
  1042.             $rep['quantiteTotalLivre'] = $rep['quantiteTotalLivre'] + $quantiteLivre ;
  1043.             $montantTotal $quantite $prix;
  1044.             $montantTotalLivre $quantiteLivre  $prix;
  1045. // var_dump($uneCommande->getLignecommandes()[0]->getId());
  1046.             $rep['montantTotal'] = $rep['montantTotal'] + $montantTotal;
  1047.             $rep['montantTotalLivre'] = $rep['montantTotalLivre'] + $montantTotalLivre;
  1048.         }
  1049.         $rep['pourcentage'] = intval(($rep['quantiteTotalLivre'] / $rep['quantiteTotal']) * 100);
  1050.         $rep['resteLivre'] = $rep['quantiteTotal'] - $rep['quantiteTotalLivre'];
  1051.         $rep['montantRestant'] = $rep['montantTotal'] - $rep['montantTotalLivre'];
  1052.         $prixLimiteCacao $detailFournisseur->getCreditFournisseur() + $detailFournisseur->getDepassementFournisseur();
  1053.         /*
  1054.          * variable boolean initialisé a false .elle va être modifier à true si tout se passe bien
  1055.          */
  1056.         if ($typeaction == 1) {
  1057.             $actionFournisseur $this->activerFournisseur($em$rep['montantRestant'], $prixLimiteCacao$tempIds);
  1058.         } else {
  1059.             $actionFournisseur $this->bloquerFournisseur($em$rep['montantRestant'], $prixLimiteCacao$tempIds);
  1060.         }
  1061.         if ($actionFournisseur) {
  1062.             $rep['msg'] = 'bloque';
  1063.             $rep['montantDu'] = $rep['montantRestant'];
  1064.             $rep['montantAccepte'] = $prixLimiteCacao;
  1065.         } else {
  1066.             if ($oneOk) {
  1067. //                    $this->flashMessage->add('fournisseur.gerer.success', $this->translator->trans("site.ajouter.succes"));
  1068.                 $rep['msg'] = '';
  1069.                 $rep['etat'] = true;
  1070.             }
  1071.         }
  1072.         return $rep;
  1073.     }
  1074.     public function getInfoAvcanceFournisseur($em$tempIds) {
  1075.         $oneOk false;
  1076.         $rep = array();
  1077.         $rep['quantiteTotal'] = 1;
  1078.         $rep['quantiteTotalLivre'] = 1;
  1079.         $rep['montantTotal'] = 1;
  1080.         $rep['montantTotalLivre'] = 1;
  1081.         $detailFournisseur $em->getRepository($this->stockBundle 'Fournisseur')->find($tempIds);
  1082.         $rep['nomFournisseur'] = $detailFournisseur->getNomFournisseur();
  1083.         $rep['id'] = $detailFournisseur->getId();
  1084.         $rep['contactFournisseur'] = $detailFournisseur->getContactFournisseur();
  1085.         $listeCommande $em->getRepository($this->stockBundle 'Commande')->getUtilisateurCommande($tempIds);
  1086.         $infoSurPlus $em->getRepository($this->stockBundle 'SurPlus')->findOneBy(array("fournisseur" => $detailFournisseur));
  1087.         $quantite 0;
  1088.         $quantiteLivre 0;
  1089.         $prix 0;
  1090.         foreach ($listeCommande as $uneCommande) {
  1091.            if($uneCommande->getLignecommandes()[0] != null){
  1092.                 $quantite $uneCommande->getLignecommandes()[0]->getQuantite();
  1093.                 $quantiteLivre  $uneCommande->getLignecommandes()[0]->getQuantiteLivre();
  1094.                 $prix $uneCommande->getLignecommandes()[0]->getPrixRigueur()->getInfoPrixRigueur();
  1095.             }
  1096.        
  1097.             $rep['quantiteTotal'] = $rep['quantiteTotal'] + $quantite;
  1098.             $rep['quantiteTotalLivre'] = $rep['quantiteTotalLivre'] +$quantiteLivre ;
  1099.             $montantTotal $quantite $prix;
  1100.             $montantTotalLivre $quantite $prix;
  1101.             $rep['montantTotal'] = $rep['montantTotal'] + $montantTotal;
  1102.             $rep['montantTotalLivre'] = $rep['montantTotalLivre'] + $montantTotalLivre;
  1103.         }
  1104.         $prixR $em->getRepository($this->stockBundle 'PrixRigueur')->getActifPrixRigueur();
  1105.         $nombreInfoLi 0;
  1106.         $montantInfoLi 0;
  1107.         if ($infoSurPlus != null  ) {
  1108.             $nombreInfoLi $infoSurPlus->getQuantite();
  1109.             $montantInfoLi $prixR[0]->getInfoPrixRigueur() * $nombreInfoLi;
  1110.         }
  1111.         $rep['quantiteTotalLivre'] = $rep['quantiteTotalLivre'] + $nombreInfoLi;
  1112.         $rep['montantTotalLivre'] = $rep['montantTotalLivre'] + $montantInfoLi;
  1113.         $rep['pourcentage'] = intval(($rep['quantiteTotalLivre'] / $rep['quantiteTotal']) * 100);
  1114.         $rep['resteLivre'] = $rep['quantiteTotal'] - $rep['quantiteTotalLivre'];
  1115.         $rep['montantRestant'] = $rep['montantTotal'] - $rep['montantTotalLivre'];
  1116.         //var_dump(1);exit;
  1117.         if ($oneOk) {
  1118. //                    $this->flashMessage->add('fournisseur.gerer.success', $this->translator->trans("site.ajouter.succes"));
  1119.             $rep['msg'] = '';
  1120.             $rep['etat'] = true;
  1121.         }
  1122.         return $rep;
  1123.     }
  1124.     public function RecuperCritereRecherche($em$nomcol$datefin$datedeb$ville$util$silivre$numcom) {
  1125.         if ($datedeb == && $datefin == 0) {
  1126.             $dateJour = new \DateTime();
  1127.             $premierDate $this->dateDuPremierDuMois($dateJour);
  1128.             $datedeb $premierDate->format("d/m/Y");
  1129.             $dateMoi $premierDate->add(new DateInterval('P1M'));
  1130.             $datefin $dateMoi->format("d/m/Y");
  1131.         }
  1132.         $tabRetour = array();
  1133.         if ($nomcol != 0) {
  1134.             $objetCollecteur $em->getRepository($this->stockBundle 'Fournisseur')->find($nomcol);
  1135.             $tabRetour['nomCollecteur'] = $objetCollecteur->getNomFournisseur();
  1136.         } else {
  1137.             $tabRetour['nomCollecteur'] = '-';
  1138.         }
  1139.         if ($ville != 0) {
  1140.             $objetVille $em->getRepository($this->stockBundle 'Ville')->find($ville);
  1141.             $tabRetour['nomVille'] = $objetVille->getNomVille();
  1142.         } else {
  1143.             $tabRetour['nomVille'] = '-';
  1144.         }
  1145.         if ($util != 0) {
  1146.             $objetUtil $em->getRepository($this->userBundle 'Utilisateur')->find($util);
  1147.             $tabRetour['nomGerant'] = $objetUtil->getNom();
  1148.         } else {
  1149.             $tabRetour['nomGerant'] = '-';
  1150.         }
  1151.         if ($silivre != 0) {
  1152.             if ($silivre == 1) {
  1153.                 $tabRetour['livre'] = 'Non Livrée';
  1154.             } elseif ($silivre == 2) {
  1155.                 $tabRetour['livre'] = 'Livr. partielle';
  1156.             } elseif ($silivre == 3) {
  1157.                 $tabRetour['livre'] = 'Livr. totale';
  1158.             } else {
  1159.                 $tabRetour['livre'] = 'livr. partielle|totale';
  1160.             }
  1161.         } else {
  1162.             $tabRetour['livre'] = '-';
  1163.         }
  1164.         if ($numcom != 0) {
  1165.             $tabRetour['codeCommande'] = $numcom;
  1166.         } else {
  1167.             $tabRetour['codeCommande'] = '-';
  1168.         }
  1169.         //var_dump($datedeb);exit;
  1170.         $tabRetour['dateDebut'] = $datedeb//$this->affichageCorrectDate($datedeb);
  1171.         $tabRetour['dateFin'] = $datefin//$this->affichageCorrectDate($datefin);
  1172.         return $tabRetour;
  1173.     }
  1174.     public function RecuperCritereRechercheSuivie($em$datefin$datedeb$ville) {
  1175.         if ($datedeb == && $datefin == 0) {
  1176.             $dateJour = new \DateTime();
  1177.             $premierDate $this->dateDuPremierDuMois($dateJour);
  1178.             $datedeb $premierDate->format("d/m/Y");
  1179.             $dateMoi $premierDate->add(new DateInterval('P1M'));
  1180.             $datefin $dateMoi->format("d/m/Y");
  1181.         }
  1182.         $tabRetour = array();
  1183.         if ($ville != 0) {
  1184.             $objetVille $em->getRepository($this->stockBundle 'Ville')->find($ville);
  1185.             $tabRetour['nomVille'] = $objetVille->getNomVille();
  1186.         } else {
  1187.             $tabRetour['nomVille'] = '-';
  1188.         }
  1189.         $tabRetour['dateDebut'] = $datedeb//$this->affichageCorrectDate($datedeb);
  1190.         $tabRetour['dateFin'] = $datefin//$this->affichageCorrectDate($datefin);
  1191.         return $tabRetour;
  1192.     }
  1193.     public function upDateSurPlus($em$nomCollecteur$quantite$fournisseurRepository,$surplusRepository ) {
  1194.         //objet collecteur
  1195.         $criteria = array('codeFournisseur' => $nomCollecteur);
  1196.         $unFournisseur $fournisseurRepository->findOneBy($criteria);
  1197.         //Information sur le surplus
  1198.         $criteriaSurplus = array('fournisseur' => $unFournisseur);
  1199.         $objetSurplus $surplusRepository->findOneBy($criteriaSurplus);
  1200.         if ($objetSurplus == null) {
  1201.             $objetSurplus = new SurPlus();
  1202.         }
  1203.         $objetSurplus->setQuantite($quantite);
  1204.         $objetSurplus->setFournisseur($unFournisseur);
  1205.         $objetSurplus->setDatePublication(new \DateTime());
  1206.         $em->persist($objetSurplus);
  1207.         $em->flush();
  1208.         return $objetSurplus;
  1209.     }
  1210.     public function recupererSurPlus($em$nomCollecteur$fournisseurRepository,$surplusRepository ) {
  1211.         //objet collecteur
  1212.         $criteria = array('codeFournisseur' => $nomCollecteur);
  1213.         $unFournisseur $fournisseurRepository->findOneBy($criteria);
  1214.         //Information sur le surplus
  1215.         $criteriaSurplus = array('fournisseur' => $unFournisseur);
  1216.         $objetSurplus $surplusRepository->findOneBy($criteriaSurplus);
  1217.         if ($objetSurplus == null) {
  1218.             $quantite 0;
  1219.         } else {
  1220.             $quantite $objetSurplus->getQuantite();
  1221.         }
  1222.         return $quantite;
  1223.     }
  1224.     
  1225.     
  1226.       public function saveSurfaceAnnee($em,$objetSurfaceAnnee,$objetAnneeCampagne,$objetSurface,$objetProduit,$objetProducteur,$codeGenere){
  1227.     
  1228.         $objetSurfaceAnnee->setAnneecampagne($objetAnneeCampagne);
  1229.         $objetSurfaceAnnee->setSurface($objetSurface);
  1230.         $objetSurfaceAnnee->setProduit($objetProduit);    
  1231.         $objetSurfaceAnnee->setCodeGenere($codeGenere);
  1232.         $objetSurfaceAnnee->setProducteur($objetProducteur);    
  1233.         $em->persist($objetSurfaceAnnee);
  1234.         $em->flush($objetSurfaceAnnee);
  1235.         
  1236.         return  $objetSurfaceAnnee;
  1237.         
  1238.     }
  1239.     
  1240.     public function getStringSqlVille($niveau){
  1241.         
  1242.         $sql "";
  1243.         $j=0;
  1244.         for($i=1$i<=$niveau$i++){           
  1245.             if($i==1){
  1246.                 $sql .=" LEFT JOIN p.ville v".$i;
  1247.             }else{
  1248.                 $sql .=" LEFT JOIN v".$j.".ville v".$i;
  1249.             }
  1250.             $j=$i;
  1251.         }
  1252.         
  1253.         
  1254.         $sqlCond ="";
  1255.         
  1256.         
  1257.         $sqlCond .=" AND v".$niveau.".id = :ville";
  1258.         
  1259.         $tab[0]= $sql
  1260.         $tab[1]= $sqlCond;
  1261.          
  1262.         return $tab;
  1263.         
  1264.     }
  1265.     
  1266.     public function initialiserIntentionSemence(EntityManager $em) {
  1267.         try {
  1268.             $sqlrech ' UPDATE  producteur set si_intention = 1 , si_semence = 1 ';
  1269.             $stmt $em->getConnection()->prepare($sqlrech);
  1270.             $stmt->bindValue(':prod'$prodPDO::PARAM_INT);
  1271.             $stmt->execute();
  1272.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  1273.             $stmt null;
  1274.             $res null;
  1275.             var_dump($e->getMessage());
  1276.         }
  1277.         return 1;
  1278.     }
  1279.     public function addHistoriqueAction($em$info$operation$codeGenere$utilisateur$producteurId$plateforme$donneeUtilisateurRepository $utilisateurRepository) {
  1280.         //Objet Utilisateur
  1281.         $objetUtilisateur $utilisateurRepository->find($utilisateur);
  1282.        
  1283.         //Objet Producteur
  1284.         //$objetProducteur = $em->getRepository($this->prodBundle . 'Producteur')->find($producteurId);             
  1285.         $objetHistoriqueAction = new HistoriqueAction();
  1286.         //$objetHistoriqueAction->setProducteur($objetProducteur);
  1287.         if($objetUtilisateur !=null){
  1288.             $objetHistoriqueAction->setUtilisateur($objetUtilisateur);
  1289.             $objetHistoriqueAction->setAbonne($objetUtilisateur->getAbonne());
  1290.         }
  1291.         $objetHistoriqueAction->setInfoTable($info);
  1292.         $objetHistoriqueAction->setOperation($operation);
  1293.         $objetHistoriqueAction->setCodeGenere($codeGenere);
  1294.         $objetHistoriqueAction->setDonnee($donnee);
  1295.         $objetHistoriqueAction->setTypePlateforme($plateforme);
  1296.         $em->persist($objetHistoriqueAction);
  1297.         $em->flush();
  1298.         //var_dump($info);exit;
  1299.         return true;
  1300.     }
  1301.     public function addHistoriqueAgentAction($em$info$operation$codeGenere$utilisateur$producteurId$plateforme$donnee,$agentIdUtilisateurRepository $utilisateurRepository$fournisseurRepository) {
  1302.         //Objet Utilisateur
  1303.         $objetUtilisateur $utilisateurRepository->find($utilisateur);
  1304.         $objetFournisseur $fournisseurRepository->find($agentId);
  1305.         //Objet Producteur
  1306.         //$objetProducteur = $em->getRepository($this->prodBundle . 'Producteur')->find($producteurId);             
  1307.         $objetHistoriqueAction = new HistoriqueAction();
  1308.         
  1309.         //$objetHistoriqueAction->setProducteur($objetProducteur);
  1310.         if($objetUtilisateur !=null){
  1311.             
  1312.             $objetHistoriqueAction->setUtilisateur($objetUtilisateur);
  1313.             $objetHistoriqueAction->setAbonne($objetUtilisateur->getAbonne());
  1314.         }
  1315.         
  1316.         $objetHistoriqueAction->setInfoTable($info);
  1317.         $objetHistoriqueAction->setOperation($operation);
  1318.         $objetHistoriqueAction->setFournisseur($objetFournisseur);
  1319.         $objetHistoriqueAction->setCodeGenere($codeGenere);
  1320.         $objetHistoriqueAction->setDonnee($donnee);
  1321.         $objetHistoriqueAction->setTypePlateforme($plateforme);
  1322.         $em->persist($objetHistoriqueAction);
  1323.         $em->flush();
  1324.         //var_dump($info);exit;
  1325.         return true;
  1326.     }
  1327.     public function getHistoriqueAction(EntityManager $em,$abonneId,$etat$datesych) {
  1328.         try {
  1329.             $sqlrech 'SELECT info_table as infoTable, operation, codeGenere, donnee FROM  historique_action WHERE abonne_id =:abonneId  and  date_publication >=:datesych and operation = 1 '//
  1330.            // $sqlrech .= ' SELECT id FROM historique_action_utilisateur WHERE 1=1 )';
  1331.             $stmt $em->getConnection()->prepare($sqlrech);
  1332.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  1333.             $stmt->bindValue(':datesych'$datesychPDO::PARAM_STR);
  1334.             
  1335.             $stmt->execute();
  1336.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  1337.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  1338.             $stmt null;
  1339.             $res null;
  1340.             var_dump($e->getMessage());
  1341.         }
  1342.         return $res;
  1343.     }
  1344.     public function getHistoriqueAgentAction(EntityManager $em,$abonneId,$etat$datesych) {
  1345.         try {
  1346.             $sqlrech 'SELECT info_table as infoTable, operation, codeGenere, donnee FROM  historique_action WHERE abonne_id =:abonneId  and  date_publication >=:datesych and operation = 2 '//
  1347.            // $sqlrech .= ' SELECT id FROM historique_action_utilisateur WHERE 1=1 )';
  1348.             $stmt $em->getConnection()->prepare($sqlrech);
  1349.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  1350.             $stmt->bindValue(':datesych'$datesychPDO::PARAM_STR);
  1351.             
  1352.             $stmt->execute();
  1353.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  1354.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  1355.             $stmt null;
  1356.             $res null;
  1357.             var_dump($e->getMessage());
  1358.         }
  1359.         return $res;
  1360.     }
  1361.     public function genereCodeBarre($em$nombre$conditionnementId){
  1362.         $tab = array();
  1363.         for($i 0;$i<=$nombre;$i++){
  1364.             $tab[$i] = uniqid()."_".$i ;
  1365.             // Inserer les informations dans la table 
  1366.             $unCodeBarre  = new CodeBarre();
  1367.             $unCodeBarre->setCodeBarre($tab[$i]);
  1368.             $unCodeBarre->setUrlCodeBarre($tab[$i]);
  1369.             if($conditionnementId != 0){
  1370.                 $unCodeBarre->setConditionnement($em->getRepository($this->stockBundle 'Conditionnement')->find($conditionnementId));
  1371.             }
  1372.             $em->persist($unCodeBarre);
  1373.             $em->flush();
  1374.         }
  1375.         return $tab ;
  1376.     }
  1377.     public function getAbonne(EntityManager $em$abonneIdAbonneRepository $abonne) {
  1378.         
  1379.         return $abonne->find($abonneId);
  1380.     }
  1381.     public function initialiserClientTableCommande(EntityManager $em$commandeId 0) {
  1382.         try {
  1383.             $sqlrech ' UPDATE commande set client_id = null, table_mange_id = null where id =:commandeId ';
  1384.            // var_dump($sqlrech, $idProduit);exit;
  1385.             $stmt $em->getConnection()->prepare($sqlrech);
  1386.             $stmt->bindValue(':commandeId'$commandeIdPDO::PARAM_INT);
  1387.             $stmt->execute();
  1388.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  1389.             $stmt null;
  1390.             $res null;
  1391.             var_dump($e->getMessage());
  1392.         }
  1393.         return 1;
  1394.     }
  1395.      /**
  1396.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  1397.      *
  1398.      * @author armand.tevi@gmail.com
  1399.      * @copyright ADMIN 2015
  1400.      *
  1401.      * @version 1
  1402.      *
  1403.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  1404.      */
  1405.     protected function validateLigneCommandeInterne($em$codeVente$objetInfoLivrer$objetCommande$objetProduit$objetPrixRigueur$quantite$idLigneCommande 0,
  1406.     $ligneCommandeRepository$livrerRepository) {
  1407.             $em->getConnection()->beginTransaction();
  1408.             //(
  1409.             try {
  1410.                //var_dump($objetPrixRigueur->getInfoPrixRigueur(), $quantite);exit;
  1411.                $montant=0;
  1412.                if($objetPrixRigueur != null){
  1413.                 $prix $objetPrixRigueur->getInfoPrixRigueur();
  1414.                 $montant =  (int)$prix $quantite;
  1415.                 
  1416.             }
  1417.                            // $prix = $objetPrixRigueur->getInfoPrixRigueur();
  1418.                             //$montant =  (int)$prix * $quantite;
  1419.                             $uneLigneCommande$ligneCommandeRepository->find($idLigneCommande);  
  1420.                             if($uneLigneCommande==null){
  1421.                                 $uneLigneCommande = new LigneCommande();
  1422.                                 $quantite $quantite $objetProduit->getQuantiteDetail();
  1423.                                 $uneLigneCommande->setAnnule(false);
  1424.                                 $uneLigneCommande->setEtatLigneCommande(1);
  1425.                                 $uneLigneCommande->setProduit($objetProduit);
  1426.                                 $uneLigneCommande->setFournisseur($objetCommande->getFournisseur());
  1427.                                 $uneLigneCommande->setMontantAutreTaxe($montant);
  1428.                                 $uneLigneCommande->setMontantHt($montant);
  1429.                                 $uneLigneCommande->setQuantite($quantite);
  1430.                                 $uneLigneCommande->setQuantiteLivre($quantite);
  1431.                                 if($objetPrixRigueur != null)
  1432.                                     $uneLigneCommande->setPrixrigueur($objetPrixRigueur);
  1433.                                 $uneLigneCommande->setAbonne($objetCommande->getUtilisateur()->getAbonne());
  1434.                                 $uneLigneCommande->setQuantiteReste(0);
  1435.                                 $uneLigneCommande->setCodeGenere("L_".rand());
  1436.                                 $uneLigneCommande->setTauxTva(0);
  1437.                                 $uneLigneCommande->setCommande($objetCommande);
  1438.                                 $em->persist($uneLigneCommande);
  1439.                                 $em->flush();
  1440.                             }
  1441.                             $uneLivrer$livrerRepository->findOneBy(['lignecommande'=>$uneLigneCommande]); 
  1442.                             if($uneLivrer == null){
  1443.                                 $uneLivrer = new Livrer();
  1444.                             }
  1445.                             $uneLivrer->setDateLivraison(new \DateTime());
  1446.                             $uneLivrer->setEtatLivraison(1);
  1447.                             $uneLivrer->setLignecommande($uneLigneCommande);
  1448.                             $uneLivrer->setNbreLivre($quantite);
  1449.                             //$uneLivrer->setAbonne($objetCommande->getUtilisateur()->getAbonne());
  1450.                             $uneLigneCommande->setQuantiteLivre($quantite);
  1451.                             $uneLigneCommande->setQuantiteReste(0);
  1452.                             //$uneLigneCommande->setEtatLigneCommande(2);
  1453.                             $objetCommande->setEtatCommande(2);
  1454.                             $uneLivrer->setNbreReste(0);
  1455.                             
  1456.                             $uneLivrer->setNombreRestantLivrer(0);
  1457.                             if($objetInfoLivrer!=null){
  1458.                                 $uneLivrer->setInfoLivrer($objetInfoLivrer);
  1459.                                 $uneLivrer->setRefBonLivraison($objetInfoLivrer->getRefBonLivraison());
  1460.                                 $uneLivrer->setRefBonReception($objetInfoLivrer->getRefBonLivraison());
  1461.                             }else{
  1462.                                 $uneLivrer->setRefBonLivraison($codeVente);
  1463.                                 $uneLivrer->setRefBonReception($codeVente);
  1464.                             }
  1465.                             
  1466.                             $uneLivrer->setPrixrigueur($objetPrixRigueur);
  1467.                             $em->persist($uneLigneCommande);
  1468.                             $em->persist($uneLivrer);
  1469.                         
  1470.                             $em->flush();
  1471.                 $em->getConnection()->commit();
  1472.                
  1473.             } catch (\Exception $e) {
  1474.                 $em->getConnection()->rollback();
  1475.                 $em->close();
  1476.                 throw $e;
  1477.             }
  1478.         
  1479.     }
  1480. /**
  1481.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  1482.      *
  1483.      * @author armand.tevi@gmail.com
  1484.      * @copyright ADMIN 2015
  1485.      *
  1486.      * @version 1
  1487.      *
  1488.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  1489.      */
  1490.     protected function saveCommande($em$codeCommande,  $montant$objetClient$objetutilisateur) {
  1491.         $objetCommande = new Commande();
  1492.     
  1493.         $objetCommande->setAnnule(FALSE);
  1494.         $objetCommande->setCodeCommande($codeCommande);
  1495.         $objetCommande->setDescriptionCommande("Reception mobile");
  1496.         $objetCommande->setEtatCommande(1);
  1497.         $objetCommande->setRefBonCommande($codeCommande);
  1498.         $objetCommande->setCodeGenere($codeCommande);
  1499.         $objetCommande->setTauxEchange(0);
  1500.         $objetCommande->setDatePublication(new \DateTime());
  1501.         $objetCommande->setMontantResteCommande(0);
  1502.         $objetCommande->setTypeCommande(3);    
  1503.         $objetCommande->setUtilisateur($objetutilisateur);  
  1504.         $objetCommande->setSiCredit(0);
  1505.         
  1506.         if($objetutilisateur != null)
  1507.             $objetCommande->setAbonne($objetutilisateur->getAbonne());
  1508.         $objetCommande->setMontantCommande($montant);
  1509.         if($objetClient !=null){
  1510.             $objetCommande->setUtilisateur($objetClient->getUtilisateur());
  1511.             if($objetClient->getUtilisateur() !=null ){
  1512.                 if($objetClient->getCaisse() != null)
  1513.                     $objetCommande->setCaisse($objetClient->getCaisse());
  1514.                 else
  1515.                     $objetCommande->setAbonne($objetClient->getUtilisateur()->getAbonne());
  1516.             }
  1517.         }
  1518.         
  1519.         $em->persist($objetCommande);                       
  1520.         $em->flush(); 
  1521.         return $objetCommande;
  1522.     }
  1523.     /**
  1524.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  1525.      *
  1526.      * @author armand.tevi@gmail.com
  1527.      * @copyright ADMIN 2015
  1528.      *
  1529.      * @version 1
  1530.      *
  1531.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  1532.      */ 
  1533.     protected function saveLivraison($em$objetCommande$objetClient,$infoLivrerRepository){
  1534.         $uneInfoLivraison  =   $infoLivrerRepository->findOneBy(['commande'=>$objetCommande]);  
  1535.         if($uneInfoLivraison == null){
  1536.             $uneInfoLivraison = new InfoLivrer();
  1537.             $uneInfoLivraison->setCommande($objetCommande);
  1538.             $uneInfoLivraison->setRefBonLivraison("L".$objetCommande->getRefBonCommande());
  1539.             $uneInfoLivraison->setRefBonReception("L".$objetCommande->getRefBonCommande());
  1540.             $uneInfoLivraison->setCodeGenere("L".$objetCommande->getRefBonCommande());
  1541.             $uneInfoLivraison->setEtatInfoLivrer(1);
  1542.             
  1543.             if($objetCommande->getFournisseur()!=NULL){
  1544.                 $uneInfoLivraison->setFournisseur($objetCommande->getFournisseur());
  1545.             }
  1546.             $uneInfoLivraison->setNbreTotalLivre(0);
  1547.             $uneInfoLivraison->setNbreSaisie(0);
  1548.             $uneInfoLivraison->setAbonne($objetCommande->getAbonne());
  1549.             if($objetClient!=null ){
  1550.                 if($objetClient->getUtilisateur() !=null ){
  1551.                     
  1552.                     if($objetClient->getCaisse() != null)
  1553.                         $uneInfoLivraison->setCaisse($objetClient->getCaisse());
  1554.                     //else
  1555.                         
  1556.                 }
  1557.             }
  1558.            
  1559.             $uneInfoLivraison->setAbonne($objetCommande->getAbonne());
  1560.             if($objetCommande->getSurfaceannee()!=null)
  1561.                 $uneInfoLivraison->setSurfaceannee($objetCommande->getSurfaceannee());
  1562.             $em->persist($uneInfoLivraison);
  1563.             $em->flush();
  1564.         }
  1565.             return $uneInfoLivraison;
  1566.     }
  1567. /**
  1568.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  1569.      *
  1570.      * @author armand.tevi@gmail.com
  1571.      * @copyright ADMIN 2015
  1572.      *
  1573.      * @version 1
  1574.      *
  1575.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  1576.      */
  1577.     protected function saveClient($em$nom$prenoms$cni$telephone$codeGenere$idVille$sexe$id,$password=""$utilisateurRepository$villeRepository$clientRepository$prixRigueurRepository$etatClientRepository) {
  1578.         
  1579.                  $objetVille$villeRepository->find($idVille);                  
  1580.                  $objetAgent=$utilisateurRepository->find($id);
  1581.                  $donnee $nom ."#".$prenoms ."#".$cni ."#"."0"."#".$telephone  ."#".$codeGenere ."#".$idVille "#".$sexe ;
  1582.                  
  1583.                 $d = new \DateTime();
  1584.                 $an $d->format('Y');
  1585.                 $m $d->format('m');
  1586.                 $j $d->format('d');
  1587.                 $testObjetUtilisateur$utilisateurRepository->findOneBy(['username'=>$telephone'abonne'=>$objetAgent->getAbonne()]);
  1588.                 $objetClient$clientRepository->findOneBy(['utilisateur'=>$testObjetUtilisateur]);
  1589.                 if( $testObjetUtilisateur == null){
  1590.                     $objetUtilisateur$utilisateurRepository->findOneBy(['codeGenere'=>$codeGenere]);
  1591.                     if($objetUtilisateur == null)
  1592.                         $objetUtilisateur= new Utilisateur();
  1593.                         //Enregestre ces données comme livraison                        
  1594.                         $objetUtilisateur->setNom($nom);
  1595.                         $objetUtilisateur->setPrenoms($prenoms);
  1596.                         $objetUtilisateur->setCni($cni);
  1597.                         $objetUtilisateur->setSexe($sexe);
  1598.                         // $objetUtilisateur->setVille($objetVille);
  1599.                         if($objetVille !=null ){
  1600.                             $objetUtilisateur->setVille($objetVille);
  1601.                         }
  1602.                     $objetUtilisateur->setTel1($telephone);
  1603.                     $objetUtilisateur->setCodeGenere($codeGenere);
  1604.                     $objetUtilisateur->setAbonne($objetAgent->getAbonne());
  1605.                     if($password != ""){
  1606.                         $objetUtilisateur->setPassword($password);
  1607.                         $objetUtilisateur->setCPassword($password); 
  1608.                     }
  1609.                     if($telephone != ""){
  1610.                         $objetUtilisateur->setUsername($telephone);
  1611.                         $objetUtilisateur->setProfil($objetAgent->getProfil()); 
  1612.                     }
  1613.                         
  1614.                     
  1615.                     $em->persist($objetUtilisateur);
  1616.                     $em->flush($objetUtilisateur);
  1617.                     
  1618.                     if($objetClient == null)
  1619.                         $objetClient= new Client(); 
  1620.                     //Generer un code pour les producteurs
  1621.                         $objetClient->setCodeClient($codeGenere);   
  1622.                         $objetClient->setCodeGenere($codeGenere);  
  1623.                         if($objetVille !=null ){
  1624.                         $objetClient->setVille($objetVille);
  1625.                         }
  1626.                         $objetClient->setUtilisateur($objetUtilisateur); 
  1627.                         $objetClient->setAbonne($objetAgent->getAbonne());
  1628.                         $em->persist($objetClient);    
  1629.                         $em->flush($objetClient);
  1630.                         if($objetUtilisateur == null){
  1631.                             //Enregistrer dans la prix lie à la caisse
  1632.                         $unCaisseClient = new CaisseClient();
  1633.                                 
  1634.                         $unCaisseClient->setCaisse($objetUtilisateur->getCaisse());
  1635.                         $unCaisseClient->setClient($objetClient) ;
  1636.                         $unCaisseClient->setAbonne($objetUtilisateur->getAbonne());
  1637.                         $em->persist($unCaisseClient);
  1638.                     }
  1639.                     // if($password !=""){
  1640.                         $objetListePrix$prixRigueurRepository->findBy(['etatPrixRigueur'=>1'abonne'=>$objetAgent->getAbonne()]);
  1641.                         foreach($objetListePrix as $objetPrix){
  1642.                             $unClientPrix = new ClientPrix();
  1643.                             $unClientPrix->setPrixrigueur($objetPrix);
  1644.                             $unClientPrix->setClient($objetClient) ;
  1645.                             $unClientPrix->setInfoPrix($objetPrix->getInfoPrixRigueur()) ;
  1646.                             $em->persist($unClientPrix);
  1647.                         }
  1648.                         $em->flush();
  1649.                         //Enregister le type de client
  1650.                         $objectEtatClient =  $etatClientRepository->find($etat=1);
  1651.                         $this->saveEtatClient$em$objectEtatClient$objetClient);
  1652.                     
  1653.                     //}
  1654.                     
  1655.                     $this->addHistoriqueAction($em"ClientAdd"1$codeGenere1$objetClient->getId(), 1$donnee$utilisateurRepository);
  1656.                     $tabInfomation["etat"]=true;
  1657.                     $tabInfomation["client"]=$objetClient;
  1658.                     $tabInfomation["codeGenere"]=$codeGenere;
  1659.                     $tabInfomation["message"]='Compte crée avec succés  !';
  1660.                     
  1661.                     
  1662.                 }else {   
  1663.                     
  1664.                     $tabInfomation["etat"]=false;
  1665.                     $tabInfomation["client"]=$objetClient;
  1666.                     $tabInfomation["codeGenere"]=$codeGenere;
  1667.                     $tabInfomation["message"]='Un compte est déjà crée avec ce numéro !'
  1668.                 }  
  1669.                     return $tabInfomation ;
  1670.     }
  1671.     /**
  1672.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  1673.      *
  1674.      * @author armand.tevi@gmail.com
  1675.      * @copyright ADMIN 2015
  1676.      *
  1677.      * @version 1
  1678.      *
  1679.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  1680.      */
  1681.     protected function saveApiClient($em$nom$prenoms$cni$telephone$codeGenere$idVille$sexe$id,$password=""$utilisateurRepository$villeRepository$clientRepository$prixRigueurRepository$etatClientRepository) {
  1682.         
  1683.         $objetVille$villeRepository->find($idVille);                  
  1684.         $objetAgent=$utilisateurRepository->find($id);
  1685.         $donnee $nom ."#".$prenoms ."#".$cni ."#"."0"."#".$telephone  ."#".$codeGenere ."#".$idVille "#".$sexe ;
  1686.         
  1687.        $d = new \DateTime();
  1688.        $an $d->format('Y');
  1689.        $m $d->format('m');
  1690.        $j $d->format('d');
  1691.        $testObjetUtilisateur$utilisateurRepository->findOneBy(['username'=>$telephone'abonne'=>$objetAgent->getAbonne()]);
  1692.        $objetClient$clientRepository->findOneBy(['utilisateur'=>$testObjetUtilisateur]);
  1693.        if( $testObjetUtilisateur == null){
  1694.            $objetUtilisateur$utilisateurRepository->findOneBy(['codeGenere'=>$codeGenere]);
  1695.            if($objetUtilisateur == null)
  1696.                $objetUtilisateur= new Utilisateur();
  1697.                //Enregestre ces données comme livraison                        
  1698.                $objetUtilisateur->setNom($nom);
  1699.                $objetUtilisateur->setPrenoms($prenoms);
  1700.                $objetUtilisateur->setCni($cni);
  1701.                $objetUtilisateur->setSexe($sexe);
  1702.                // $objetUtilisateur->setVille($objetVille);
  1703.                if($objetVille !=null ){
  1704.                    $objetUtilisateur->setVille($objetVille);
  1705.                }
  1706.            $objetUtilisateur->setTel1($telephone);
  1707.            $objetUtilisateur->setCodeGenere($codeGenere);
  1708.            $objetUtilisateur->setAbonne($objetAgent->getAbonne());
  1709.            if($password != ""){
  1710.                $objetUtilisateur->setPassword($password);
  1711.                $objetUtilisateur->setCPassword($password); 
  1712.            }
  1713.            if($telephone != ""){
  1714.                $objetUtilisateur->setUsername($telephone);
  1715.                $objetUtilisateur->setProfil($objetAgent->getProfil()); 
  1716.            }
  1717.                
  1718.            
  1719.            $em->persist($objetUtilisateur);
  1720.            $em->flush($objetUtilisateur);
  1721.            
  1722.            if($objetClient == null)
  1723.                $objetClient= new Client(); 
  1724.            //Generer un code pour les producteurs
  1725.                $objetClient->setCodeClient($codeGenere);   
  1726.                $objetClient->setCodeGenere($codeGenere);  
  1727.                if($objetVille !=null ){
  1728.                $objetClient->setVille($objetVille);
  1729.                }
  1730.                $objetClient->setUtilisateur($objetUtilisateur); 
  1731.                $objetClient->setAbonne($objetAgent->getAbonne());
  1732.                $em->persist($objetClient);    
  1733.                $em->flush($objetClient);
  1734.                if($objetUtilisateur == null){
  1735.                    //Enregistrer dans la prix lie à la caisse
  1736.                $unCaisseClient = new CaisseClient();
  1737.                        
  1738.                $unCaisseClient->setCaisse($objetUtilisateur->getCaisse());
  1739.                $unCaisseClient->setClient($objetClient) ;
  1740.                $unCaisseClient->setAbonne($objetUtilisateur->getAbonne());
  1741.                $em->persist($unCaisseClient);
  1742.            }
  1743.            // if($password !=""){
  1744.                $objetListePrix$prixRigueurRepository->findBy(['etatPrixRigueur'=>1'abonne'=>$objetAgent->getAbonne()]);
  1745.                foreach($objetListePrix as $objetPrix){
  1746.                    $unClientPrix = new ClientPrix();
  1747.                    $unClientPrix->setPrixrigueur($objetPrix);
  1748.                    $unClientPrix->setClient($objetClient) ;
  1749.                    $unClientPrix->setInfoPrix($objetPrix->getInfoPrixRigueur()) ;
  1750.                    $em->persist($unClientPrix);
  1751.                }
  1752.                $em->flush();
  1753.                //Enregister le type de client
  1754.                $objectEtatClient =  $etatClientRepository->find($etat=1);
  1755.                $this->saveEtatClient$em$objectEtatClient$objetClient);
  1756.            
  1757.            //}
  1758.            
  1759.            $this->addHistoriqueAction($em"ClientAdd"1$codeGenere1$objetClient->getId(), 1$donnee$utilisateurRepository);
  1760.            $tabInfomation["etat"]=true;
  1761.            //$tabInfomation["client"]=$objetClient;
  1762.            $tabInfomation["codeGenere"]=$codeGenere;
  1763.            $tabInfomation["message"]='Compte crée avec succés  !';
  1764.            
  1765.            
  1766.        }else {   
  1767.            
  1768.            $tabInfomation["etat"]=false;
  1769.            //$tabInfomation["client"]=$objetClient;
  1770.            $tabInfomation["codeGenere"]=$codeGenere;
  1771.            $tabInfomation["message"]='Un compte est déjà crée avec ce numéro !'
  1772.        }  
  1773.            return $tabInfomation ;
  1774. }
  1775.   
  1776.     protected function saveEtatClient($em$objectEtatClient$objetClient){   
  1777.                     
  1778.         $objetEtatInfoClient = new  EtatInfoClient();
  1779.         $objetEtatInfoClient->setEtatclient($objectEtatClient);
  1780.         $objetEtatInfoClient->setClient($objetClient) ;
  1781.         $em->persist($objetEtatInfoClient);
  1782.         return $objetEtatInfoClient;
  1783.     } 
  1784.   
  1785.     protected function saveEtatInfoOpportuniteClient($em$objetEtatOpportunite$objetOpportunite){   
  1786.                     
  1787.         $objetEtatInfoOpportunite= new  EtatInfoOpportunite();
  1788.         $objetEtatInfoOpportunite->setOpportunite($objetOpportunite);
  1789.         $objetEtatInfoOpportunite->setEtatopportunite($objetEtatOpportunite) ;
  1790.         $em->persist($objetEtatInfoOpportunite);
  1791.         return $objetEtatInfoOpportunite;
  1792.     } 
  1793.     protected function saveOpportuniteClient($em$objetClient$objetAbonne$codeCommande$dateJour){   
  1794.         $objetOpportunite= new  Opportunite();
  1795.         $objetOpportunite->setClient($objetClient);
  1796.         $objetOpportunite->setAbonne($objetAbonne) ;
  1797.         if($objetClient != null)
  1798.             $objetOpportunite->setTitreOpportunite("commande du client ".$objetClient->getUtilisateur()->getNom()." <br/> Num Commnande "$codeCommande ." <br/> Date Commnande ".$dateJour->format("d-m-Y") ) ;
  1799.         else
  1800.             $objetOpportunite->setTitreOpportunite("commande du client  <br/> Num Commnande "$codeCommande ." <br/> Date Commnande ".$dateJour->format("d-m-Y") ) ;
  1801.         $em->persist($objetOpportunite);
  1802.         return $objetOpportunite;
  1803.     } 
  1804.   /**
  1805.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  1806.      *
  1807.      * @author armand.tevi@gmail.com
  1808.      * @copyright ADMIN 2015
  1809.      *
  1810.      * @version 1
  1811.      *
  1812.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  1813.      */
  1814.     protected function updateClient($em$nom$prenoms$cni$telephone$codeGenere$idVille$sexe$id,$password=""$email$adresse$utilisateurRepository$villeRepository$clientRepository$prixRigueurRepository) {
  1815.         
  1816.                  $objetVille$em->getRepository($this->stockBundle 'Ville')->find($idVille);                  
  1817.                  $objetAgent$em->getRepository($this->userBundle 'Utilisateur')->find($id);
  1818.                  $donnee $nom ."#".$prenoms ."#".$cni ."#"."0"."#".$telephone  ."#".$codeGenere ."#".$idVille "#".$sexe ;
  1819.                  //$groupement
  1820.                  // $objetProduit= $em->getRepository($this->stockBundle . 'Produit')->find(1);
  1821.                  //$objetAnneeCampagne = $em->getRepository($this->prodBundle . 'AnneeCampagne')->findOneBy(array("produit"=>$objetProduit,"etatAnneeCampagne"=>1 )) ;
  1822.                  ///$ligneCommande = $em->getRepository($this->stockBundle . 'Commande')->getLigneCommandeOperation($producteur_id, $anneecampagne_id);
  1823.                  
  1824.                  $d = new \DateTime();
  1825.                  $an $d->format('Y');
  1826.                     $m $d->format('m');
  1827.                     $j $d->format('d');
  1828.                     //$testObjetUtilisateur= $em->getRepository($this->userBundle . 'Utilisateur')->findOneBy(['username'=>$telephone, 'abonne'=>$objetAgent->getAbonne()]);
  1829.                     
  1830.                     //if( $testObjetUtilisateur == null){
  1831.                         $objetUtilisateur$utilisateurRepository->findOneBy(['codeGenere'=>$codeGenere]);
  1832.                         if($objetUtilisateur == null)
  1833.                             $objetUtilisateur= new Utilisateur();
  1834.                          //Enregestre ces données comme livraison                        
  1835.                          $objetUtilisateur->setNom($nom);
  1836.                          $objetUtilisateur->setPrenoms($prenoms);
  1837.                          $objetUtilisateur->setCni($cni);
  1838.                          $objetUtilisateur->setSexe($sexe);
  1839.                          
  1840.                          $objetUtilisateur->setEmail($email);
  1841.                          $objetUtilisateur->setAdresse($adresse);
  1842.                          // $objetUtilisateur->setVille($objetVille);
  1843.     
  1844.                          if($objetVille !=null ){
  1845.                             $objetUtilisateur->setVille($objetVille);
  1846.                          }
  1847.                         $objetUtilisateur->setTel1($telephone);
  1848.                         $objetUtilisateur->setCodeGenere($codeGenere);
  1849.                         $objetUtilisateur->setAbonne($objetAgent->getAbonne());
  1850.     
  1851.                         if($password != ""){
  1852.                             $objetUtilisateur->setPassword(md5($password));
  1853.                             $objetUtilisateur->setCPassword(md5($password)); 
  1854.                         }
  1855.     
  1856.                         if($telephone != ""){
  1857.                             $objetUtilisateur->setUsername($telephone);
  1858.                             $objetUtilisateur->setProfil($objetAgent->getProfil()); 
  1859.                         }
  1860.                             
  1861.     
  1862.                         
  1863.                         $em->persist($objetUtilisateur);
  1864.                         $em->flush($objetUtilisateur);
  1865.                         $objetClient$clientRepository->findOneBy(['codeGenere'=>$codeGenere]);
  1866.                         if($objetClient == null)
  1867.                             $objetClient= new Client(); 
  1868.                         //Generer un code pour les producteurs
  1869.                          $objetClient->setCodeClient($codeGenere);   
  1870.                          $objetClient->setCodeGenere($codeGenere);  
  1871.                          if($objetVille !=null ){
  1872.                             $objetClient->setVille($objetVille);
  1873.                          }
  1874.                          $objetClient->setUtilisateur($objetUtilisateur); 
  1875.                          $objetClient->setAbonne($objetAgent->getAbonne());
  1876.                          $em->persist($objetClient);    
  1877.                          $em->flush($objetClient);
  1878.     
  1879.                          if($objetUtilisateur == null){
  1880.                              //Enregistrer dans la prix lie à la caisse
  1881.                         $unCaisseClient = new CaisseClient();
  1882.                                 
  1883.                         $unCaisseClient->setCaisse($objetUtilisateur->getCaisse());
  1884.                         $unCaisseClient->setClient($objetClient) ;
  1885.                         $unCaisseClient->setAbonne($objetUtilisateur->getAbonne());
  1886.                         $em->persist($unCaisseClient);
  1887.                          }
  1888.     
  1889.                         
  1890.                          $this->addHistoriqueAction($em"ClientAdd"1$codeGenere1$objetClient->getId(), 1$donnee$utilisateurRepository);
  1891.                          
  1892.                         $tabInfomation["etat"]=true;
  1893.                         $tabInfomation["message"]='Compte mise à jour avec succes   !';
  1894.                         
  1895.                         
  1896.                    /* }else {   
  1897.                         
  1898.                         $tabInfomation["etat"]=false;
  1899.                         $tabInfomation["message"]='Un compte est déjà crée avec ce numéro !'; 
  1900.                     }  */
  1901.                      return $tabInfomation ;
  1902.     }
  1903.   /**
  1904.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  1905.      *
  1906.      * @author armand.tevi@gmail.com
  1907.      * @copyright ADMIN 2015
  1908.      *
  1909.      * @version 1
  1910.      *
  1911.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  1912.      */
  1913.     protected function saveLigneCommande($em$codeVente$objetInfoLivrer$objetCommande$objetProduit$objetPrixRigueur$quantite$idLigneCommande 0$etat=1$ligneCommandeRepository) {
  1914.         $em->getConnection()->beginTransaction();
  1915.         //(
  1916.         try {
  1917.             $montant =0;    
  1918.                         if($objetPrixRigueur != null){
  1919.                             $prix $objetPrixRigueur->getInfoPrixRigueur();
  1920.                             $montant =  (int)$prix $quantite;   
  1921.                         }
  1922.                         
  1923.                         $objetLigneCommande =$ligneCommandeRepository->findOneBy(array("codeGenere"=>$codeVente));
  1924.                            
  1925.                         $siNouveau 0;
  1926.                         
  1927.                         if($objetLigneCommande ==null){
  1928.                             $siNouveau 1;
  1929.                             $objetLigneCommande = new LigneCommande();
  1930.                         }
  1931.                         
  1932.                         $objetLigneCommande->setAnnule(false);
  1933.                         $objetLigneCommande->setEtatLigneCommande($etat);
  1934.                         $objetLigneCommande->setProduit($objetProduit);
  1935.                         $objetLigneCommande->setMontantAutreTaxe(0);
  1936.                         $objetLigneCommande->setMontantHt($montant);
  1937.                         $objetLigneCommande->setQuantite($quantite);
  1938.                         $objetLigneCommande->setQuantiteLivre($quantite);
  1939.                         $objetLigneCommande->setCodeGenere($codeVente);
  1940.                         if($objetPrixRigueur != null)
  1941.                             $objetLigneCommande->setPrixrigueur($objetPrixRigueur);
  1942.                         $objetLigneCommande->setQuantiteReste(0);
  1943.                         // $objetLigneCommande->setCaisse($objetUtilisateur->getCaisse());
  1944.                         $objetLigneCommande->setTypeOperation($objetCommande->getTypeCommande());
  1945.                         
  1946.                         $objetLigneCommande->setCommande($objetCommande);
  1947.                        // if($objetUtilisateur !=null ){
  1948.                             $objetLigneCommande->setAbonne($objetCommande->getAbonne());
  1949.                         
  1950.                         $objetLigneCommande->setTypeLigneCommande(1);
  1951.                     // $montantCommande = (int) $montantCommande + (int) $montant;
  1952.                         $em->persist($objetLigneCommande);
  1953.                         $em->flush();
  1954.             $em->getConnection()->commit();
  1955.            
  1956.         } catch (\Exception $e) {
  1957.             $em->getConnection()->rollback();
  1958.             $em->close();
  1959.             throw $e;
  1960.         }
  1961.         return  $objetLigneCommande;
  1962.     
  1963. }
  1964. /**
  1965.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  1966.      *
  1967.      * @author armand.tevi@gmail.com
  1968.      * @copyright ADMIN 2015
  1969.      *
  1970.      * @version 1
  1971.      *
  1972.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  1973.      */
  1974.     protected function saveLigneCommandeClient($em$codeVente$objetInfoLivrer$objetCommande$objetProduit$objetPrixRigueur$quantite$idLigneCommande 0$etat=1) {
  1975.         $em->getConnection()->beginTransaction();
  1976.         //(
  1977.         try {
  1978.             $montant =0;    
  1979.                         if($objetPrixRigueur != null){
  1980.                             $prix $objetPrixRigueur->getInfoPrixRigueur();
  1981.                             $montant =  (int)$prix $quantite;
  1982.                             
  1983.                         }
  1984.                         
  1985.                         $objetLigneCommande =$this->LigneCommandeClient->findOneBy(array("codeGenere"=>$codeVente));
  1986.                            
  1987.                         $siNouveau 0;
  1988.                         
  1989.                         if($objetLigneCommande ==null){
  1990.                             $siNouveau 1;
  1991.                             $objetLigneCommande = new LigneCommandeClient();
  1992.                         }
  1993.                         
  1994.                         $objetLigneCommande->setAnnule(false);
  1995.                         $objetLigneCommande->setEtatLigneCommande($etat);
  1996.                         $objetLigneCommande->setProduit($objetProduit);
  1997.                         $objetLigneCommande->setMontantAutreTaxe(0);
  1998.                         $objetLigneCommande->setMontantHt($montant);
  1999.                         $objetLigneCommande->setQuantite($quantite);
  2000.                         $objetLigneCommande->setQuantiteLivre($quantite);
  2001.                         $objetLigneCommande->setCodeGenere($codeVente);
  2002.                         if($objetPrixRigueur != null)
  2003.                             $objetLigneCommande->setPrixrigueur($objetPrixRigueur);
  2004.                         $objetLigneCommande->setQuantiteReste(0);
  2005.                         // $objetLigneCommande->setCaisse($objetUtilisateur->getCaisse());
  2006.                         $objetLigneCommande->setTypeOperation($objetCommande->getTypeCommande());
  2007.                         
  2008.                         $objetLigneCommande->setCommandeclient$objetCommande);
  2009.                        // if($objetUtilisateur !=null ){
  2010.                             $objetLigneCommande->setAbonne($objetCommande->getAbonne());
  2011.                         
  2012.                         $objetLigneCommande->setTypeLigneCommande(1);
  2013.                     // $montantCommande = (int) $montantCommande + (int) $montant;
  2014.                         $em->persist($objetLigneCommande);
  2015.                         $em->flush();
  2016.             $em->getConnection()->commit();
  2017.            
  2018.         } catch (\Exception $e) {
  2019.             $em->getConnection()->rollback();
  2020.             $em->close();
  2021.             throw $e;
  2022.         }
  2023.         return  $objetLigneCommande;
  2024.     
  2025. }
  2026.    
  2027.     protected function savePrix($em$prix$objetProduit$typePrix$objetUtilisateur$prixRigueurRepository,  $cibleRepository$caracteristiquePrixRepository) {
  2028.         $objetPrix $prixRigueurRepository->findOneBy(['infoPrixRigueur'=>$prix'produit'=>$objetProduit'typePrixRigueur'=> $typePrix]);
  2029.             if($objetPrix == null){
  2030.                 $objetCible $cibleRepository->findOneBy(['etat'=>3'abonne'=>$objetUtilisateur->getAbonne()]);
  2031.                 $objetCarat $caracteristiquePrixRepository->findOneBy(['etat'=>3'abonne'=>$objetUtilisateur->getAbonne()]);
  2032.                 $objetPrix = new PrixRigueur();
  2033.                 if($objetCible!= null)
  2034.                     $objetPrix->setCible($objetCible );
  2035.                 if($objetCarat != null)   
  2036.                     $objetPrix->setCaracteristiquePrix($objetCarat);
  2037.                 $objetPrix->setProduit($objetProduit);
  2038.                 $objetPrix->setInfoPrixRigueur($prix);
  2039.                 $objetPrix->setTypePrixRigueur(2);
  2040.                 $objetPrix->setEtatPrixRigueur(1);
  2041.                 $objetPrix->setAbonne($objetUtilisateur->getAbonne());
  2042.                 $em->persist($objetPrix);
  2043.                 $em->flush();
  2044.                 //Enregistrer dans la prix lie à la caisse
  2045.                 if($objetUtilisateur->getCaisse()!=null){
  2046.                     $unCaissePrix = new CaissePrix();   
  2047.                     $unCaissePrix->setCaisse($objetUtilisateur->getCaisse());
  2048.                     $unCaissePrix->setPrixrigueur($objetPrix) ;
  2049.                     $unCaissePrix->setAbonne($objetUtilisateur->getAbonne());
  2050.                     $em->persist($unCaissePrix);
  2051.                 }
  2052.             }
  2053.             return  $objetPrix;
  2054.     }
  2055.     protected function saveSurfaceAnneeFormulaire($em$surfaceAnnee$producteurId$produitId$objetAnneeCampagne$codeGenere$utilId$producteurRepository$produitRepository$utilisateurRepository$codeExploitation=0$typeParcelle=0) {
  2056.             $objetProducteur $producteurRepository->find($producteurId);
  2057.             if($produitId !=0)
  2058.                 $objetProduit =$produitRepository->find($produitId);
  2059.             $parCodeGenere $codeGenere;
  2060.             $surfaceAnnee->setAnneecampagne($objetAnneeCampagne);
  2061.             $surfaceAnnee->setProducteur($objetProducteur);
  2062.             $surfaceAnnee->setProduit($objetProduit);
  2063.             $surfaceAnnee->setCodeGenere($codeGenere);
  2064.             $surfaceAnnee->setCodeSurface($codeGenere);
  2065.             $surfaceAnnee->setProdCodeGenere($objetProducteur->getCodeGenere());
  2066.             $em->persist($surfaceAnnee);
  2067.             $em->flush();
  2068.             if($surfaceAnnee->getSurfaceannee() != null)
  2069.                 $parCodeGenere $surfaceAnnee->getSurfaceannee()->getCodeGenere();
  2070.             $donnee $surfaceAnnee->getSuperficie() ."#".$objetProducteur->getCodeGenere() ."#".$codeGenere ."#"$parCodeGenere ."#1#".$produitId ."#0#".$utilId."#".$codeExploitation."#".$typeParcelle."#0#0";   
  2071.             $this->addHistoriqueAction($em'ProducteurIntention'1$codeGenere$utilId$objetProducteur->getId(), 1$donnee$utilisateurRepository);
  2072.     
  2073.             return  $surfaceAnnee;
  2074.     }
  2075.     protected function saveTacheFormulaire($em$titre$observation$datedeb$datefin$heuredeb$heurefin$idOperation,$tabIdUtil$utilId,  $type,
  2076.      $utilisateurRepository$anneCampagneRepository$surfaceAnneeRepository$planteRepository$projetRepository$producteurRepository$tacheProduitEtapeCroissanceRepository) {
  2077.    
  2078.         
  2079.         $objetUtilisateur $utilisateurRepository->find((int)$utilId);
  2080.         //$idProjet =0;
  2081.         if($type == 1){
  2082.             $objetSaison $anneCampagneRepository->find((int)$idOperation);
  2083.         }
  2084.         else if($type == 2){
  2085.             $objetSurfaceAnnee $surfaceAnneeRepository->findOneBy(["codeGenere"=>$idOperation]);
  2086.         }
  2087.         else if($type == 3){
  2088.             $objetPlante$planteRepository->findOneBy(["codeGenere"=>$idOperation]);
  2089.         }
  2090.         
  2091.         else if($type == 4){
  2092.             $objetProducteur$producteurRepository->findOneBy(["codeGenere"=>$idOperation]);
  2093.         }
  2094.         
  2095.         else if($type == 5){
  2096.             $objeTacheProduitEtapeCroissance$tacheProduitEtapeCroissanceRepository->find($idOperation);
  2097.         }else{
  2098.             $unProjet $projetRepository->find((int)$idOperation);
  2099.         }
  2100.         //$unBeneficiaire = $em->getRepository($this->assoBundle . 'Beneficiaire')->find((int) $idBeneficiaire);
  2101.         //$type = $request->request->get("type");
  2102.         $uneActivite =  new Activite();
  2103.         //AnneeCampagne  
  2104.         if($type != 5)                          
  2105.             $uneActivite->setDescriptionActivite($observation); 
  2106.         else
  2107.             $uneActivite->setSurfaceAnnee($observation); 
  2108.         //$uneActivite->setMotif($motif);        
  2109.         //$uneActivite->setCat($cat);        
  2110.         $uneActivite->setTitreActivite($titre);    
  2111.         $uneActivite->setDateDebut(new \DateTime($datedeb." ".$heuredeb));
  2112.         $uneActivite->setDateFin(new \DateTime($datefin." ".$heurefin));
  2113.         if($type == 5){
  2114.             $uneActivite->setSiAgricole(1);    
  2115.             if($utilId == )
  2116.                 $uneActivite->setSiRecolte(1);    
  2117.         }
  2118.         //$objetPlante->setAbonne($objetUtilisateur->getAbonne());                        
  2119.         //$uneActivite->setBeneficiaire($descriptionActivite);
  2120.         //$uneActivite->setVille($uneVille);
  2121.         if($type == 1){
  2122.             $uneActivite->setSaison($objetSaison);
  2123.         } else if($type == 2){
  2124.             $uneActivite->setSurfaceAnnee($objetSurfaceAnnee);
  2125.         } else if($type == 3){
  2126.             $uneActivite->setPlante($objetPlante);
  2127.         } else if($type == 4){
  2128.             $uneActivite->setProducteur($objetProducteur);
  2129.             //var_dump(1);exit;
  2130.         } else if($type == 5){
  2131.             $uneActivite->setTacheproduitetapecroissance($objeTacheProduitEtapeCroissance);
  2132.             //var_dump(1);exit;
  2133.         }else{
  2134.             $uneActivite->setProjet($unProjet);
  2135.         }
  2136.         
  2137.         $uneActivite->setTypeActivite($type);
  2138.         $uneActivite->setAbonne($objetUtilisateur->getAbonne());
  2139.         $em->persist($uneActivite);    
  2140.         $tabIdUtil explode('|'$tabIdUtil); 
  2141.             $i 0;
  2142.             foreach($tabIdUtil as $utilId){
  2143.                 if($utilId !=""){
  2144.                     $objetUtilisateur$utilisateurRepository->find($utilId);
  2145.                     $concerne =  new Concerne();
  2146.                     $concerne->setActivite($uneActivite);
  2147.                     // $concerne->setBeneficiaire($unBeneficiaire);
  2148.                     $concerne->setUtilisateur($objetUtilisateur);
  2149.                     //$concerne->setObservation($observation);
  2150.                     //$em->persist($uneActivite);
  2151.                     $em->persist($concerne);
  2152.                     ++$i;
  2153.                 }
  2154.             }
  2155.         $em->flush();
  2156.     }
  2157.     public function getActiviteSuivant(EntityManager $em$objetProduitEtapeCroissance,  $objetTacheProduitEtapeCroissance$produitEtapeCroissanceRepository,  $tacheProduitEtapeCroissanceRepository$objetSurfaceAnnee) {
  2158.         $i=1;
  2159.         do {
  2160.             $ordreSuivant $objetProduitEtapeCroissance->getOrdre() + $i;
  2161.             $siStop false ;
  2162.             $objetProduitEtapeCroissanceSuivant $produitEtapeCroissanceRepository->findOneBy(['produit'=>$objetProduitEtapeCroissance->getProduit(), "ordre"=>$ordreSuivant]);
  2163.             
  2164.             if($objetProduitEtapeCroissanceSuivant != null){
  2165.             
  2166.                 $objetTacheProduitEtapeCroissance $tacheProduitEtapeCroissanceRepository->findOneBy(['produitetapecroissance'=>$objetProduitEtapeCroissanceSuivant'siLastEtapeActivite'=>1]);
  2167.                 if($objetTacheProduitEtapeCroissance != null) {
  2168.                     $objetActivite= new Activite();
  2169.                     $objetActivite->setDescriptionActivite("Tache");
  2170.                     $objetActivite->setTypeActivite($objetTacheProduitEtapeCroissance->getActivite()->getTypeActivite());
  2171.                     $objetActivite->setTitreActivite($objetTacheProduitEtapeCroissance->getActivite()->getTitreActivite());
  2172.                     $periode =  $objetProduitEtapeCroissance->getPeriodeEtapeCroissance();
  2173.                     $periodeSuivant $objetProduitEtapeCroissance->getPeriodeEtapeCroissance() + 10;
  2174.                     if($i == 1){
  2175.                         $dateDebut $objetTacheProduitEtapeCroissance->getDateDebut()->modify("+"$periode +" days");
  2176.                         
  2177.                         $dateFin $objetTacheProduitEtapeCroissance->getDateFin()->modify("+"$periodeSuivant +" days");
  2178.                     }else{
  2179.                         $dateDebut $objetProduitEtapeCroissanceSuivant->getDateDebut()->modify("+"$periode +" days");
  2180.                         $dateFin $objetProduitEtapeCroissanceSuivant->getDateFin()->modify("+"$periodeSuivant +" days");
  2181.                     }
  2182.                     $objetActivite->setDateDebut($dateDebut);
  2183.                     $objetActivite->setDateFin($dateFin);
  2184.                     $objetActivite->setTacheproduitetapecroissance($objetTacheProduitEtapeCroissance);
  2185.                     $objetActivite->setSurfaceannee($objetSurfaceAnnee);
  2186.                     $objetActivite->setProducteur($objetSurfaceAnnee->getProducteur());
  2187.                     $em->persist($objetActivite);
  2188.                     
  2189.                 }
  2190.                 
  2191.             }
  2192.             if($objetProduitEtapeCroissance ==null)
  2193.                  $siStop true;
  2194.             $objetProduitEtapeCroissance =  $objetProduitEtapeCroissanceSuivant ;
  2195.             ++$i;
  2196.         }while($siStop);
  2197.         $em->flush();
  2198.         return 1;
  2199.     }
  2200.     protected function saveVarieteTransformation($em$unProduit$objetProduit$categorie$objetAbonne$siSemence=0) {
  2201.     
  2202.         $unProduit->setProduit($objetProduit);
  2203.         $unProduit->setCodeGenere($unProduit->getCodeProduit());
  2204.         $unProduit->setDescriptionProduit($unProduit->getNomProduit());
  2205.         $unProduit->setCategorie($categorie); //Produit transforme
  2206.         if($siSemence == ){
  2207.             $unProduit->setSiSemence(1);    
  2208.         }else if( $siSemence == ){
  2209.             $unProduit->setSiAgricole(1); 
  2210.         }
  2211.         $unProduit->setAbonne($objetAbonne);
  2212.         $em->persist($unProduit);
  2213.         $em->flush();
  2214.         return   $unProduit;
  2215.     }
  2216.     protected function saveProduitConditionne($em$unProduit$objetCarateristiqueProduit$categorie$objetAbonne$siSemence=0) {
  2217.     
  2218.         $unProduit->setCarateristiqueproduit($objetCarateristiqueProduit);
  2219.         $unProduit->setCodeGenere($unProduit->getCodeProduit());
  2220.         $unProduit->setDescriptionProduit($unProduit->getNomProduit());
  2221.         $unProduit->setCategorie($categorie); //Produit transforme
  2222.         if($siSemence == ){
  2223.             $unProduit->setSiSemence(1);    
  2224.         }else if( $siSemence == ){
  2225.             $unProduit->setSiAgricole(1); 
  2226.         }
  2227.         $unProduit->setAbonne($objetAbonne);
  2228.         $em->persist($unProduit);
  2229.         $em->flush();
  2230.         return   $unProduit;
  2231.     }
  2232.     public function initialiserProduitInspection(EntityManager $em$inspectionId 0) {
  2233.         try {
  2234.             $sqlrech ' UPDATE inspection_produit set etat_inspection_produit = 2 where inspection_id =:inspectionId ';
  2235.            // var_dump($sqlrech, $idProduit);exit;
  2236.             $stmt $em->getConnection()->prepare($sqlrech);
  2237.             $stmt->bindValue(':inspectionId'$inspectionIdPDO::PARAM_INT);
  2238.             $stmt->execute();
  2239.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2240.             $stmt null;
  2241.             $res null;
  2242.             var_dump($e->getMessage());
  2243.         }
  2244.         return 1;
  2245.     }
  2246.     public function initialiserOpportunite(EntityManager $em$etatOpportuniteId 0$opportuniteId 0) {
  2247.         try {
  2248.             $sqlrech ' UPDATE etat_info_opportunite set etat_data_info_opportunite = 0 where etatopportunite_id =:etatOpportuniteId AND opportunite_id =:opportuniteId ';
  2249.            // var_dump($sqlrech, $idProduit);exit;
  2250.             $stmt $em->getConnection()->prepare($sqlrech);
  2251.             $stmt->bindValue(':etatOpportuniteId'$etatOpportuniteIdPDO::PARAM_INT);
  2252.             $stmt->bindValue(':opportuniteId'$opportuniteIdPDO::PARAM_INT);
  2253.             $stmt->execute();
  2254.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2255.             $stmt null;
  2256.             $res null;
  2257.             var_dump($e->getMessage());
  2258.         }
  2259.         return 1;
  2260.     }
  2261.     public function initialiserProfilInspection(EntityManager $em$inspectionId 0) {
  2262.         try {
  2263.             $sqlrech ' UPDATE inspection_profil set etat_inspection_profil = 2 where inspection_id =:inspectionId ';
  2264.            // var_dump($sqlrech, $idProduit);exit;
  2265.             $stmt $em->getConnection()->prepare($sqlrech);
  2266.             $stmt->bindValue(':inspectionId'$inspectionIdPDO::PARAM_INT);
  2267.             $stmt->execute();
  2268.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2269.             $stmt null;
  2270.             $res null;
  2271.             var_dump($e->getMessage());
  2272.         }
  2273.         return 1;
  2274.     }
  2275.     public function genereCodeProducteurVersionAnanas(EntityManager $em$villageId$groupementId$anneeAdhesion$zoneProducteur=0$groupementRepository$producteurGroupementRepository
  2276.     ,$villeRepository$abonneVilleRepository) {
  2277.         //var_dump($villageId, $groupementId, $anneeAdhesion);exit;
  2278.        
  2279.         try {
  2280.             $objetGroupement $groupementRepository->find($groupementId);
  2281.             $listeProducteurGroupement $producteurGroupementRepository->findBy(['groupement'=>$objetGroupement]);
  2282.             $rangProducteur count($listeProducteurGroupement)+1;
  2283.             if($rangProducteur<10)
  2284.                 $rangProducteur "0".$rangProducteur;
  2285.             $objetVillage$villeRepository->find($villageId);
  2286.             $codeVillage substr($objetVillage->getNomVille(), 03);
  2287.             if($zoneProducteur != null )
  2288.                 $codeZone substr($zoneProducteur->getNomVille(), 02);
  2289.             else
  2290.                 $codeZone ="";
  2291.             $anneeAdhesion substr($anneeAdhesion22);
  2292.             
  2293.             $criteriaAbonneVille = array('abonne' => $objetGroupement->getAbonne(), 'ville'=>$objetVillage);
  2294.             $objetAbonneVille $abonneVilleRepository->findOneBy($criteriaAbonneVille);
  2295.             $objetPartenaire $objetVillage;
  2296.             if($objetAbonneVille !=null)
  2297.                 $etatVilleAbonne $objetAbonneVille->getEtatAbonneVille();
  2298.             else
  2299.                 $etatVilleAbonne "";
  2300.             //var_dump($codeVillage);exit;
  2301.             /*if($objetVillage->getTypeVille() == 5){
  2302.                 $objetPartenaire = $objetVillage->getVille()->getVille()->getVille();
  2303.             }else if($objetVillage->getTypeVille() == 4){
  2304.                 $objetPartenaire = $objetVillage->getVille()->getVille();
  2305.             }else if($objetVillage->getTypeVille() == 3){
  2306.                 $objetPartenaire = $objetVillage->getVille();
  2307.             }
  2308.             if($zoneProducteur!=0)
  2309.                 $objetZoneProducteur = $zoneProducteur;
  2310.             else
  2311.                 $objetZoneProducteur =$objetPartenaire->getVille();*/
  2312.             //var_dump($objetPartenaire->getId(),$objetPartenaire->getTypeVille(),$objetPartenaire->getCodeVille());exit;
  2313.             $codeProducteur =  "F".$anneeAdhesion." ".$codeZone." ".$etatVilleAbonne." ".$objetGroupement->getCodeGenere()." ".$rangProducteur;
  2314.            // var_dump( $codeProducteur);exit;
  2315.            //var_dump($objetPartenaire->getVille()->getVille(), $objetPartenaire->getCodeVille(), $anneeAdhesion,$codeVillage,$objetGroupement->getCodeGenere(),$rangProducteur);exit;
  2316.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2317.             var_dump($e->getMessage());
  2318.         }
  2319.         return $codeProducteur;
  2320.     }
  2321.     public function genereCodeProducteurVersionAnanas_2(EntityManager $em$villageId$groupementId$anneeAdhesion$zoneProducteur=0) {
  2322.         //var_dump($villageId, $groupementId, $anneeAdhesion);exit;
  2323.        
  2324.         try {
  2325.             $objetGroupement $em->getRepository($this->prodBundle 'Groupement')->find($groupementId);
  2326.             $listeProducteurGroupement $em->getRepository($this->prodBundle 'ProducteurGroupement')->findBy(['groupement'=>$objetGroupement]);
  2327.             $rangProducteur count($listeProducteurGroupement)+1;
  2328.             if($rangProducteur<10)
  2329.                 $rangProducteur "0".$rangProducteur;
  2330.             $objetVillage$em->getRepository($this->stockBundle 'Ville')->find($villageId);
  2331.             $codeVillage substr($objetVillage->getNomVille(), 03);
  2332.             $anneeAdhesion substr($anneeAdhesion22);
  2333.             //var_dump($objetVillage->getVille()->getVille()->getVille()->getId());exit;
  2334.             $criteriaAbonneVille = array('abonne' => $objetGroupement->getAbonne(), 'ville'=>$objetVillage);
  2335.             $objetAbonneVille $em->getRepository($this->userBundle 'AbonneVille')->findOneBy($criteriaAbonneVille);
  2336.             $objetPartenaire $objetVillage;
  2337.             
  2338.             if($objetVillage->getTypeVille() == 5){
  2339.                 $objetPartenaire $objetVillage->getVille()->getVille()->getVille();
  2340.             }else if($objetVillage->getTypeVille() == 4){
  2341.                 $objetPartenaire $objetVillage->getVille()->getVille();
  2342.             }else if($objetVillage->getTypeVille() == 3){
  2343.                 $objetPartenaire $objetVillage->getVille();
  2344.             }
  2345.             if($zoneProducteur!=0)
  2346.                 $objetZoneProducteur $zoneProducteur;
  2347.             else
  2348.                 $objetZoneProducteur =$objetPartenaire->getVille();
  2349.             //var_dump($objetPartenaire->getId(),$objetPartenaire->getTypeVille(),$objetPartenaire->getCodeVille());exit;
  2350.             $codeProducteur =  "F".$anneeAdhesion." ".$objetPartenaire->getCodeVille()." ".$objetZoneProducteur->getCodeVille()." ".$objetAbonneVille->getEtatAbonneVille()." ".$objetGroupement->getCodeGenere()." ".$rangProducteur;
  2351.             //var_dump("F",$anneeAdhesion,$objetPartenaire->getCodeVille(),$objetZoneProducteur->getCodeVille(),$objetAbonneVille->getEtatAbonneVille(),$objetGroupement->getCodeGenere(),$rangProducteur);exit;
  2352.            //var_dump($objetPartenaire->getVille()->getVille(), $objetPartenaire->getCodeVille(), $anneeAdhesion,$codeVillage,$objetGroupement->getCodeGenere(),$rangProducteur);exit;
  2353.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2354.             var_dump($e->getMessage());
  2355.         }
  2356.         return $codeProducteur;
  2357.     }
  2358.     public function genereNumeroLotCaisse(EntityManager $em$nombreCargaison,$nombreCarton$anneeAdhesion$regionId) {
  2359.         try {
  2360.             $objetVillage$em->getRepository($this->stockBundle 'Ville')->find($regionId);
  2361.             $codeVillage substr($objetVillage->getNomVille(), 02);
  2362.             $anneeAdhesion substr($anneeAdhesion22);
  2363.             //var_dump($objetVillage->getVille()->getVille()->getVille()->getId());exit
  2364.             //var_dump($objetPartenaire->getId(),$objetPartenaire->getTypeVille(),$objetPartenaire->getCodeVille());exit;
  2365.             $codeLot =  sprintf("%04d"$nombreCargaison)."-".sprintf("%05d"$nombreCarton)."-".$anneeAdhesion."-".$codeVillage."-TG" ;
  2366.             //var_dump("F",$anneeAdhesion,$objetPartenaire->getCodeVille(),$objetZoneProducteur->getCodeVille(),$objetAbonneVille->getEtatAbonneVille(),$objetGroupement->getCodeGenere(),$rangProducteur);exit;
  2367.            //var_dump($objetPartenaire->getVille()->getVille(), $objetPartenaire->getCodeVille(), $anneeAdhesion,$codeVillage,$objetGroupement->getCodeGenere(),$rangProducteur);exit;
  2368.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2369.             var_dump($e->getMessage());
  2370.         }
  2371.         return $codeLot;
  2372.     }
  2373.     public function dupliquerImageProduit(EntityManager $em$parentId$objetProduitEncours$objetAbonne) {
  2374.         //var_dump($villageId, $groupementId, $anneeAdhesion);exit;
  2375.         try {
  2376.             $objetProduit $em->getRepository($this->stockBundle 'Produit')->find($parentId);
  2377.             
  2378.             $objetImageParent $em->getRepository($this->stockBundle 'Image')->findOneBy(['produit'=>$objetProduit]);
  2379.             if($objetImageParent != null){
  2380.                 $objetImage = new Image();
  2381.                 $objetImage->setUrlImage($objetImageParent->getUrlImage());
  2382.                // $objetImage->setInspectionrempli($$objetProduit);    
  2383.                 $objetImage->setElementCodeGenere($objetProduitEncours->getCodeGenere());    
  2384.                 $objetImage->setProduit($objetProduit);    
  2385.                 $objetImage->setAbonne($objetAbonne);        
  2386.                 $objetImage->setCodeGenere("IMGV_".rand());                
  2387.                 $objetImage->setTitreImage("Produit Image");                   
  2388.                 $em->persist($objetImage);    
  2389.                 $em->flush($objetImage);
  2390.             }
  2391.            
  2392.            //var_dump($objetPartenaire->getVille()->getVille(), $objetPartenaire->getCodeVille(), $anneeAdhesion,$codeVillage,$objetGroupement->getCodeGenere(),$rangProducteur);exit;
  2393.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2394.             var_dump($e->getMessage());
  2395.         }
  2396.         return  $objetImage;
  2397.     }
  2398.     /**
  2399.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  2400.      *
  2401.      * @author armand.tevi@gmail.com
  2402.      * @copyright ADMIN 2015
  2403.      *
  2404.      * @version 1
  2405.      *
  2406.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  2407.      */
  2408.     protected function savePlante($em$codePlante$prodCodeGenere$codeGenere$parCodeGenere$utilisateurRepository,  $produitRepository,  $surfaceAnneeRepository ,  $planteRepository){
  2409.             $donnee $codePlante."#".$prodCodeGenere."#".$codeGenere."#".$parCodeGenere;
  2410.             $objetProduit$produitRepository->findOneBy(['codeGenere'=>$prodCodeGenere]);                  
  2411.             $objetSurfaceAnnee$surfaceAnneeRepository->findOneBy(['codeGenere'=>$prodCodeGenere]);                  
  2412.                   
  2413.             $objetPlante $planteRepository->findOneBy(['codePlante'=>$codePlante'produit'=>$objetProduit'surfaceannee'=>$objetSurfaceAnnee ]);
  2414.             if($objetPlante == null)
  2415.                 $objetPlante= new Plante();
  2416.                     //Enregestre ces données comme livraison                        
  2417.                     $objetPlante->setCodePlante($codePlante);
  2418.                     $objetPlante->setCodeGenere($codeGenere);
  2419.                     $objetPlante->setProduit($objetProduit);
  2420.                     $objetPlante->setAbonne($objetProduit->getAbonne());
  2421.                     $objetPlante->setSurfaceannee($objetSurfaceAnnee);
  2422.                     // $objetUtilisateur->setVille($objetVille);
  2423.                     $em->persist($objetPlante);
  2424.                // }
  2425.                 $em->flush();
  2426.             
  2427.                 $this->addHistoriqueAction($em"PlanteAdd"1$codeGenere1NUll1$donnee$utilisateurRepository);
  2428.     }
  2429.     /**
  2430.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  2431.      *
  2432.      * @author armand.tevi@gmail.com
  2433.      * @copyright ADMIN 2015
  2434.      *
  2435.      * @version 1
  2436.      *
  2437.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  2438.      */
  2439.     protected function saveUtilisateur($em$nom$prenoms$username,$password$cni$telephone$codeGenere$idVille$sexe$profilId) {
  2440.         //$objetVille= $em->getRepository($this->stockBundle . 'Ville')->find($idVille);                  
  2441.                 
  2442.                  $d = new \DateTime();
  2443.                  $an $d->format('Y');
  2444.                     $m $d->format('m');
  2445.                     $j $d->format('d');
  2446.                     $objetUtilisateur$em->getRepository($this->userBundle 'Utilisateur')->findOneBy(['codeGenere'=>$codeGenere]);
  2447.                     $objetProfil$em->getRepository($this->userBundle 'Profil')->find($profilId);
  2448.                   
  2449.                     if($objetUtilisateur == null)
  2450.                         $objetUtilisateur= new Utilisateur();
  2451.                      //Enregestre ces données comme livraison                        
  2452.                      $objetUtilisateur->setNom($nom);
  2453.                      $objetUtilisateur->setPrenoms($prenoms);
  2454.                      $objetUtilisateur->setCni($cni);
  2455.                      $objetUtilisateur->setSexe($sexe);
  2456.                      $objetUtilisateur->setUsername($username);
  2457.                      $objetUtilisateur->setPassword($password);
  2458.                      $objetUtilisateur->setCpassword($password);
  2459.                      // $objetUtilisateur->setVille($objetVille);
  2460.                      
  2461.                     $objetUtilisateur->setTel1($telephone);
  2462.                     $objetUtilisateur->setCodeGenere($codeGenere);
  2463.                     $objetUtilisateur->setAbonne($objetProfil->getAbonne());
  2464.                     $objetUtilisateur->setProfil($objetProfil);
  2465.                     $em->persist($objetUtilisateur);
  2466.                     $em->flush($objetUtilisateur);
  2467.                     
  2468.  
  2469.     }
  2470.     /**
  2471.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  2472.      *
  2473.      * @author armand.tevi@gmail.com
  2474.      * @copyright ADMIN 2015
  2475.      *
  2476.      * @version 1
  2477.      *
  2478.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  2479.      */
  2480.     protected function saveAutreInfoProducteur($em,$groupement$objetProducteur$ville 0$villeRepository,$groupementRepository$producteurGroupementRepository$zoneProducteurRepository) {
  2481.         //$objetVille= $em->getRepository($this->stockBundle . 'Ville')->find($idVille);                  
  2482.                 
  2483.             //Enregistrer le groupement
  2484.             $objetGroupement $groupementRepository->find($groupement);    
  2485.             
  2486.             if($ville !=0)
  2487.                 $objetVille $villeRepository->find($ville); 
  2488.             
  2489.             //$em->getRepository($this->stockBundle . 'Ville')->findOneBy(array('nomVille'=>$groupement));
  2490.                         
  2491.             $objetProducteurGroupement$producteurGroupementRepository->findOneBy(['producteur'=>$objetProducteur]);                   //$em->getRepository($this->stockBundle . 'Ville')->findOneBy(array('nomVille'=>$groupement));
  2492.             if($objetProducteurGroupement == null )
  2493.                 $objetProducteurGroupement= new ProducteurGroupement(); 
  2494.             $objetProducteurGroupement->setProducteur($objetProducteur);
  2495.             $objetProducteurGroupement->setGroupement($objetGroupement);
  2496.             $objetProducteurGroupement->setAbonne($objetProducteur->getAbonne());
  2497.             $em->persist($objetProducteurGroupement);    
  2498.             $em->flush($objetProducteurGroupement);
  2499.             // Mettre le producteur dans une zone
  2500.             $objetZoneProducteur$zoneProducteurRepository->findOneBy(['producteur'=>$objetProducteur]);                   //$em->getRepository($this->stockBundle . 'Ville')->findOneBy(array('nomVille'=>$groupement));
  2501.             if($objetZoneProducteur == null )
  2502.                 $objetZoneProducteur= new ZoneProducteur(); 
  2503.             $objetZoneProducteur->setProducteur($objetProducteur);
  2504.             if($ville !=0)
  2505.                 $objetZoneProducteur->setVille($objetVille );
  2506.             $objetZoneProducteur->setAbonne($objetProducteur->getAbonne());
  2507.             $em->persist($objetZoneProducteur);    
  2508.             $em->flush($objetZoneProducteur);
  2509.                     
  2510.  
  2511.     }
  2512.     protected function getInfoProduit($int) {
  2513.         
  2514.         if($int ==){
  2515.             $info "Montant";
  2516.         }else if($int ==2){
  2517.             $info "Nbre";
  2518.         }else{
  2519.             $info "Liquidité";
  2520.         }
  2521.         return $info;
  2522.     }
  2523.     protected function getInfoService($int) {
  2524.         
  2525.         if($int ==){
  2526.             $info "Dépot";
  2527.         }else if($int ==2){
  2528.             $info "Retrait";
  2529.         }else if($int ==3){
  2530.             $info "Commision";
  2531.         }else if($int ==3){
  2532.             $info "Liquidité";
  2533.         }else if($int ==3){
  2534.             $info "S.virtuel";
  2535.         }else{
  2536.             $info "Approvisionnement";  
  2537.         }
  2538.         return $info;
  2539.     }
  2540.     protected function getRealCell($nombre){
  2541.         $nombreDebut 65;
  2542.         if($nombre<=90){
  2543.             return chr($nombre);
  2544.         }else{
  2545.             $reste $nombre%91;
  2546.             //var_dump("nombre = ".$nombre, "reste = ".$reste );
  2547.             
  2548.             if($reste%26 == 0){
  2549.                 ++$nombreDebut;
  2550.                 $reste 0;
  2551.             }
  2552.             if($reste>26)
  2553.                 $reste =$reste%27;
  2554.             
  2555.             
  2556.             $nombreSuivant 65+$reste;
  2557.             //var_dump("nombre = ".$nombre, "reste = ".$reste , "SUivant = ".$nombreSuivant);
  2558.             return chr($nombreDebut).chr($nombreSuivant);
  2559.         }
  2560.     }
  2561.     protected function afficherVenteProduit($donneeProduit$i){
  2562.        
  2563.         if($i==1){
  2564.            $result =  $donneeProduit[0]['quantiteTotal'];
  2565.         }else if($i==2) {
  2566.             $result =  $donneeProduit[0]['montantTotal'];
  2567.         }else if($i==3) {
  2568.             $result =  "-";
  2569.         }
  2570.         return $result;
  2571.     }
  2572.     protected function afficherVenteService($donneeProduit$i){
  2573.     
  2574.        // var_dump();exit;
  2575.        if($donneeProduit !=null){
  2576.         if($i==1){
  2577.             $result =  $donneeProduit[0]['soldedebit'];
  2578.          }else if($i==2) {
  2579.              $result =  $donneeProduit[0]['soldecredit'] ;
  2580.          }else if($i==3) {
  2581.              $result =  "-";
  2582.          }
  2583.          else  {
  2584.              $result =  "-";
  2585.          }
  2586.          return $result;;
  2587.        }
  2588.         
  2589.     }
  2590.     protected function saveGroupement($em$groupement$objetAbonne,$groupementRepositroy$objetZoneAbonne){
  2591.         $criteriaGroupe = array('nomGroupement' => $groupement'abonne' => $objetAbonne);
  2592.         $objetGroupement $groupementRepositroy->findOneBy($criteriaGroupe);
  2593.         if($objetGroupement ==null){
  2594.             $objetGroupement = new Groupement();
  2595.         }
  2596.         $objetGroupement->setNomGroupement($groupement);
  2597.         $objetGroupement->setAbonne($objetAbonne);
  2598.         $objetGroupement->setVille($objetZoneAbonne);
  2599.         $em->persist($objetGroupement);
  2600.         $em->flush();
  2601.     }
  2602.     protected function saveZoneAbonne($em$villeProducteur$objetAbonne$villeRepositroy){
  2603.         $criteriaSup = array('nomVille' => $villeProducteur);
  2604.         $objetVille $villeRepositroy->findOneBy($criteriaSup);
  2605.         if ($objetVille  == null) {
  2606.             $objetVille = new Ville();
  2607.             $objetVille->setNomVille($villeProducteur);
  2608.             //$objetVille->setVille($villeZone);
  2609.             $objetVille->setPays($em->getRepository($this->stockBundle 'Pays')->find(1));
  2610.             $objetVille->setTypeVille(7);
  2611.             $em->persist($objetVille);
  2612.         }
  2613.          
  2614.         $objetZoneAbonne = new AbonneVille();
  2615.         $objetZoneAbonne->setVille($objetVille);
  2616.         $objetZoneAbonne->setAbonne($objetAbonne);
  2617.         $objetZoneAbonne->setTypeAbonneVille(5);
  2618.         $em->persist($objetZoneAbonne);
  2619.         $em->flush();
  2620.         return  $objetVille;
  2621.     }
  2622.     protected function saveZone($em$objetPage$objetGroupement,$objetAbonne){
  2623.         //faire une boucle sur les pages que recevoir les zones
  2624.         $criteriaSup = array('page' => $objetPage,'groupement'=>$objetGroupement);
  2625.         $objetZoneGroupement $em->getRepository($this->cmsBundle 'ZoneGroupement')->findOneBy($criteriaSup);
  2626.         foreach ($objetPage->getZones() as $objetZone) {
  2627.             $objetNZone = new \Entity\cms\ZoneGroupement();   
  2628.             $objetNZone->setTitreZone($objetZone->getTitreZone());
  2629.             $objetNZone->setDescriptionZone($objetZone->getDescriptionZone());
  2630.             $objetNZone->setEtatZone($objetZone->getEtatZone());
  2631.             $objetNZone->setTypeElement($objetZone->getTypeElement());
  2632.             if($objetZone->getTypeElement()== 2){
  2633.                 $uneRubrique $this->saveRubrique($em$objetAbonne$objetZone->getPointeVers());
  2634.                 $objetNZone->setPointeVers($uneRubrique->getId());
  2635.             }
  2636.             if($objetZone->getTypeElement()== 1){
  2637.                 $unArticle $this->saveArticle($em$objetAbonne$objetZone->getPointeVers());
  2638.                 $objetNZone->setPointeVers($unArticle->getId());
  2639.             }
  2640.            // $objetNZone->setSiSysteme($objetZone->getSiSysteme());
  2641.             $objetNZone->setTypeAffichage($objetZone->getTypeAffichage());
  2642.             $objetNZone->setStyle($objetZone->getStyle());
  2643.             $objetNZone->setAbonne($objetAbonne);
  2644.             $objetNZone->setPage($objetPage);
  2645.             $objetNZone->setGroupement($objetGroupement);
  2646.             $objetNZone->setDateAjoutZone($objetZone->getDateAjoutZone());
  2647.             $em->persist($objetNZone);
  2648.             $em->flush();
  2649.         }
  2650.         
  2651.     }
  2652.     protected function saveRubrique($em$objetAbonne$id){
  2653.         //faire une boucle sur les pages que recevoir les zones
  2654.         $objetCurrentRubrique$em->getRepository($this->cmsBundle 'Rubrique')->find($id);
  2655.         $objetRubrique = new \Entity\cms\Rubrique();   
  2656.         $objetRubrique->setDesignationRubrique($objetCurrentRubrique->getDesignationRubrique());
  2657.         $objetRubrique->setDescriptionRubrique($objetCurrentRubrique->getDescriptionRubrique());
  2658.         $objetRubrique->setAbonne($objetAbonne);
  2659.         $em->persist($objetRubrique);
  2660.         $em->flush(); 
  2661.         return $objetRubrique;
  2662.             
  2663.     }
  2664.     protected function saveArticle($em$objetAbonne$id){
  2665.         //faire une boucle sur les pages que recevoir les zones
  2666.         
  2667.         $objetCurrentArticle$em->getRepository($this->cmsBundle 'Article')->find($id);
  2668.         $objetRubrique $this->saveRubrique($em$objetAbonne$objetCurrentArticle->getRubrique()->getId());
  2669.         $objetArticle = new \Entity\cms\Article();  
  2670.         $objetArticle->setRubrique($objetRubrique);
  2671.         $objetArticle->setTitre($objetCurrentArticle->getTitre());
  2672.         $objetArticle->setContenuArticle($objetCurrentArticle->getContenuArticle());
  2673.         $objetArticle->setResumeArticle($objetCurrentArticle->getResumeArticle());
  2674.         $objetArticle->setTypeArticle($objetCurrentArticle->getTypeArticle());
  2675.         $objetArticle->setAbonne($objetAbonne);
  2676.         $em->persist($objetArticle);
  2677.         $em->flush(); 
  2678.         return $objetArticle;
  2679.             
  2680.     }
  2681.       
  2682.   
  2683.     public function getStatInspectionAction(EntityManager $em,$abonneId$inspectionId$mois$siListe=0) {
  2684.         try {
  2685.             $dateTime = new \DateTime();
  2686.             if($siListe==0)
  2687.                 $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 ';
  2688.             else
  2689.                 $sqlrech 'SELECT Count(ri.id) as total ';
  2690.             
  2691.             $sqlrech .= '
  2692.                             FROM  inspection_rempli ir
  2693.                             INNER JOIN inspection i on i.id = ir.inspection_id
  2694.                             INNER JOIN producteur p  on ir.producteur_id  = p.id
  2695.                             INNER JOIN utilisateur u on p.utilisateur_id = u.id
  2696.                             WHERE i.abonne_id =:abonneId AND YEAR(ir.date_enregistrement) =:annee  
  2697.                             AND i.id =:inspectionId AND MONTH(ir.date_enregistrement)=:mois
  2698.                             GROUP BY i.id, MONTH(ir.date_enregistrement) '//
  2699.            
  2700.             $stmt $em->getConnection()->prepare($sqlrech);
  2701.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  2702.             $stmt->bindValue(':annee'$dateTime->format('Y'), PDO::PARAM_STR);
  2703.             $stmt->bindValue(':inspectionId'$inspectionIdPDO::PARAM_INT);
  2704.             $stmt->bindValue(':mois'$moisPDO::PARAM_INT);
  2705.             
  2706.             $stmt->execute();
  2707.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  2708.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2709.             $stmt null;
  2710.             $res null;
  2711.             var_dump($e->getMessage());
  2712.         }
  2713.         return $res;
  2714.     }
  2715.     public function getStatInspectionByAgentAction(EntityManager $em,$abonneId$agentId$inspectionId) {
  2716.         try {
  2717.             $dateTime = new \DateTime();
  2718.             $sqlrech 'SELECT Count(ir.id) as total
  2719.                             FROM  inspection_rempli ir
  2720.                             INNER JOIN inspection i on i.id = ir.inspection_id
  2721.                             INNER JOIN utilisateur u on u.id = ir.utilisateur_id
  2722.                             WHERE i.abonne_id =:abonneId AND u.id =:agentId  
  2723.                             AND i.id =:inspectionId  AND ir.etat_fournisseur_producteur =:etat
  2724.                             GROUP BY u.id '//
  2725.            
  2726.             $stmt $em->getConnection()->prepare($sqlrech);
  2727.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  2728.             $stmt->bindValue(':agentId'$agentIdPDO::PARAM_INT);
  2729.             $stmt->bindValue(':inspectionId'$inspectionIdPDO::PARAM_INT);
  2730.             $stmt->bindValue(':etat'1PDO::PARAM_INT);
  2731.            
  2732.             
  2733.             $stmt->execute();
  2734.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  2735.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2736.             $stmt null;
  2737.             $res null;
  2738.             var_dump($e->getMessage());
  2739.         }
  2740.         return $res;
  2741.     }
  2742.     public function getAchatVarieteAction(EntityManager $em,$abonneId$produitId) {
  2743.         try {
  2744.             $dateTime = new \DateTime();
  2745.             $sqlrech 'SELECT Count(lc.quantite) as quantiteTotal
  2746.             
  2747.                             FROM  commande c
  2748.                             INNER JOIN lignecommande lc on lc.commande_id = c.id
  2749.                             INNER JOIN produit_abonne pa on lc.produitabonne_id  = pa.id
  2750.                             INNER JOIN produit p on pa.produit_id = p.id
  2751.                             INNER JOIN abonne a on pa.abonne_id = a.id
  2752.                             
  2753.                             WHERE a.id =:abonneId AND YEAR(c.date_commande) =:annee  AND p.id =:produitId 
  2754.                             GROUP BY p.nom_produit, MONTH(c.date_commande) '//
  2755.            
  2756.             $stmt $em->getConnection()->prepare($sqlrech);
  2757.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  2758.             $stmt->bindValue(':annee'$dateTime->format('Y'), PDO::PARAM_STR);
  2759.             $stmt->bindValue(':produitId'$produitIdPDO::PARAM_INT);
  2760.             
  2761.             $stmt->execute();
  2762.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  2763.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2764.             $stmt null;
  2765.             $res null;
  2766.             var_dump($e->getMessage());
  2767.         }
  2768.         return $res;
  2769.     }
  2770.     public function getAchatMoisAction(EntityManager $em,$abonneId) {
  2771.         try {
  2772.             $dateTime = new \DateTime();
  2773.             $sqlrech 'SELECT DISTINCT( MONTH(c.date_commande)) as mois
  2774.             
  2775.                             FROM  commande c
  2776.                             INNER JOIN lignecommande lc on lc.commande_id = c.id
  2777.                             INNER JOIN produit_abonne pa on lc.produitabonne_id  = pa.id
  2778.                             INNER JOIN produit p on pa.produit_id = p.id
  2779.                             INNER JOIN abonne a on pa.abonne_id = a.id
  2780.                             
  2781.                             WHERE a.id =:abonneId AND YEAR(c.date_commande) =:annee 
  2782.                             GROUP BY p.nom_produit, MONTH(c.date_commande) '//
  2783.            
  2784.             $stmt $em->getConnection()->prepare($sqlrech);
  2785.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  2786.             $stmt->bindValue(':annee'$dateTime->format('Y'), PDO::PARAM_STR);
  2787.             
  2788.             $stmt->execute();
  2789.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  2790.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2791.             $stmt null;
  2792.             $res null;
  2793.             var_dump($e->getMessage());
  2794.         }
  2795.         return $res;
  2796.     }
  2797.     public function getStatProducteurGroupementAction(EntityManager $em,$abonneId$groupementId) {
  2798.         try {
  2799.             $sqlrech 'SELECT Count(g.id) as total
  2800.                             FROM  groupement g
  2801.                             INNER JOIN producteur_groupement gp on gp.groupement_id = g.id
  2802.                             INNER JOIN producteur p on gp.producteur_id = p.id
  2803.                             INNER JOIN producteur_abonne pa on pa.producteur_id  = p.id
  2804.                             INNER JOIN abonne a on pa.abonne_id  = a.id
  2805.                             WHERE a.id =:abonneId  AND g.id =:groupementId 
  2806.                             GROUP BY g.id
  2807.                         '
  2808.             $stmt $em->getConnection()->prepare($sqlrech);
  2809.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  2810.             $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  2811.             $stmt->execute();
  2812.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  2813.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2814.             $stmt null;
  2815.             $res null;
  2816.             var_dump($e->getMessage());
  2817.         }
  2818.         return $res;
  2819.     }
  2820.     public function getStatProducteurEntity(EntityManager $em,$abonneId$entityId$siGroupement$partenaireId=0$typeAction=0$tabProduit=0) {
  2821.         try {
  2822.             $sqlrech 'SELECT COUNT(DISTINCT(p.id)) as total ' ;
  2823.             if($siGroupement == 1){
  2824.                 $sqlrech .= '
  2825.                             FROM  groupement g ';
  2826.                 $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.groupement_id = g.id
  2827.                                 INNER JOIN producteur p on gp.producteur_id = p.id' ;
  2828.             }else{
  2829.                 $sqlrech .= '
  2830.                             FROM  ville v ' ;
  2831.                 $sqlrech .= '   INNER JOIN zone_producteur zp on zp.ville_id = v.id
  2832.                                 INNER JOIN producteur p on zp.producteur_id = p.id' ;
  2833.             }
  2834.             
  2835.             if($typeAction != 0){
  2836.                 $sqlrech .= '   INNER JOIN producteur_abonne pa on pa.producteur_id  = p.id
  2837.                                 INNER JOIN abonne a on pa.abonne_id  = a.id
  2838.                             '
  2839.                 if($typeAction == &&  $partenaireId != 0)
  2840.                     $sqlrech .= " INNER JOIN partenaire pt  on pa.partenaire_id = pt.id ";
  2841.             }else{
  2842.                 $sqlrech .= " INNER JOIN abonne a on p.abonne_id  = a.id ";
  2843.                 
  2844.             }
  2845.             if($tabProduit != 0){
  2846.                 $sqlrech .= "  INNER JOIN surface_annee sa on sa.producteur_id  = p.id 
  2847.                                INNER JOIN produit prod on prod.id = sa.produit_id ";
  2848.             }
  2849.             if($siGroupement == 1)
  2850.                 $sqlrech .= '   WHERE a.id =:abonneId  AND g.id =:entityId  AND p.etat_prod = 1'
  2851.             else
  2852.                 $sqlrech .= '   WHERE a.id =:abonneId  AND v.id =:entityId AND p.etat_prod = 1 '
  2853.             $i 0;
  2854.             if($tabProduit !=&& count($tabProduit)!=0){         
  2855.                 // if($prod != 1){
  2856.                 $i=0;
  2857.                 foreach($tabProduit as $unProduitId){
  2858.                     if($i == 0){
  2859.                         $sqlrech .= " AND ( prod.id = :produit".$unProduitId."";
  2860.                     //var_dump($uneVille->getId());
  2861.                     }else{
  2862.                         $sqlrech .= " OR prod.id= :produit".$unProduitId."";
  2863.                     }
  2864.                     $i++;
  2865.                 //$tabProduitUser[] = $unInfoProduit->getId();            
  2866.                 }    
  2867.                 $sqlrech .= " ) ";
  2868.             }
  2869.             
  2870.             if($siGroupement == 1)
  2871.                 $sqlrech .= ' GROUP BY g.id ';  
  2872.             else
  2873.                 $sqlrech .= ' GROUP BY v.id '
  2874.             
  2875.             
  2876.             //var_dump( $sqlrech , $abonneId, $entityId);exit;
  2877.             $stmt $em->getConnection()->prepare($sqlrech);
  2878.             if($tabProduit !=0){    
  2879.                 foreach($tabProduit as $unProduitId){
  2880.                     $stmt->bindValue(":produit".$unProduitId.""$unProduitIdPDO::PARAM_INT);            
  2881.                 }
  2882.             }
  2883.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  2884.             $stmt->bindValue(':entityId'$entityIdPDO::PARAM_INT);
  2885.             $stmt->execute();
  2886.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  2887.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2888.             $stmt null;
  2889.             $res null;
  2890.             var_dump($e->getMessage());
  2891.         }
  2892.         return $res;
  2893.     }
  2894.     public function getCountStatSurfaceEntity(EntityManager $em,$abonneId$entityId$siGroupement$partenaireId=0$typeAction=0$tabProduit=0) {
  2895.         try {
  2896.             $sqlrech 'SELECT Count(DISTINCT(sa.id)) as nombreTotal ' ;
  2897.             if($siGroupement == 1){
  2898.                 $sqlrech .= '
  2899.                             FROM  groupement g ';
  2900.                 $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.groupement_id = g.id
  2901.                                 INNER JOIN producteur p on gp.producteur_id = p.id' ;
  2902.             }else{
  2903.                 $sqlrech .= '
  2904.                             FROM  ville v ' ;
  2905.                 $sqlrech .= '   INNER JOIN zone_producteur zp on zp.ville_id = v.id
  2906.                                 INNER JOIN producteur p on zp.producteur_id = p.id' ;
  2907.             }
  2908.             $sqlrech .= '   INNER JOIN surface_annee sa on sa.producteur_id  = p.id '
  2909.            
  2910.             if($typeAction != 0){
  2911.                 $sqlrech .= '   INNER JOIN producteur_abonne pa on pa.producteur_id  = p.id
  2912.                                 INNER JOIN abonne a on pa.abonne_id  = a.id '
  2913.                 if($typeAction == &&  $partenaireId != 0)
  2914.                     $sqlrech .= " INNER JOIN partenaire pt  on pa.partenaire_id = pt.id ";
  2915.             }else{
  2916.                 $sqlrech .= " INNER JOIN abonne a on p.abonne_id  = a.id ";
  2917.                 
  2918.             }
  2919.             if($tabProduit != 0){
  2920.                 $sqlrech .= "INNER JOIN produit prod on prod.id = sa.produit_id  ";
  2921.             }
  2922.             if($siGroupement == 1)
  2923.                 $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'
  2924.             else
  2925.                 $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'
  2926.             
  2927.             
  2928.             $i 0;
  2929.             if($tabProduit !=&& count($tabProduit)!=0){         
  2930.                 // if($prod != 1){
  2931.                 $i=0;
  2932.                 foreach($tabProduit as $unProduitId){
  2933.                     if($i == 0){
  2934.                         $sqlrech .= " AND ( prod.id = :produit".$unProduitId."";
  2935.                     //var_dump($uneVille->getId());
  2936.                     }else{
  2937.                         $sqlrech .= " OR prod.id= :produit".$unProduitId."";
  2938.                     }
  2939.                     $i++;
  2940.                 //$tabProduitUser[] = $unInfoProduit->getId();            
  2941.                 }    
  2942.                 $sqlrech .= " ) ";
  2943.             }
  2944.             
  2945.             if($siGroupement == 1)
  2946.                 $sqlrech .= ' GROUP BY g.id ';  
  2947.             else
  2948.                 $sqlrech .= ' GROUP BY v.id ';  
  2949.             $stmt $em->getConnection()->prepare($sqlrech);
  2950.             //if($produitId != 0)
  2951.                 //$stmt->bindValue(':produitId', $produitId, PDO::PARAM_INT);
  2952.             if($tabProduit !=0){    
  2953.                 foreach($tabProduit as $unProduitId){
  2954.                     $stmt->bindValue(":produit".$unProduitId.""$unProduitIdPDO::PARAM_INT);            
  2955.                 }
  2956.             }
  2957.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  2958.             $stmt->bindValue(':entityId'$entityIdPDO::PARAM_INT);
  2959.             $stmt->execute();
  2960.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  2961.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  2962.             $stmt null;
  2963.             $res null;
  2964.             var_dump($e->getMessage());
  2965.         }
  2966.         return $res;
  2967.     }
  2968.     public function getSumStatSurfaceEntity(EntityManager $em,$abonneId$entityId$siGroupement$partenaireId=0$typeAction=0$tabProduit=0) {
  2969.         try {
  2970.             $sqlrech 'SELECT CAST(SUM(sa.superficie) AS DECIMAL(10,2)) as surperficieTotal, CAST(SUM(sa.superficie_reelle) AS DECIMAL(10,2)) as surperficieTotalReelle  ' ;
  2971.             if($siGroupement == 1){
  2972.                 $sqlrech .= ' FROM  groupement g ';
  2973.                 $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.groupement_id = g.id
  2974.                                 INNER JOIN producteur p on gp.producteur_id = p.id' ;
  2975.             }else{
  2976.                 $sqlrech .= ' FROM  ville v ' ;
  2977.                 $sqlrech .= '   INNER JOIN zone_producteur zp on zp.ville_id = v.id
  2978.                                 INNER JOIN producteur p on zp.producteur_id = p.id' ;
  2979.             }
  2980.             $sqlrech .= '   INNER JOIN surface_annee sa on sa.producteur_id  = p.id '
  2981.             if($tabProduit != 0){
  2982.                 $sqlrech .= "  INNER JOIN produit prod on prod.id = sa.produit_id ";
  2983.             }
  2984.             if($typeAction != 0){
  2985.                 $sqlrech .= '   INNER JOIN producteur_abonne pa on pa.producteur_id  = p.id
  2986.                                 INNER JOIN abonne a on pa.abonne_id  = a.id
  2987.                             '
  2988.                 if($typeAction == &&  $partenaireId != 0)
  2989.                     $sqlrech .= " INNER JOIN partenaire pt  on pa.partenaire_id = pt.id ";
  2990.             }else{
  2991.                 $sqlrech .= " INNER JOIN abonne a on p.abonne_id  = a.id";
  2992.                 
  2993.             }
  2994.             if($siGroupement == 1)
  2995.                 $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'
  2996.             else
  2997.                 $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'
  2998.             
  2999.             if($tabProduit !=&& count($tabProduit)!=0){         
  3000.                 // if($prod != 1){
  3001.                 $i=0;
  3002.                 foreach($tabProduit as $unProduitId){
  3003.                     if($i == 0){
  3004.                         $sqlrech .= " AND ( prod.id = :produit".$unProduitId."";
  3005.                     //var_dump($uneVille->getId());
  3006.                     }else{
  3007.                         $sqlrech .= " OR prod.id= :produit".$unProduitId."";
  3008.                     }
  3009.                     $i++;
  3010.                 //$tabProduitUser[] = $unInfoProduit->getId();            
  3011.                 }    
  3012.                 $sqlrech .= " ) ";
  3013.             }
  3014.             if($siGroupement == 1)
  3015.                 $sqlrech .= ' GROUP BY g.id ';  
  3016.             else
  3017.                 $sqlrech .= ' GROUP BY v.id '
  3018.            // if($siGroupement == 2)
  3019.                 //var_dump($sqlrech);exit;
  3020.             $stmt $em->getConnection()->prepare($sqlrech);
  3021.             if($tabProduit !=0){    
  3022.                 foreach($tabProduit as $unProduitId){
  3023.                     $stmt->bindValue(":produit".$unProduitId.""$unProduitIdPDO::PARAM_INT);            
  3024.                 }
  3025.             }
  3026.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  3027.             $stmt->bindValue(':entityId'$entityIdPDO::PARAM_INT);
  3028.             $stmt->execute();
  3029.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  3030.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3031.             $stmt null;
  3032.             $res null;
  3033.             var_dump($e->getMessage());
  3034.         }
  3035.         return $res;
  3036.     }
  3037.     public function getStatStockGroupementAction(EntityManager $em,$abonneId$groupementId) {
  3038.         try {
  3039.             $sqlrech 'SELECT Count(g.id) as total
  3040.                             FROM lignecommande lc
  3041.                             INNER JOIN livrer l on l.lignecommande_id = lc.id
  3042.                             INNER JOIN  info_livrer il on il.id = l.infolivrer_id
  3043.                             INNER JOIN producteur p on lc.producteur_id = p.id
  3044.                             INNER JOIN producteur_groupement gp on gp.groupement_id = p.id
  3045.                             LEFT JOIN groupement g on gp.groupement_id = g.id
  3046.                             INNER JOIN producteur_abonne pa on pa.producteur_id  = p.id
  3047.                             INNER JOIN abonne a on pa.abonne_id  = a.id
  3048.                             WHERE a.id =:abonneId  AND g.id =:groupementId 
  3049.                             GROUP BY g.id
  3050.                         ' ;         
  3051.             $stmt $em->getConnection()->prepare($sqlrech);
  3052.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  3053.             $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  3054.             $stmt->execute();
  3055.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  3056.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3057.             $stmt null;
  3058.             $res null;
  3059.             var_dump($e->getMessage());
  3060.         }
  3061.         return $res;
  3062.     }
  3063.     public function getStatProducteurZoneAction(EntityManager $em,$abonneId$groupementId) {
  3064.         
  3065.             try {
  3066.                 $sqlrech 'SELECT Count(g.id) as total
  3067.                                 FROM  groupement g
  3068.                                 INNER JOIN producteur_groupement gp on gp.groupement_id = g.id
  3069.                                 INNER JOIN producteur p on gp.producteur_id = p.id
  3070.                                 INNER JOIN producteur_abonne pa on pa.producteur_id  = p.id
  3071.                                 INNER JOIN abonne a on pa.abonne_id  = a.id
  3072.                                 WHERE a.id =:abonneId  AND g.id =:groupementId 
  3073.                                 GROUP BY g.id
  3074.                             '
  3075.                 $stmt $em->getConnection()->prepare($sqlrech);
  3076.                 $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  3077.                 $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  3078.                 $stmt->execute();
  3079.                 $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  3080.             } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3081.                 $stmt null;
  3082.                 $res null;
  3083.                 var_dump($e->getMessage());
  3084.             }
  3085.             return $res;
  3086.     }
  3087.    
  3088.     public function getStatStockParcelleAction(EntityManager $em,$abonneId$groupementId$zoneId) {
  3089.         try {
  3090.             $sqlrech 'SELECT Count(sa.id) as total
  3091.                             FROM surface_annee sa
  3092.                             INNER JOIN produit p on sa.produit_id = p.id
  3093.                             INNER JOIN produit_abonne pa on pa.produit_id  = p.id
  3094.                             INNER JOIN abonne a on pa.abonne_id  = a.id
  3095.                             WHERE a.id =:abonneId  
  3096.                             GROUP BY p.id
  3097.                         ' ;         
  3098.             $stmt $em->getConnection()->prepare($sqlrech);
  3099.             $stmt->bindValue(':abonneId'$abonneIdPDO::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 getStatGeolocalisationAction(EntityManager $em,$abonneId$groupementId$zoneId$siP=0$partenaireId=0$typeAction=0$siListe=0) {
  3110.         try {
  3111.             if($siListe==0)
  3112.                 $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';
  3113.             else
  3114.                 $sqlrech 'SELECT Count(sa.id) as total ';
  3115.             $sqlrech .= '
  3116.                             FROM surface_annee sa
  3117.                             INNER JOIN produit pr on sa.produit_id = pr.id
  3118.                              ';
  3119.                 if($groupementId != || $zoneId !=0)
  3120.                     $sqlrech .= " INNER JOIN producteur p  on sa.producteur_id  = p.id
  3121.                                   INNER JOIN utilisateur u on p.utilisateur_id = u.id
  3122.                 ";
  3123.                 if($groupementId != 0){
  3124.                     $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.producteur_id = p.id
  3125.                                     INNER JOIN groupement g on gp.groupement_id = g.id' ;
  3126.                 }
  3127.                 if($zoneId != 0){
  3128.                     $sqlrech .= '   INNER JOIN zone_producteur zp on zp.producteur_id = p.id
  3129.                                     INNER JOIN ville v on zp.ville_id = v.id' ;
  3130.                 }
  3131.                 if($typeAction != 0){
  3132.                     $sqlrech .= " INNER JOIN surface_abonne sab on sab.surfaceannee_id  = sa.id ";
  3133.                     $sqlrech .= " INNER JOIN abonne a on sab.abonne_id =  a.id ";
  3134.                     if($typeAction == &&  $partenaireId != 0)
  3135.                         $sqlrech .= " INNER JOIN partenaire pt on sab.partenaire_id = pt.id ";
  3136.                 }else{
  3137.                     $sqlrech .= " INNER JOIN abonne a on sa.abonne_id  = a.id";
  3138.                 }
  3139.                 $sqlrech .= " WHERE a.id =:abonneId  AND sa.id ";
  3140.                 if($siP==0)
  3141.                     $sqlrech .= ' IN';
  3142.                 else
  3143.                     $sqlrech .= ' NOT IN';
  3144.                 $sqlrech .= '     (
  3145.                         SELECT DISTINCT(surfaceannee_id) FROM localisation WHERE 1=1 and type_localisation = 1
  3146.                     ) 
  3147.                     
  3148.                 ' ;         
  3149.                 if($typeAction == &&  $partenaireId != 0)
  3150.                     $sqlrech .= " AND  pt.id =:partenaireId  ";
  3151.                 if($groupementId != )
  3152.                     $sqlrech .= " AND  g.id =:groupementId  ";
  3153.                 if($zoneId != )
  3154.                     $sqlrech .= " AND  v.id =:zoneId  ";
  3155.                     //var_dump($sqlrech);exit;
  3156.                 //INNER JOIN produit_abonne pa on pa.produit_id  = p.id
  3157.                 $stmt $em->getConnection()->prepare($sqlrech);
  3158.                 if($typeAction == &&  $partenaireId != 0)
  3159.                     $stmt->bindValue(':partenaireId'$partenaireIdPDO::PARAM_INT);
  3160.                 
  3161.                 if($groupementId != )
  3162.                     $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  3163.                 if($zoneId != )
  3164.                     $stmt->bindValue(':zoneId'$zoneIdPDO::PARAM_INT);
  3165.                 if($typeAction == || $typeAction == 1)
  3166.                     $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  3167.             $stmt->execute();
  3168.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  3169.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3170.             $stmt null;
  3171.             $res null;
  3172.             var_dump($e->getMessage());
  3173.         }
  3174.         return $res;
  3175.     }
  3176.     public function getStatPolygonAction(EntityManager $em,$abonneId$groupementId$zoneId$siP=0$partenaireId=0$typeAction=0$siListe=0) {
  3177.         
  3178.         try {
  3179.             if($siListe==0)
  3180.                 $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';
  3181.             else
  3182.                 $sqlrech 'SELECT Count(sa.id) as total ';
  3183.             $sqlrech .= '
  3184.                             FROM surface_annee sa
  3185.                             INNER JOIN produit pr on sa.produit_id = pr.id
  3186.                              ';
  3187.                 if($groupementId != || $zoneId !=0)
  3188.                     $sqlrech .= " INNER JOIN producteur p  on sa.producteur_id  = p.id
  3189.                                   INNER JOIN utilisateur u on p.utilisateur_id = u.id ";
  3190.                 if($groupementId != 0){
  3191.                     $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.producteur_id = p.id
  3192.                                     INNER JOIN groupement g on gp.groupement_id = g.id' ;
  3193.                 }
  3194.                 if($zoneId != 0){
  3195.                     $sqlrech .= '   INNER JOIN zone_producteur zp on zp.producteur_id = p.id
  3196.                                     INNER JOIN ville v on zp.ville_id = v.id' ;
  3197.                 }
  3198.                 if($typeAction != 0){
  3199.                     $sqlrech .= " INNER JOIN surface_abonne sab on sab.surfaceannee_id  = sa.id ";
  3200.                     $sqlrech .= " INNER JOIN abonne a on sab.abonne_id =  a.id ";
  3201.                     if($typeAction == &&  $partenaireId != 0)
  3202.                         $sqlrech .= " INNER JOIN partenaire pt on sab.partenaire_id = pt.id ";
  3203.                 }else{
  3204.                     $sqlrech .= " INNER JOIN abonne a on sa.abonne_id  = a.id";
  3205.                 }
  3206.                 $sqlrech .= " WHERE a.id =:abonneId  AND sa.id ";
  3207.                 if($siP==0)
  3208.                     $sqlrech .= ' IN';
  3209.                 else
  3210.                     $sqlrech .= ' NOT IN';
  3211.                 $sqlrech .= '     (
  3212.                         SELECT DISTINCT(surfaceannee_id) FROM localisation WHERE 1=1 and type_localisation = 1 and     tab_polygone is null
  3213.                     )   
  3214.                 ' ;         
  3215.                 if($typeAction == &&  $partenaireId != 0)
  3216.                     $sqlrech .= " AND  pt.id =:partenaireId  ";
  3217.                 if($groupementId != )
  3218.                     $sqlrech .= " AND  g.id =:groupementId  ";
  3219.                 if($zoneId != )
  3220.                     $sqlrech .= " AND  v.id =:zoneId  ";
  3221.                     //var_dump($sqlrech);exit;
  3222.                 //INNER JOIN produit_abonne pa on pa.produit_id  = p.id
  3223.                 $stmt $em->getConnection()->prepare($sqlrech);
  3224.                 if($typeAction == &&  $partenaireId != 0)
  3225.                     $stmt->bindValue(':partenaireId'$partenaireIdPDO::PARAM_INT);
  3226.                 
  3227.                 if($groupementId != )
  3228.                     $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  3229.                 if($zoneId != )
  3230.                     $stmt->bindValue(':zoneId'$zoneIdPDO::PARAM_INT);
  3231.                 if($typeAction == || $typeAction == 1)
  3232.                     $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  3233.             $stmt->execute();
  3234.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  3235.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3236.             $stmt null;
  3237.             $res null;
  3238.             var_dump($e->getMessage());
  3239.         }
  3240.         return $res;
  3241.     }
  3242.     public function getStatGeolocalisationTotalAction(EntityManager $em,$abonneId$groupementId$zoneId$siP=0$partenaireId=0$typeAction=0) {
  3243.         try {
  3244.             $sqlrech 'SELECT Count(sa.id) as total
  3245.                             FROM surface_annee sa
  3246.                             INNER JOIN produit pr on sa.produit_id = pr.id
  3247.                             
  3248.                              ';
  3249.                 if($groupementId != || $zoneId !=0)
  3250.                 $sqlrech .= " INNER JOIN producteur p  on sa.producteur_id  = p.id";
  3251.                 if($groupementId != 0){
  3252.                     $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.producteur_id = p.id
  3253.                                     INNER JOIN groupement g on gp.groupement_id = g.id' ;
  3254.                 }
  3255.                 if($zoneId != 0){
  3256.                     $sqlrech .= '   INNER JOIN zone_producteur zp on zp.producteur_id = p.id
  3257.                                     INNER JOIN ville v on zp.ville_id = v.id' ;
  3258.                 }
  3259.                     if($typeAction != 0){
  3260.                         $sqlrech .= " INNER JOIN surface_abonne sab on sab.surfaceannee_id  = sa.id ";
  3261.                         $sqlrech .= " INNER JOIN abonne a on  sab.abonne_id =  a.id ";
  3262.                         if($typeAction == &&  $partenaireId != 0)
  3263.                             $sqlrech .= " INNER JOIN partenaire pt on sab.partenaire_id = pt.id ";
  3264.                     }else{
  3265.                         $sqlrech .= " INNER JOIN abonne a on sa.abonne_id  = a.id";
  3266.                     }
  3267.             /*if($siP==0)
  3268.                 $sqlrech .= ' IN';
  3269.             else
  3270.                 $sqlrech .= ' NOT IN';
  3271.             $sqlrech .= '     (
  3272.                     SELECT DISTINCT(surfaceannee_id) FROM localisation WHERE 1=1 and type_localisation = 1
  3273.                 ) 
  3274.                 
  3275.             ' ; */       
  3276.             $sqlrech .= " WHERE a.id =:abonneId  ";
  3277.             if($typeAction == &&  $partenaireId != 0)
  3278.                 $sqlrech .= " AND  pt.id =:partenaireId  ";
  3279.                 
  3280.             if($groupementId != )
  3281.                 $sqlrech .= " AND  g.id =:groupementId  ";
  3282.             if($zoneId != )
  3283.                 $sqlrech .= " AND  v.id =:zoneId  ";
  3284.             //INNER JOIN produit_abonne pa on pa.produit_id  = p.id
  3285.             $stmt $em->getConnection()->prepare($sqlrech);
  3286.             if($typeAction == &&  $partenaireId != 0)
  3287.                 $stmt->bindValue(':partenaireId'$partenaireIdPDO::PARAM_INT);
  3288.             
  3289.             if($groupementId != )
  3290.                 $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  3291.             if($zoneId != )
  3292.                 $stmt->bindValue(':zoneId'$zoneIdPDO::PARAM_INT);
  3293.             
  3294.             if($typeAction == || $typeAction == 1)
  3295.                 $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  3296.             $stmt->execute();
  3297.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  3298.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3299.             $stmt null;
  3300.             $res null;
  3301.             var_dump($e->getMessage());
  3302.         }
  3303.         return $res;
  3304.     }
  3305.     public function getStatInspectionParcelleAction(EntityManager $em,$abonneId$groupementId$zoneId$inspectionId$siP=0$partenaireId=0$typeAction=0$siListe=1) {
  3306.         try {
  3307.             if($siListe==0)
  3308.                 $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';
  3309.             else
  3310.                 $sqlrech 'SELECT Count(sa.id) as total ';
  3311.             $sqlrech .= '
  3312.                             FROM surface_annee sa
  3313.                         '
  3314.                 //if($groupementId != 0 || $zoneId !=0)
  3315.                 $sqlrech .= " INNER JOIN producteur p  on sa.producteur_id  = p.id
  3316.                                 INNER JOIN utilisateur u on p.utilisateur_id = u.id
  3317.                                 ";
  3318.                 if($groupementId != 0){
  3319.                     $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.producteur_id = p.id
  3320.                                     INNER JOIN groupement g on gp.groupement_id = g.id' ;
  3321.                 }
  3322.                 
  3323.                 if($zoneId != 0){
  3324.                     $sqlrech .= '   INNER JOIN zone_producteur zp on zp.producteur_id = p.id
  3325.                                     INNER JOIN ville v on zp.ville_id = v.id' ;
  3326.                 }
  3327.                 if($typeAction != 0){
  3328.                     $sqlrech .= " INNER JOIN surface_abonne sab on sab.surfaceannee_id  = sa.id ";
  3329.                     $sqlrech .= " INNER JOIN abonne a on  sab.abonne_id =  a.id ";
  3330.                     if($typeAction == &&  $partenaireId != 0)
  3331.                         $sqlrech .= " INNER JOIN partenaire pt on sab.partenaire_id = pt.id ";
  3332.                 }else{
  3333.                     $sqlrech .= " INNER JOIN abonne a on sa.abonne_id  = a.id";
  3334.                 }
  3335.             
  3336.                 $sqlrech .= " WHERE a.id =:abonneId  AND sa.id ";
  3337.                 if($siP==0)
  3338.                     $sqlrech .= ' IN';
  3339.                 else
  3340.                     $sqlrech .= ' NOT IN';
  3341.                 $sqlrech .= '     (
  3342.                         SELECT surfaceannee_id FROM inspection_rempli WHERE inspection_id =:inspectionId AND surfaceannee_id is not null
  3343.                     )
  3344.                 ' ;  
  3345.                 if($typeAction == &&  $partenaireId != 0)
  3346.                     $sqlrech .= " AND  pt.id =:partenaireId  ";
  3347.                 
  3348.                 if($groupementId != )
  3349.                     $sqlrech .= " AND  g.id =:groupementId  ";
  3350.                 if($zoneId != )
  3351.                     $sqlrech .= " AND  v.id =:zoneId  ";
  3352.                 //INNER JOIN produit_abonne pa on pa.produit_id  = p.id
  3353.                 $stmt $em->getConnection()->prepare($sqlrech);
  3354.                 
  3355.                 //var_dump($sqlrech, $zoneId);exit;
  3356.                 if($typeAction == &&  $partenaireId != 0)
  3357.                     $stmt->bindValue(':partenaireId'$partenaireIdPDO::PARAM_INT);
  3358.                 if($typeAction == || $typeAction == 1)
  3359.                     $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  3360.                 
  3361.                 if($groupementId != )
  3362.                     $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  3363.                 if($zoneId != )
  3364.                     $stmt->bindValue(':zoneId'$zoneIdPDO::PARAM_INT);
  3365.             
  3366.                 $stmt->bindValue(':inspectionId'$inspectionIdPDO::PARAM_INT);
  3367.                 $stmt->execute();
  3368.                 $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  3369.             } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3370.                 $stmt null;
  3371.                 $res null;
  3372.                 var_dump($e->getMessage());
  3373.             }
  3374.             return $res;
  3375.     }
  3376.     function siVide($value){
  3377.         if($value == "")
  3378.             return "_____________________________";
  3379.         else
  3380.             return $value;
  3381.     }
  3382.     public function genereStockProduitConditionne($em$codeCommande$montant$objetProduit$objetPrix$quantite,$infoLivrerRepository$ligneCommandeRepository$livrerRepository,$objetUtilisateur) {
  3383.         $autoObjetCommande $this->saveCommande($em$codeCommande,  $montantnull$objetUtilisateur);
  3384.         $autoObjetLivraison $this->saveLivraison($em$autoObjetCommandenull,$infoLivrerRepository) ;
  3385.         $this->validateLigneCommandeInterne($em$codeCommande$autoObjetLivraison$autoObjetCommande$objetProduit$objetPrix$quantite0$ligneCommandeRepository$livrerRepository);
  3386.         $this->manageStock($em$objetProduit->getId(),$quantite1);
  3387.     }
  3388.     public function creerTabMenu($em,$idEtabl$abonneIdMenuRepository $menuRepository){
  3389.         $listeMenu $menuRepository->getAllMenuActif($abonneId);
  3390.         $i=0;
  3391.         $tabMenu = array();
  3392.         foreach($listeMenu as $unMenu){
  3393.             $tab explode('|'$unMenu->getContenuMenu());
  3394.             $tabMenu[$i]['lien'] = $tab[0];
  3395.             if(count($tab) >1)
  3396.                 $tabMenu[$i]['id'] = $tab[1];
  3397.             else
  3398.                 $tabMenu[$i]['id'] ="";
  3399.             $tabMenu[$i]['titre'] = $unMenu->getTitre();
  3400.             $tabMenu[$i]['type']  = $unMenu->getTypeMenu();
  3401.             $i++;
  3402.         }
  3403.         return $tabMenu
  3404.     } 
  3405.     public function creerTabMenuReact($em,$idEtabl$abonneIdMenuRepository $menuRepository){
  3406.         $listeMenu $menuRepository->getAllMenuAvecSousMenuActif($abonneId);
  3407.         $i=0;
  3408.         $tabMenu = array();
  3409.         foreach($listeMenu as $unMenu){
  3410.             $tab explode('|'$unMenu->getContenuMenu());
  3411.             $tabMenu[$i]['lien'] = $this->getInfoMenu($tab[0]);
  3412.             if(count($tab) >1)
  3413.                 $tabMenu[$i]['id'] = $tab[1];
  3414.             else
  3415.                 $tabMenu[$i]['id'] ="";
  3416.             $tabMenu[$i]['titre'] = $unMenu->getTitre();
  3417.             $tabMenu[$i]['type']  = $unMenu->getTypeMenu();
  3418.             $sousMenu $menuRepository->getSousAllMenuActif($unMenu->getId());
  3419.             $tabMenu[$i]['sousMenu']  = $this->getMenuForme($sousMenu);
  3420.             $i++;
  3421.         }
  3422.         return $tabMenu
  3423.     } 
  3424.     
  3425.     public function getMenuForme($listeMenu){
  3426.         $i=0;
  3427.         $tabMenu = array();
  3428.         foreach($listeMenu as $unMenu){
  3429.             $tab explode('|'$unMenu->getContenuMenu());
  3430.             $tabMenu[$i]['lien'] = $this->getInfoMenu($tab[0]);
  3431.             if(count($tab) >1)
  3432.                 $tabMenu[$i]['id'] = $tab[1];
  3433.             else
  3434.                 $tabMenu[$i]['id'] ="";
  3435.             $tabMenu[$i]['titre'] = $unMenu->getTitre();
  3436.             $tabMenu[$i]['type']  = $unMenu->getTypeMenu();
  3437.             $i++;
  3438.         }
  3439.         return $tabMenu
  3440.     } 
  3441.     public function getInfoMenu($menu){
  3442.         if($menu=="app_admin_info_page"){
  3443.             $infoMenu "";
  3444.         }else if($menu=="app_admin_details_article"){
  3445.             $infoMenu '/articles';
  3446.         }else if($menu=="app_admin_details_rubrique"){
  3447.             $infoMenu "/details";
  3448.         }else if($menu=="app_admin_catalogue_page"){
  3449.             $infoMenu "/catalogue";
  3450.         }else if($menu=="app_admin_carte_page"){
  3451.             $infoMenu "/info/carte";
  3452.         }else if($menu=="admin_projet_get_liste_public"){
  3453.             $infoMenu "/get/liste/projet/public";
  3454.         }
  3455.         return $infoMenu
  3456.     } 
  3457.     
  3458.     
  3459.     protected function saveDefautPageTemplate($em$objetTemplate,$objetAbonne$pageRepository){
  3460.         //faire une boucle sur les pages que recevoir les zones
  3461.         $criteriaSup = array('template' => $objetTemplate,'abonne' => $objetAbonne);
  3462.         $objetPage $pageRepository->findOneBy($criteriaSup);
  3463.         
  3464.         if ($objetPage == null ) {
  3465.             
  3466.             $objetNPage = new Page();   
  3467.             $objetNPage->setTitrePage("Accueil");
  3468.             $objetNPage->setTwigPage("index.html.twig");
  3469.             $objetNPage->setDescriptionPage("Gestion de la page d'accueil de l'abonne : ".$objetAbonne->getNom());
  3470.             $objetNPage->setSiPageAccueil(1);
  3471.             $objetNPage->setAbonne($objetAbonne);
  3472.             $objetNPage->setTemplate($objetTemplate);
  3473.             $em->persist($objetNPage);
  3474.             $em->flush();  
  3475.         }
  3476.         
  3477.     }
  3478.     protected function getListeAbonne($em,$objetAbonne ,$abonneRepository){
  3479.         if($objetAbonne->getSiPrincipale() == 2)
  3480.             $listeAbonne$abonneRepository->findBy(array("partenaire"=>$objetAbonne->getpartenaire()));
  3481.         else
  3482.             $listeAbonne = array();
  3483.         return  $listeAbonne;
  3484.     }
  3485.          /**
  3486.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  3487.      *
  3488.      * @author armand.tevi@gmail.com
  3489.      * @copyright ADMIN 2015
  3490.      *
  3491.      * @version 1
  3492.      *
  3493.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  3494.      */
  3495.     protected function insertSurfaceAnneeHistorique($em$objetSurfaceAnnee$objetAnneeCampagne,$surfaceAnneeHistoriqueRepository) {
  3496.         //$objetVille= $em->getRepository($this->stockBundle . 'Ville')->find($idVille);   
  3497.         $criteriaHistorique = array('surfaceannee' => $objetSurfaceAnnee'anneecampagne'=>$objetAnneeCampagne);
  3498.         
  3499.         $objetSurfaceAnneeHistorique =  $surfaceAnneeHistoriqueRepository->findOneBy($criteriaHistorique);               
  3500.         if( $objetSurfaceAnneeHistorique == null)
  3501.             $objetSurfaceAnneeHistorique = new SurfaceAnneeHistorique;
  3502.    
  3503.         $objetSurfaceAnneeHistorique->setSurfaceannee($objetSurfaceAnnee);
  3504.         $objetSurfaceAnneeHistorique->setAnneecampagne($objetAnneeCampagne);
  3505.         $objetSurfaceAnneeHistorique->setAbonne($objetSurfaceAnnee->getAbonne());
  3506.         $em->persist($objetSurfaceAnneeHistorique);
  3507.         $em->flush();
  3508.  
  3509.     }
  3510.     protected function infoSigne($signe){
  3511.         $infoSigne "";
  3512.         switch ($signe) {
  3513.             case 1:
  3514.                 $infoSigne ">";
  3515.                 break;
  3516.             case 2:
  3517.                 $infoSigne =">=";
  3518.                 break;
  3519.             case 3:
  3520.                 $infoSigne "<";
  3521.                 break;
  3522.             case 4:
  3523.                 $infoSigne "<=";
  3524.                 break; 
  3525.         }
  3526.         return $infoSigne;  
  3527.     }
  3528.     public function initialiserInspectionRempliProducteur(EntityManager $em$producteurId 0$inspectionId0) {
  3529.         try {
  3530.             $sqlrech ' UPDATE inspection_rempli set etat_fournisseur_producteur = 2  WHERE producteur_id =:producteurId  AND inspection_id =:inspectionId ';
  3531.            // var_dump($sqlrech, $idProduit);exit;
  3532.             $stmt $em->getConnection()->prepare($sqlrech);
  3533.             $stmt->bindValue(':producteurId'$producteurIdPDO::PARAM_INT);
  3534.             $stmt->bindValue(':inspectionId'$inspectionIdPDO::PARAM_INT);
  3535.             $stmt->execute();
  3536.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3537.             $stmt null;
  3538.             $res null;
  3539.             var_dump($e->getMessage());
  3540.         }
  3541.         return 1;
  3542.     }
  3543.     public function initialiserProgrammeInspection(EntityManager $em$typeProgramme 0$etatProgramme=) {
  3544.         try {
  3545.             $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 )';
  3546.            
  3547.             $stmt $em->getConnection()->prepare($sqlrech);
  3548.             $stmt->bindValue(':typeProgramme'$typeProgrammePDO::PARAM_INT);
  3549.             $stmt->bindValue(':etatProgramme'$etatProgrammePDO::PARAM_INT);
  3550.             $stmt->execute();
  3551.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3552.             $stmt null;
  3553.             $res null;
  3554.             var_dump($e->getMessage());
  3555.         }
  3556.         return 1;
  3557.     }
  3558.     public function initialiserProgramme(EntityManager $em$typeProgramme 0) {
  3559.         try {
  3560.             $sqlrech ' UPDATE programme set etat_programme = 0  WHERE type_programme =:typeProgramme ';
  3561.            // var_dump($sqlrech, $idProduit);exit;
  3562.             $stmt $em->getConnection()->prepare($sqlrech);
  3563.             $stmt->bindValue(':typeProgramme'$typeProgrammePDO::PARAM_INT);
  3564.             $stmt->execute();
  3565.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3566.             $stmt null;
  3567.             $res null;
  3568.             var_dump($e->getMessage());
  3569.         }
  3570.         return 1;
  3571.     }
  3572.     public function initialiserInspectionRempliSurface(EntityManager $em$surfaceId 0$inspectionId0) {
  3573.         try {
  3574.             $sqlrech ' UPDATE inspection_rempli set etat_fournisseur_producteur = 2  where surfaceannee_id =:surfaceId AND inspection_id =:inspectionId ';
  3575.            // var_dump($sqlrech, $idProduit);exit;
  3576.             $stmt $em->getConnection()->prepare($sqlrech);
  3577.             $stmt->bindValue(':surfaceId'$surfaceIdPDO::PARAM_INT);
  3578.             $stmt->bindValue(':inspectionId'$inspectionIdPDO::PARAM_INT);
  3579.             $stmt->execute();
  3580.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3581.             $stmt null;
  3582.             $res null;
  3583.             var_dump($e->getMessage());
  3584.         }
  3585.         return 1;
  3586.     }
  3587.     public function getInfoProducteurAnniversaireAction(EntityManager $em,$abonneId) {
  3588.         try {
  3589.             $dateTime = new \DateTime();
  3590.             $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
  3591.             
  3592.                             FROM  producteur p
  3593.                             INNER JOIN utilisateur u on p.utilisateur_id = u.id
  3594.                         
  3595.                             INNER JOIN abonne a on p.abonne_id = a.id
  3596.                             
  3597.                             WHERE a.id =:abonneId AND MONTH(u.date_naissance) =:mois  AND DAY(u.date_naissance) =:jour  
  3598.                              '//
  3599.            
  3600.            //var_dump($sqlrech, $dateTime->format('m'), $dateTime->format('d'));exit;
  3601.             $stmt $em->getConnection()->prepare($sqlrech);
  3602.             $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  3603.             $stmt->bindValue(':mois'$dateTime->format('m'), PDO::PARAM_STR);
  3604.             $stmt->bindValue(':jour'$dateTime->format('d'), PDO::PARAM_STR);
  3605.             $stmt->execute();
  3606.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  3607.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3608.             $stmt null;
  3609.             $res null;
  3610.             var_dump($e->getMessage());
  3611.         }
  3612.         return $res;
  3613.     }
  3614.     public function getTonnageByAnnee($abonneId$commandeRepository,$produitId$type$surfaceId$producteurId$typeCulture$infoAnnee ) {
  3615.         $tab = array();
  3616.         $infoAnneePasse =0;
  3617.         if($infoAnnee!=0)
  3618.             $infoAnneePasse =  $infoAnnee-1;
  3619.         
  3620.         $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);
  3621.         $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);
  3622.         //(0,0,0,0,0,0,0,0,6,0,20,1,$sessionData['abonneId'], 0,0,0,$listeObjetSurface[0]->getId(),$infoAnneeId); 
  3623.         $tab = [$totalInfoAnnee$totalInfoAnneePasse]; 
  3624.         
  3625.         return  $tab
  3626.     }
  3627.     public function getFinanceByAnnee($em$operationManager,$produitId$type$surfaceId$producteurId$typeCompe$infoAnnee$sens ) {
  3628.         $tab = array();
  3629.         $infoAnneePasse =0;
  3630.         if($infoAnnee!=0)
  3631.             $infoAnneePasse =  $infoAnnee-1;
  3632.         
  3633.         $totalInfoAnnee =  $operationManager->soldeCaisseProducteurDate($em,$idCaisse=0,$datedeb=0$datefin=0$idprod=0,$idab=0,$compte='0'$producteurId$fournisseurId=0,$sens$typeCompe$infoAnnee) ; 
  3634.         $totalInfoAnneePasse =  $operationManager->soldeCaisseProducteurDate($em,$idCaisse=0,$datedeb=0$datefin=0$idprod=0,$idab=0,$compte='0'$producteurId$fournisseurId=0,$sens$typeCompe$infoAnneePasse) ; 
  3635.         //(0,0,0,0,0,0,0,0,6,0,20,1,$sessionData['abonneId'], 0,0,0,$listeObjetSurface[0]->getId(),$infoAnneeId); 
  3636.         $tab = [$totalInfoAnnee$totalInfoAnneePasse]; 
  3637.         
  3638.         return  $tab
  3639.     }
  3640.     /**
  3641.      * Methode s'occupant de copier les commandes en attente vers les commandes validees .
  3642.      *
  3643.      * @author armand.tevi@gmail.com
  3644.      * @copyright ADMIN 2015
  3645.      *
  3646.      * @version 1
  3647.      *
  3648.      * @return twig d'ajout d'un abonne ajouterFournisseur.html.twig
  3649.      */
  3650.     protected function saveInfoDeplacer($em$objetLigneCommande$entrepotDepart$entrepotArrive$quantite$numeroLot$dateEnvoi$dateReception) {
  3651.         $em->getConnection()->beginTransaction();
  3652.         //(
  3653.         try {
  3654.             $objetInfoDeplacer = new InfoDeplacer();
  3655.             $objetInfoDeplacer->setLigneCommande($objetLigneCommande);
  3656.             $objetInfoDeplacer->setEntrepotDepart($entrepotDepart);
  3657.             $objetInfoDeplacer->setEntrepotArrive($entrepotArrive);
  3658.             $objetInfoDeplacer->setQuantite($quantite);
  3659.             $objetInfoDeplacer->setNumeroLot($numeroLot);
  3660.             $objetInfoDeplacer->setDateLivraison($dateReception);
  3661.             $objetInfoDeplacer->setDateEnvoi($dateEnvoi);
  3662.             // $montantCommande = (int) $montantCommande + (int) $montant;
  3663.             $em->persist($objetInfoDeplacer);
  3664.             $em->flush();
  3665.             $em->getConnection()->commit();
  3666.         } catch (\Exception $e) {
  3667.             $em->getConnection()->rollback();
  3668.             $em->close();
  3669.             throw $e;
  3670.         }
  3671.         return  $objetInfoDeplacer;
  3672.     
  3673. }
  3674. function traiteFonctionDonneeImage($em$JSONData$parameters$surfaceAnneeRepository$inspectionRempliRepository$producteurRepository$imageRepository$type)
  3675.     { ///Revoir comment aj()outer l'abonne
  3676.         if($type == 2)
  3677.             $listImage $JSONData;
  3678.         else
  3679.             $listImage json_decode($JSONDatatrue);
  3680.         $em->getConnection()->beginTransaction();
  3681.         //$donnee = $unProducteur["nom"] ."#". $unProducteur["prenoms"] ."#".$unProducteur["telephone"] ."#". $unProducteur["idVille"] ."#".$unProducteur["codeGenere"]  ."#".$unProducteur["idutil"] ."#".$unProducteur["sexe"]."#".$unProducteur["cni"]  ;
  3682.         $codeGenere "0001";
  3683.         if ($listImage  != null) {
  3684.             foreach ($listImage as $uneImage) {
  3685.                 //$votreImage = base64_decode($parameters['image'.$uneImage["id"]]);
  3686.                 $file_path =   __DIR__ '/../../../public/';
  3687.                 $dossier "producteur/";
  3688.                 
  3689.                 if(array_key_exists('image' $uneImage["id"], $parameters)){
  3690.                     if($type == 2)
  3691.                         $urlImage $parameters['path'];
  3692.                     else
  3693.                         $urlImage  $parameters['image' $uneImage["id"]];
  3694.                     if ($uneImage["typeImage"] == 2) {
  3695.                         $media str_replace('data:audio/mpeg;base64,Base64EncodedMP3Data'''$urlImage);
  3696.                         $media str_replace(' ''+'$media);
  3697.                         $nameImage "audio_" uniqid() . "_" $uneImage["id"] . '.mp3';
  3698.                     } else {
  3699.                         $media str_replace('data:image/png;base64,'''$urlImage);
  3700.                         $media str_replace(' ''+'$media);
  3701.                         $nameImage "signature_" uniqid() . "_" $uneImage["id"] . '.png';
  3702.                     }
  3703.                 
  3704.                     // Create Image path with Image name and Extension
  3705.                     $file $file_path $dossier $nameImage;
  3706.                     // Decode the Base64 encoded Image
  3707.                     if ($uneImage["typeImage"] == 2)
  3708.                         $data base64_decode($urlImage);
  3709.                     else
  3710.                         $data base64_decode($media);
  3711.                     // Save Image in the Image Directory
  3712.                     $success file_put_contents($file$data);
  3713.                     //$file_path = $file_path . base64_decode( $_FILES['image'.$uneImage["id"]]['name']);
  3714.                     $objetImage null;
  3715.                     if ($uneImage["typeImage"] != 3)
  3716.                         $objetImage $imageRepository->findOneBy(array("titreImage" => $uneImage["codeGenere"]));
  3717.                     if ($objetImage == null) {
  3718.                         $objetImage = new Image();
  3719.                         $objetImage->setUrlImage($dossier $nameImage);
  3720.                         if ($uneImage["typeImage"] == 3) {
  3721.                             $objetSurfaceAnnee $surfaceAnneeRepository->findOneBy(array("codeGenere" => $uneImage['prodCodeGenere']));
  3722.                             if ($objetSurfaceAnnee != null)
  3723.                                 $objetImage->setSurfaceannee($objetSurfaceAnnee);
  3724.                         }
  3725.                         if ($uneImage["typeImage"] == 10) {
  3726.                             $objetProducteur $producteurRepository->findOneBy(array("codeGenere" => $uneImage['prodCodeGenere']));
  3727.                             if ($objetProducteur != null)
  3728.                                 $objetImage->setProducteur($objetProducteur);
  3729.                         } else {
  3730.                             $objetInspectionRempli $inspectionRempliRepository->findOneBy(array("codeGenere" => $uneImage['prodCodeGenere']));
  3731.                             if ($objetInspectionRempli != null)
  3732.                                 $objetImage->setInspectionrempli($objetInspectionRempli);
  3733.                         }
  3734.                         $objetImage->setCodeGenere($uneImage["prodCodeGenere"]);
  3735.                         $objetImage->setElementCodeGenere($uneImage["prodCodeGenere"]);
  3736.                         $objetImage->setTitreImage($uneImage["codeGenere"]);
  3737.                         $em->persist($objetImage);
  3738.                         $em->flush($objetImage);
  3739.                     }
  3740.                 }
  3741.             }
  3742.         }
  3743.         $em->getConnection()->commit();
  3744.     }
  3745.     function getChatBatInspection($em,$abonneId$inspectionId ){
  3746.             $i=0;  
  3747.             $tabDonnee = [1,2,3,4,5,6,7,8,9,10,11,12];
  3748.             $tabDonneeInspection = array();
  3749.             $tabDonneeMois= array();
  3750.             $infoInspection = array();
  3751.             
  3752.             //var_dump(1);exit; 
  3753.             foreach ($tabDonnee as $uneDonneeMois  ) {
  3754.                 
  3755.                 $infoInspection =$this->getStatInspectionAction($em,$abonneId$inspectionId$uneDonneeMois)  ;
  3756.                 
  3757.                 $tabDonneeMois[$i]= $this->traiteInfoMois($uneDonneeMois);
  3758.                 if(count($infoInspection)!=)
  3759.                     $tabDonneeInspection[$i] =  $infoInspection[0]['total'];   
  3760.                 else
  3761.                     $tabDonneeInspection[$i] =  0;
  3762.                 $i++;
  3763.                
  3764.             }
  3765.             return [$tabDonneeMois$tabDonneeInspection];
  3766.     }
  3767.     public function getStatSuivrelocalisationAction(EntityManager $em,$abonneId$groupementId$zoneId$siP=0$partenaireId=0$typeAction=0$siListe=0$avecLocalisation=0$agentId 0) {
  3768.         try {
  3769.             if($siListe==0)
  3770.                 $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';
  3771.             else
  3772.                 $sqlrech 'SELECT Count(DISTINCT(sa.id)) as total ';
  3773.             $sqlrech .= '
  3774.                             FROM surface_annee sa
  3775.                             INNER JOIN produit pr on sa.produit_id = pr.id
  3776.                              ';
  3777.                 /*if($groupementId != 0 || $zoneId !=0)*/
  3778.                     $sqlrech .= " INNER JOIN producteur p  on sa.producteur_id  = p.id
  3779.                                   INNER JOIN utilisateur u on p.utilisateur_id = u.id
  3780.                 ";
  3781.                 if($groupementId != 0){
  3782.                     $sqlrech .= '   INNER JOIN producteur_groupement gp on gp.producteur_id = p.id
  3783.                                     INNER JOIN groupement g on gp.groupement_id = g.id' ;
  3784.                 }
  3785.                 if($zoneId != 0){
  3786.                     $sqlrech .= '   INNER JOIN zone_producteur zp on zp.producteur_id = p.id
  3787.                                     INNER JOIN ville v on zp.ville_id = v.id' ;
  3788.                 }
  3789.                 if($typeAction != 0){
  3790.                     $sqlrech .= " INNER JOIN surface_abonne sab on sab.surfaceannee_id  = sa.id ";
  3791.                     $sqlrech .= " INNER JOIN abonne a on sab.abonne_id =  a.id ";
  3792.                     if($typeAction == &&  $partenaireId != 0)
  3793.                         $sqlrech .= " INNER JOIN partenaire pt on sab.partenaire_id = pt.id ";
  3794.                 }else{
  3795.                     $sqlrech .= " INNER JOIN abonne a on sa.abonne_id  = a.id";
  3796.                 }
  3797.                 if($avecLocalisation == 0){
  3798.                     $sqlrech .= " LEFT JOIN localisation l ON l.surfaceannee_id = sa.id ";
  3799.                 }else if($avecLocalisation == 1){
  3800.                     $sqlrech .= " INNER JOIN localisation l ON l.surfaceannee_id = sa.id 
  3801.                                 INNER JOIN utilisateur ut on ut.id = l.utilisateur_id ";
  3802.                 }
  3803.                 $sqlrech .= " WHERE a.id =:abonneId  AND  sa.etat_surface_annee =1 ";
  3804.                 if($siP==0//on a pas touché la parcelle mais pas de localisation recu !
  3805.                     $sqlrech .= ' AND sa.superficie_reelle IS NOT NULL AND l.surfaceannee_id is null ';
  3806.                 elseif($siP==1//Pas d'activité de localisation sur la parcelle sur la parcelle
  3807.                     $sqlrech .= ' AND sa.superficie_reelle IS  NULL AND l.surfaceannee_id IS NOT NULL ';
  3808.                 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
  3809.                     $sqlrech .= " AND ( sa.superficie_reelle ='null' OR sa.superficie_reelle = '0' ) AND l.tab_polygone = '0' ";
  3810.                 elseif($siP==3//Parcelle null mais on a les valeurs sur les points de localisation
  3811.                     $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 != '')  ";
  3812.                 elseif($siP==4//Parcelle null mais on a les valeurs sur les points de localisation
  3813.                     $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 != '')  ";
  3814.                 elseif($siP==5//Parcelle null mais on a les valeurs sur les points de localisation
  3815.                     $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 = '')  ";
  3816.                 elseif($siP==6//Parcelle null mais on a les valeurs sur les points de localisation
  3817.                     $sqlrech .= " AND ( sa.superficie_reelle ='null' OR sa.superficie_reelle ='0' ) AND (l.tab_polygone = '0' OR l.tab_polygone = '')  ";
  3818.                 else
  3819.                     $sqlrech .= ' ';        
  3820.                 if($typeAction == &&  $partenaireId != 0)
  3821.                     $sqlrech .= " AND  pt.id =:partenaireId  ";
  3822.                 if($groupementId != )
  3823.                     $sqlrech .= " AND  g.id =:groupementId  ";
  3824.                 if($agentId != )
  3825.                     $sqlrech .= " AND  ut.id =:agentId  ";
  3826.                 if($zoneId != )
  3827.                     $sqlrech .= " AND  v.id =:zoneId  ";
  3828.                 //var_dump($sqlrech);
  3829.                 //INNER JOIN produit_abonne pa on pa.produit_id  = p.id
  3830.                 $stmt $em->getConnection()->prepare($sqlrech);
  3831.                 if($typeAction == &&  $partenaireId != 0)
  3832.                     $stmt->bindValue(':partenaireId'$partenaireIdPDO::PARAM_INT);
  3833.                 
  3834.                 if($groupementId != )
  3835.                     $stmt->bindValue(':groupementId'$groupementIdPDO::PARAM_INT);
  3836.                 if($agentId != )
  3837.                     $stmt->bindValue(':agentId'$agentIdPDO::PARAM_INT);
  3838.                 if($zoneId != )
  3839.                     $stmt->bindValue(':zoneId'$zoneIdPDO::PARAM_INT);
  3840.                 if($typeAction == || $typeAction == 1)
  3841.                     $stmt->bindValue(':abonneId'$abonneIdPDO::PARAM_INT);
  3842.             $stmt->execute();
  3843.             $res $stmt->executeQuery()->fetchAllAssociative(); //$stmt->fetchAll(PDO::FETCH_ASSOC);
  3844.         } catch (\Symfony\Component\Form\Exception\Exception $e) {
  3845.             $stmt null;
  3846.             $res null;
  3847.             var_dump($e->getMessage());
  3848.         }
  3849.         return $res;
  3850.     }
  3851.     
  3852.     
  3853. }