src/ControllerModel/user/paramUtilTrait.php line 822

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