src/Controller/stock/OperationController.php line 777

Open in your IDE?
  1. <?php
  2. namespace App\Controller\stock;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Contracts\Translation\TranslatorInterface;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use App\Entity\user\Module;
  7. use App\Entity\stock\Categorie;
  8. use App\Entity\stock\Fournisseur;
  9. use App\Entity\stock\Facture;
  10. use App\Entity\stock\Fichier;
  11. use App\Repository\stock\LigneCommandeRepository;
  12. use App\Repository\stock\CommandeRepository;
  13. use App\Repository\stock\InventaireRepository;
  14. use App\Form\stock\CategorieType;
  15. use App\Form\stock\FichierType;
  16. use App\Services\user\LoginManager;
  17. use Types\stock\TypeMenu;
  18. use App\Repository\user\ConnexionRepository;
  19. use App\Repository\user\AbonneRepository;
  20. use App\Repository\user\ActionRepository;
  21. use App\Services\param\ParametreManager;
  22. use App\Repository\param\ParamRepository;
  23. use App\Repository\user\ModuleRepository;
  24. use App\Repository\user\ControleurRepository;
  25. use App\Repository\user\ProfilRepository;
  26. use App\Repository\user\UtilisateurRepository;
  27. use App\Repository\stock\TypeOperationRepository;
  28. use App\Repository\stock\VilleRepository;
  29. use App\Repository\stock\CaisseRepository;
  30. use App\Repository\stock\FournisseurRepository;
  31. use App\Repository\prod\ProducteurRepository;
  32. use App\Repository\cms\TemplateRepository;
  33. use App\Repository\prod\GroupementRepository;
  34. use App\Repository\stock\CategorieProduitRepository;
  35. use PHPExcel;
  36. use PHPExcel_IOFactory;
  37. use PHPExcel_Style_Fill;
  38. use PHPExcel_Style_Alignment;
  39. use PHPExcel_Style;
  40. use PHPExcel_Worksheet_ColumnDimension;
  41. use PHPExcel_Style_NumberFormat;
  42. use PHPExcel_Writer_Excel2007;
  43. use Symfony\Component\HttpFoundation\Request;
  44. use App\ControllerModel\user\paramUtilTrait;
  45. use App\Types\stock\TypeStock;
  46. use App\Services\stock\OperationManager;
  47. class OperationController extends AbstractController {
  48.     use paramUtilTrait;
  49.     protected $nom 'CategorieController';
  50.     protected $description 'Controlleur qui gère les opérations';
  51.     protected $response;
  52.     protected $logMessage ' [ CategorieController ] ';
  53.     /**
  54.      * Déclaration de l'entity manager.
  55.      *
  56.      * @var
  57.      */
  58.     protected $em;
  59.     public function __construct(TranslatorInterface $translatorLigneCommandeRepository $ligneCommandeRepositoryOperationManager $operationManager) {
  60.         //parent::__construct();
  61.         $this->response = new Response();
  62.         $this->response->headers->addCacheControlDirective('no-cache'true);
  63.         $this->response->headers->addCacheControlDirective('max-age'0);
  64.         $this->response->headers->addCacheControlDirective('must-revalidate'true);
  65.         $this->response->headers->addCacheControlDirective('no-store'true);
  66.          $this->moduleTitre Module::MOD_GEST_OP;
  67.         $this->moduleDesc Module::MOD_GEST_OP_DESC;
  68.         $this->translator $translator;
  69.         $this->ligneCommandeRepository$ligneCommandeRepository;
  70.         $this->operationManager $operationManager;
  71.     }
  72.     /**
  73.      * Methode s'occupant de l'ajout du produit.
  74.      *
  75.      * @author armand.tevi@gmail.com
  76.      * @copyright ADMIN 2015
  77.      *
  78.      * @version 1
  79.      * @return twig d'ajout d'un abonne ajouterproduit.html.twig
  80.      */
  81.     public function getAlimenterCaisseAction(Request $request$type,LoginManager $loginManager,ParamRepository $paramRepositor,ConnexionRepository $connexionRepository,ActionRepository $actionRepository,
  82.     ModuleRepository $moduleRepository,ControleurRepository $controleurRepository,ProfilRepository $profilRepository,
  83.     TypeOperationRepository $typeOperationRepository,VilleRepository $villeRepositoryFournisseurRepository $fournisseurRepositoryAbonneRepository $abonneRepository,
  84.     ProducteurRepository $producteurRepository) {
  85.           /*
  86.          * Nom de l'action en cours
  87.          */
  88.         $nomAction __FUNCTION__;
  89.         /*
  90.          * Description de l'action de l'action en cours
  91.          */
  92.         $descAction "Alimenter les caisses extérieures ";
  93.         $locale ='fr';
  94.         $valRetour =$this->gestionDroitUtil($request$nomAction$descAction,$this->moduleTitre,$this->moduleDesc$loginManager,$paramRepositor,$connexionRepository$actionRepository$moduleRepository$controleurRepository$profilRepository );
  95.         if($valRetour==1){
  96.             return $this->redirect($this->generateUrl('app_logout'));
  97.         }elseif($valRetour==2){
  98.             return $this->redirect($this->generateUrl('app_admin_user_access_refuse'));
  99.         }
  100.         $sessionData $this->infosConnecte($request$loginManager$paramRepositor,$connexionRepository$actionRepository);;
  101.         $em $this->getDoctrine()->getManager();
  102.         $prod $sessionData["produit_id"];
  103.         $infoPartenaire  $this->getInfoPartenaire($em$this->getAbonne($em$sessionData['abonneId'],$abonneRepository));
  104.         try {
  105.             
  106.         } catch (\Exception $e) {
  107.             var_dump($e->getMessage());
  108.             exit;
  109.         }
  110.         
  111.         $infoPartenaire  $this->getInfoPartenaire($em$this->getAbonne($em$sessionData['abonneId'],$abonneRepository));
  112.          $typeOperation $typeOperationRepository->getListeTypeOperation($total=0$page=0$articles_per_page=0$sessionData["abonneId"]) ; //getListeTypeOperationSimple($sessionData["abonneId"]);
  113.          //var_dump($typeOperation);exit;
  114.          $listeFournisseur $fournisseurRepository->getAllFournisseur($type=2$sessionData['abonneId'], $infoPartenaire['partenaireId'], $infoPartenaire['typeAction']);
  115.          //liste de producteurs
  116.          $queryResult $producteurRepository->getAllProducteur(000000000,1,5,array(),0,$sessionData['abonneId'], 00,0,0,$infoPartenaire['partenaireId'], $infoPartenaire['typeAction'],0,0,0);
  117.             
  118.         /*
  119.          * Préparation des informations que nous allons traiter  sur le twig
  120.          */
  121.         //$this->data['listeProduit'] = $listeProduit;
  122.         
  123.         //recupération de la liste des villes 
  124.         $listeVille $villeRepository->getAllActiveVille($prod);
  125.         $idTypeOperation TypeStock::TYPEOPERALIMCAISSE;
  126.         
  127.         $this->data['locale'] = $locale;
  128.         $this->data['typeOperation'] = $typeOperation;
  129.         $this->data['type'] = $type;
  130.         $this->data['listeVille'] = $listeVille;
  131.         $this->data['listeProducteur'] = $queryResult['data']; 
  132.         $this->data['idTypeOperation'] = $idTypeOperation;
  133.         $this->data['listeFournisseur'] = $listeFournisseur;
  134.         $this->data['actionRepository'] = $actionRepository;
  135.         return $this->render($this->stockBundleSlash($sessionData['typePresentation']). '/Operation/alimenterCaisse.html.twig'$this->data$this->response);
  136.     }
  137.     /**
  138.      * Methode s'occupant de l'ajout du produit.
  139.      *
  140.      * @author armand.tevi@gmail.com
  141.      * @copyright ADMIN 2015
  142.      *
  143.      * @version 1
  144.      * @return twig d'ajout d'un abonne ajouterproduit.html.twig
  145.      */
  146.     public function getPageOperationAction(Request $request$codecommande$type) {
  147.         /*
  148.          * Nom de l'action en cours
  149.          */
  150.         $nomAction __FUNCTION__;
  151.         /*
  152.          * Description de l'action de l'action en cours
  153.          */
  154.         $descAction "Avoir accès à la page de paiement des commandes livrées";
  155.         /*
  156.          * Préparation du message de log 
  157.          */
  158.         $this->logMessage .= ' [ ' $nomAction ' ] ';
  159.         /*
  160.          * Service de gestion des droits
  161.          */
  162.         
  163.         /*
  164.          * Informations de session
  165.          */
  166.         $sessionData $this->infosConnecte($request$loginManager$paramRepositor,$connexionRepository$actionRepository);;
  167.         /*
  168.          * Locale en cours
  169.          */
  170.         $locale $loginManager->getLocale();
  171.         $this->data['locale'] = $locale;
  172.         /*
  173.          * On vérifie si l'utilisateur est connecté
  174.          */
  175.         $status $loginManager->isConnecte($nomAction$paramRepositor,$connexionRepository$actionRepository);
  176.         if ($status['isConnecte']) {
  177.             /*
  178.              * Au cas ou l'utilisateur est connecté on vérifie s'il nest pas innactif. S'il est innactif
  179.              * on garde en mémoire flash la route actuelle pour effectuer une redirection lors de la prochaine connexion
  180.              */
  181.             if ($status['isInnactif']) {
  182.                 $routeName $request->get('_route');
  183.                 $routeParams $request->get('_route_params');
  184.                 $this->get('session')->getFlashBag()->add('restoreUrl'$this->generateUrl($routeName$routeParams));
  185.                 $this->get('session')->getFlashBag()->add('ina'$this->translator->trans("site.long.periode"));
  186.                 return $this->redirect($this->generateUrl('app_logout'));
  187.             }
  188.             /*
  189.              * Seuls les utilisateurs admins ont le droit d'acceder à cette action
  190.              */
  191.             if (!$status['isUser']) {
  192.                 return $this->redirect($this->generateUrl('app_logout'));
  193.             }
  194.         } else {
  195.             return $this->redirect($this->generateUrl('app_logout'));
  196.         }
  197.         /*
  198.          * Gestion des droits
  199.          */
  200.         if (!$loginManager->getOrSetActions(Module::MOD_GEST_PRODModule::MOD_GEST_PROD_DESC$this->getNomClassRun(__CLASS__), $this->description$nomAction$descAction$sessionData['idProfil'], $moduleRepository$controleurRepository$actionRepository$profilRepository)) {
  201.             $this->logMessage .= ' [ TENTATIVE DE VIOLATION DE DROITS ] ';
  202.             $this->get('session')->getFlashBag()->add('access'"Vous n'avez pas le droit d'accéder à cette page");
  203.             return $this->redirect($this->generateUrl('app_admin_user_access_refuse'));
  204.         }
  205.         try {
  206.             
  207.         } catch (\Exception $e) {
  208.             var_dump($e->getMessage());
  209.             exit;
  210.         }
  211.         $em $this->getDoctrine()->getManager();
  212.          $typeOperation $em->getRepository($this->stockBundle 'TypeOperation')->getListeTypeOperationSimple$sessionData['abonneId']);
  213.         /*
  214.          * Préparation des informations que nous allons traiter  sur le twig
  215.          */
  216.         //$this->data['listeProduit'] = $listeProduit;
  217.         $this->data['locale'] = $locale;
  218.         $this->data['codecommande'] = $codecommande;
  219.         $this->data['typeOperation'] = $typeOperation;
  220.         $this->data['type'] = $type;
  221.         return $this->render($this->stockBundleSlash($sessionData['typePresentation']). '/Operation/operationPaiement.html.twig'$this->data$this->response);
  222.     }
  223.     /**
  224.      * Methode s'occupant de l'ajout du produit.
  225.      *
  226.      * @author armand.tevi@gmail.com
  227.      * @copyright ADMIN 2015
  228.      *
  229.      * @version 1
  230.      * @return twig d'ajout d'un abonne ajouterproduit.html.twig
  231.      */
  232.     public function traterFichierDonneeExcelAction(Request $request$id) {
  233.         /*
  234.          * Nom de l'action en cours
  235.          */
  236.         $nomAction __FUNCTION__;
  237.         /*
  238.          * Description de l'action de l'action en cours
  239.          */
  240.         $descAction "Expoter le fichier excel comportant les avances et livraison des collecteurs ";
  241.         
  242.         $valRetour =$this->gestionDroitUtil($request$nomAction$descAction,$this->moduleTitre,$this->moduleDesc$loginManager,$paramRepositor,$connexionRepository$actionRepository$moduleRepository$controleurRepository$profilRepository );
  243.         if($valRetour==1){
  244.             return $this->redirect($this->generateUrl('app_logout'));
  245.         }elseif($valRetour==2){
  246.             return $this->redirect($this->generateUrl('app_admin_user_access_refuse'));
  247.         }
  248.         $em $this->getDoctrine()->getManager();
  249.         
  250.         $objetChemin $em->getRepository($this->stockBundle 'Fichier')->find($id);
  251.         
  252.         //Recuperation du chemin du fichier
  253.         $chenimFichierExcel __DIR__ '/../../../public/' $objetChemin->getTitreImage();
  254.         
  255.         $restCommande =array();                        
  256.         
  257.         $collectuer =null;
  258.         $objetProduit $em->getRepository($this->stockBundle 'Produit')->find(\Types\stock\TypeStock::IDPROD);
  259.         $em->getConnection()->beginTransaction();    
  260.             try {
  261.                 /*
  262.                  * Récupération des la liste des critères
  263.                  */
  264.                 $array_data = array();
  265.                 $XLSXDocument = new \PHPExcel_Reader_Excel2007();
  266.                 $Excel $XLSXDocument->load($chenimFichierExcel);
  267.                 // get all the row of my file
  268.                 $rowIterator $Excel->getActiveSheet()->getRowIterator();
  269.                 $i 0;
  270.                 foreach ($rowIterator as $row) {
  271.                     $cellIterator $row->getCellIterator();
  272.                     // Loop all cells, even if it is not set
  273.                     $cellIterator->setIterateOnlyExistingCells(false);
  274.                     $rowIndex $row->getRowIndex();
  275.                     
  276.                     $array_data[$rowIndex] = array('A' => '''B' => '''C' => '''D' => '''E' => '''F' => '''G' => '''H' => '''N' => '''O' => '''P' => '''R' => '');
  277.                     if ($rowIndex >= $objetChemin->getDebutTraitement()) {
  278.                         
  279.                         //$Excel->ge('A' . $IndexLigne, $value);                        
  280.                         foreach ($cellIterator as $cell) {
  281.                             if ($cell->getValue() != null) {
  282.                                 if ('A' == $cell->getColumn()) {
  283.                                     $numeroCommande $cell->getValue();
  284.                                     
  285.                                 } elseif ('B' == $cell->getColumn()) {
  286.                                     $liquidationCommande $cell->getValue();
  287.                                 } elseif ('C' == $cell->getColumn()) {
  288.                                     $dateCommande $cell->getValue();
  289.                                 } elseif ('F' == $cell->getColumn()) {
  290.                                     $zoneCommande $cell->getValue();
  291.                                     
  292.                                 } elseif ('G' == $cell->getColumn()) {                                    
  293.                                     $collectuer $cell->getValue();
  294.                                     
  295.                                 } elseif ('H' == $cell->getColumn()) {
  296.                                     $operation $cell->getValue();
  297.                                    //var_dump($operation);exit; 
  298.                                 } elseif ('N' == $cell->getColumn()) {
  299.                                     $quantite $cell->getValue();
  300.                                 } elseif ('O' == $cell->getColumn()) {
  301.                                     $avance $cell->getValue();
  302.                                 } elseif ('P' == $cell->getColumn()) {
  303.                                     $livre $cell->getValue();
  304.                                 } elseif ('Q' == $cell->getColumn()) {
  305.                                     $prixUnitaire $cell->getValue();
  306.                                 } elseif ('R' == $cell->getColumn()) {
  307.                                     $prixTotal $cell->getValue();
  308.                                 }
  309.                             }
  310.                         }
  311.                         
  312. //                        if($i == 0){
  313. //                            $restCommande[$collectuer] = 0;
  314. //                            
  315. //                        }
  316.                         //  if( stripos($numeroCommande, 'L')===FALSE){
  317.                         if ($collectuer != null) {
  318.                             
  319.                             $laDateComma $this->traiterInfoDate($dateCommande);
  320.                             
  321.                             
  322.                                 
  323.                             $objetCollecteur $this->ajouterCollecteur($em$collectuer,$zoneCommande);
  324.                             
  325.                             //var_dump($objetCollecteur->getId());    
  326.                             
  327.                               
  328.                             if ($operation == "Avance") {                                
  329.                                 $prixRig $this->ajouterPrix($em$prixUnitaire$objetProduit,$laDateComma);
  330.                                 $montantTotal = (int) $prixUnitaire * (int) $quantite;
  331.                                 $this->recuperationDeVille($em$zoneCommande$objetCollecteur);                                
  332.                                 $objetCommande $this->ajouterLaCommande($em$objetCollecteur$numeroCommande$laDateComma$montantTotal);
  333.                                 
  334.                                 $this->ajouterLaLigneCommande($em$objetCollecteur$objetCommande$montantTotal$quantite$objetProduit$prixRig);
  335.                                
  336.                             } elseif ($operation == "Livraison") {    
  337.                                  if(!array_key_exists($objetCollecteur->getId(), $restCommande)){
  338.                                         $restCommande[$objetCollecteur->getId()] = 0;  
  339.                                         //var_dump($objetCollecteur->getId());
  340.                                  }
  341.                                  
  342.                                 //$objetCommande = $this->ajouterLaCommande($em, $objetCollecteur, $liquidationCommande, $laDateComma, $montantTotal);
  343.                                 //var_dump($restCommande["'".$collectuer]."'");exit;  
  344.                                 //var_dump($rest&Commande[$objetCollecteur->getId()]);exit;
  345.                                 $restCommande[$objetCollecteur->getId()] = $this->ajouterLaLivraison($em$numeroCommande$quantite$laDateComma$collectuer$numeroCommande,$zoneCommande,$restCommande[$objetCollecteur->getId()]);
  346.                                 $this->upDateSurPlus($em$collectuer,$restCommande[$objetCollecteur->getId()]);    
  347.                                 
  348.                             }
  349.                             /*else {
  350.                                 $this->traiterAjustementCompte($em, $numeroCommande, $quantite, $prixUnitaire, $objetCollecteur, $objetProduit, $laDateComma);
  351.                             }*/
  352.                             $i++;
  353.                         }
  354.                         
  355.                     }
  356.                    
  357.                     $collectuer null;
  358.                     //Traitement des operations
  359.                     //Enregistrement des opérations des 
  360.                 }
  361.                 $em->getConnection()->commit();
  362.                 //$listeProduit = $em->getRepository($this->stockBundle . 'Produit')->getAllProduit();
  363.                 //$listeProduit = $em->getRepository($this->stockBundle . 'Produit')->getAllProduit();
  364.             } catch (\Exception $exc) {
  365.                 $em->getConnection()->rollBack();
  366.                 throw $exc;
  367.             }
  368.         $objetChemin->setEtatFichier(2);
  369.         $objetChemin->setTitreImage($objetChemin->getTitreImage());
  370.         $em->persist($objetChemin);
  371.         $em->flush();
  372.         /*
  373.          * Aller sur la page de la liste des fichiers 
  374.          */
  375.          return $this->redirect($this->generateUrl('admin_fichiers'));
  376.         
  377.     }
  378.     /**
  379.      * Methode s'occupant de l'ajout du produit.
  380.      *
  381.      * @author armand.tevi@gmail.com
  382.      * @copyright ADMIN 2015
  383.      *
  384.      * @version 1
  385.      * @return twig d'ajout d'un abonne ajouterproduit.html.twig
  386.      */
  387.     public function traterFichierDonneeResiduelExcelAction(Request $request$id) {
  388.         /*
  389.          * Nom de l'action en cours
  390.          */
  391.         $nomAction __FUNCTION__;
  392.         /*
  393.          * Description de l'action de l'action en cours
  394.          */
  395.         $descAction "Expoter le fichier excel comportant les avances et livraison des collecteurs ";
  396.         
  397.         $valRetour =$this->gestionDroitUtil($request$nomAction$descAction,$this->moduleTitre,$this->moduleDesc$loginManager,$paramRepositor,$connexionRepository$actionRepository$moduleRepository$controleurRepository$profilRepository );
  398.         if($valRetour==1){
  399.             return $this->redirect($this->generateUrl('app_logout'));
  400.         }elseif($valRetour==2){
  401.             return $this->redirect($this->generateUrl('app_admin_user_access_refuse'));
  402.         }
  403.         $em $this->getDoctrine()->getManager();
  404.         
  405.         $objetChemin $em->getRepository($this->stockBundle 'Fichier')->find($id);
  406.         
  407.         //Recuperation du chemin du fichier
  408.         $chenimFichierExcel __DIR__ '/../../../public/' $objetChemin->getTitreImage();
  409.         
  410.         $restCommande =array();                        
  411.         
  412.         $collectuer =null;
  413.         $objetProduit $em->getRepository($this->stockBundle 'Produit')->find(\Types\stock\TypeStock::IDPROD);
  414.         $em->getConnection()->beginTransaction();    
  415.             try {
  416.                 /*
  417.                  * Récupération des la liste des critères
  418.                  */
  419.                 $array_data = array();
  420.                 $XLSXDocument = new \PHPExcel_Reader_Excel2007();
  421.                 $Excel $XLSXDocument->load($chenimFichierExcel);
  422.                 // get all the row of my file
  423.                 $rowIterator $Excel->getActiveSheet()->getRowIterator();
  424.                 $i 0;
  425.                 foreach ($rowIterator as $row) {
  426.                     $cellIterator $row->getCellIterator();
  427.                     // Loop all cells, even if it is not set
  428.                     $cellIterator->setIterateOnlyExistingCells(false);
  429.                     $rowIndex $row->getRowIndex();
  430.                     
  431.                     $array_data[$rowIndex] = array('A' => '''B' => '''C' => '''D' => '''E' => '''F' => '''G' => '');
  432.                     if ($rowIndex >= $objetChemin->getDebutTraitement()) {
  433.                         
  434.                         //$Excel->ge('A' . $IndexLigne, $value);                        
  435.                         foreach ($cellIterator as $cell) {
  436.                             if ($cell->getValue() != null) {
  437.                                 if ('A' == $cell->getColumn()) {
  438.                                     $dateCommande $cell->getValue();                                    
  439.                                 } elseif ('B' == $cell->getColumn()) {
  440.                                     $sac $cell->getValue();
  441.                                 } elseif ('C' == $cell->getColumn()) {
  442.                                     $collectuer $cell->getValue();
  443.                                 } elseif ('D' == $cell->getColumn()) {
  444.                                     $nomCollecteur $cell->getValue();                                    
  445.                                 } elseif ('E' == $cell->getColumn()) {                                    
  446.                                     $quantite $cell->getValue();                                    
  447.                                 } elseif ('F' == $cell->getColumn()) {
  448.                                     $prixUnitaire $cell->getValue();
  449.                                 } elseif ('G' == $cell->getColumn()) {
  450.                                     $prixTotal $cell->getValue();
  451.                                 }
  452.                             }
  453.                         }                        
  454. //                        if($i == 0){
  455. //                            $restCommande[$collectuer] = 0;
  456. //                            
  457. //                        }$quantite
  458.                         //  if( stripos($numeroCommande, 'L')===FALSE){
  459.                         if ($collectuer != null) {
  460.                             
  461.                             $laDateComma $this->traiterInfoDate($dateCommande);
  462.                             
  463.                             $objetCollecteur $this->ajouterCollecteur($em$collectuer,$objetChemin->getVille()->getNomVille());
  464.                             
  465.                                 $numeroCommande "R".$objetChemin->getVille()->getNomVille()."_".$i;
  466.                             
  467.                                 $prixRig $this->ajouterPrix($em$prixUnitaire$objetProduit,$laDateComma);
  468.                                 $montantTotal = (int) $prixUnitaire * (int) $quantite;
  469.                                 $this->recuperationDeVille($em$objetChemin->getVille()->getNomVille(), $objetCollecteur);                                
  470.                                 $objetCommande $this->ajouterLaCommande($em$objetCollecteur$numeroCommande$laDateComma$montantTotal);                               
  471.                                 $infoCommande $this->ajouterLaLigneCommande($em$objetCollecteur$objetCommande$montantTotal$quantite$objetProduit$prixRig);                                                              
  472.                                 $this->ajouterLaLivraisonResiduelle($em$numeroCommande$quantite$laDateComma$collectuer$numeroCommande,$objetChemin->getVille()->getNomVille(),$infoCommande->getId());                                 
  473.                                 $i++;
  474.                         }
  475.                         
  476.                     }
  477.                    
  478.                     $collectuer null;
  479.                     //Traitement des operations
  480.                     //Enregistrement des opérations des 
  481.                 }
  482.                 $em->getConnection()->commit();
  483.                 //$listeProduit = $em->getRepository($this->stockBundle . 'Produit')->getAllProduit();
  484.                 //$listeProduit = $em->getRepository($this->stockBundle . 'Produit')->getAllProduit();
  485.             } catch (\Exception $exc) {
  486.                 $em->getConnection()->rollBack();
  487.                 throw $exc;
  488.             }
  489.         $objetChemin->setEtatFichier(2);
  490.         $objetChemin->setTitreImage($objetChemin->getTitreImage());
  491.         $em->persist($objetChemin);
  492.         $em->flush();
  493.         /*
  494.          * Aller sur la page de la liste des fichiers 
  495.          */
  496.          return $this->redirect($this->generateUrl('admin_fichiers'));
  497.         
  498.     }
  499.     public function ajouterCollecteur($em$nomCollecteur,$ville='Kpalimé') {
  500.         //objet collecteur
  501.         $criteria = array('codeFournisseur' => $nomCollecteur);
  502.         $unFournisseur $em->getRepository($this->stockBundle 'Fournisseur')->findOneBy($criteria);
  503.         if ($unFournisseur == null) {
  504.             $unFournisseur = new Fournisseur();
  505.             $unFournisseur->setCodeFournisseur($nomCollecteur);
  506.             $unFournisseur->setNomFournisseur($nomCollecteur);
  507.             $unFournisseur->setRessourceFournisseur($nomCollecteur);
  508.             $unFournisseur->setAdresseFournisseur($ville);
  509.             $unFournisseur->setEtatFournisseur(\Types\user\TypeEtat::ACTIF);
  510.             $unFournisseur->setContactFournisseur('0000000');
  511.             $unFournisseur->setDateModification(new \DateTime());
  512.             $unFournisseur->setDatePublication(new \DateTime());
  513.             $em->persist($unFournisseur);
  514.             $em->flush();            
  515.         }
  516.         return $unFournisseur;
  517.     }
  518.     public function ajouterPrix($em$prix$objetProduit,$laDateComma=null) {
  519.         //objet collecteur
  520.         $criteria = array('infoPrixRigueur' => $prix);
  521.         $ancienPrix $em->getRepository($this->stockBundle 'PrixRigueur')->findOneBy($criteria);
  522.         
  523.         if ($ancienPrix != null) {
  524.             $ancienPrix->setDatePublication($laDateComma);
  525.            
  526.         } else {
  527.             $this->initialiserAncienPrixZero($em0);
  528.             $ancienPrix = new \Entity\stock\PrixRigueur();
  529.             $ancienPrix->setInfoPrixRigueur($prix);
  530.             $ancienPrix->setDatePublication($laDateComma);
  531.             $ancienPrix->setProduit($objetProduit);
  532.             $ancienPrix->setEtatPrixRigueur(\Types\user\TypeEtat::INACTIF);
  533.             
  534.         }
  535.         $em->persist($ancienPrix);
  536.             $em->flush();
  537.             return $ancienPrix;
  538.     }
  539.     public function traiterInfoDate($date) {
  540.         //traitement
  541.         //$rest = substr("abcdef", -3, 1); 
  542.         $date $date 1;
  543.         $date date("m/d/y"mktime(0001$date1900));
  544.         $objetDate = new \DateTime($date);
  545.         // var_dump($objetDate);exit;
  546.         return $objetDate;
  547.     }
  548.     public function recuperationDeVille($em$nomVille$objetFournisseur) {
  549.         //var_dump($nomVille);exit;
  550.         $criteria = array('nomVille' => $nomVille);
  551.         $ville $em->getRepository($this->stockBundle 'Ville')->findOneBy($criteria);
  552.         if ($ville == null) {
  553.             $ville = new \Entity\stock\Ville();
  554.             $ville->setNomVille($nomVille);
  555.             $em->persist($ville);
  556.             $em->flush();
  557.         }
  558.         //recuperation de l'utilisateur
  559.         $criteriaUtil = array('ville' => $ville);
  560.         $utilisateur $em->getRepository($this->userBundle 'Utilisateur')->findOneBy($criteriaUtil);        
  561.         $criteriaSeTrouver = array('ville' => $ville'utilisateur' => $utilisateur'fournisseur' => $objetFournisseur );        
  562.         $seTrouve $em->getRepository($this->stockBundle 'SeTrouver')->findOneBy($criteriaSeTrouver);
  563.         
  564.         if($seTrouve == null){
  565.             //Enrégistrement pour lie utilisateur ville et collecteur
  566.             $seTrouve = new \Entity\stock\SeTrouver();
  567.             $seTrouve->setDateLivraison(new \DateTime());
  568.             $seTrouve->setFournisseur($objetFournisseur);
  569.             $seTrouve->setUtilisateur($utilisateur);
  570.             $seTrouve->setVille($ville);
  571.             $em->persist($seTrouve);
  572.             $em->flush();
  573.         }
  574.         return $seTrouve;
  575.     }
  576.     public function ajouterLaCommande($em$objetCollecteur$numeroCommande$objetDate$montantCommande) {
  577.        // $uneCommande = null;
  578.         
  579. //        //Verifier si la commande existe 
  580. //        $criteriaCode = array('codeCommande' => $numeroCommande, 'fournisseur' => $objetCollecteur);
  581. //        $uneCommande = $em->getRepository($this->stockBundle . 'Commande')->findOneBy($criteriaCode);
  582. //        if (count($uneCommande) == 0) {
  583.             $uneCommande = new \Entity\stock\Commande();
  584.             $uneCommande->setCodeCommande($numeroCommande);
  585.             $uneCommande->setRefBonCommande($numeroCommande);
  586.             $uneCommande->setFournisseur($objetCollecteur);
  587.             $uneCommande->setDateCommande($objetDate);
  588.             $uneCommande->setMontantCommande($montantCommande);
  589.             $uneCommande->setMontantResteCommande(0);
  590.             $uneCommande->setEtatCommande(\Types\user\TypeEtat::ACTIF);
  591.             $uneCommande->setDateModification(new \DateTime());
  592.             $uneCommande->setDatePublication(new \DateTime());
  593.             $em->persist($uneCommande);
  594.             $em->flush();
  595. //        }
  596.        
  597.         //traitement
  598.         return $uneCommande;
  599.     }
  600.     public function ajouterLaLigneCommande($em$objetCollecteur$objetCommande$montantCommande$quantiteCommande$objetProduit$objetPrix) {
  601.         $uneLigneCommande null;
  602.         if ($objetCommande != null) {
  603.             $uneLigneCommande = new \Entity\stock\LigneCommande();
  604.             $uneLigneCommande->setMontantAutreTaxe(0);
  605.             $uneLigneCommande->setCommande($objetCommande);
  606.             $uneLigneCommande->setFournisseur($objetCollecteur);
  607.             $uneLigneCommande->setProduit($objetProduit);
  608.             $uneLigneCommande->setMontantHt($montantCommande);
  609.             $uneLigneCommande->setPrixrigueur($objetPrix);
  610.             $uneLigneCommande->setQuantiteReste($quantiteCommande);
  611.             $uneLigneCommande->setQuantiteLivre(0);
  612.             $uneLigneCommande->setQuantite($quantiteCommande);
  613.             $uneLigneCommande->setEtatLigneCommande(\Types\user\TypeEtat::ACTIF);
  614.             $em->persist($uneLigneCommande);
  615.             $em->flush();
  616.         }
  617.         return $uneLigneCommande;
  618.     }
  619.     
  620.     public function traiterAjustementCompte($em$codeCommande,  $quantiteCommande$montantCommande$objetCollecteur,  $objetProduit,  $dateCommande) {
  621.         
  622.         
  623.        // var_dump(strpos($codeCommande, "REG/")); 
  624.         $prixActuel 0;
  625.         $codeCommande str_replace("REG/"""$codeCommande);
  626.        
  627.         $criteriaCode = array('codeCommande' => $codeCommande'fournisseur' => $objetCollecteur);
  628.         $objetCommande $em->getRepository($this->stockBundle 'Commande')->findOneBy($criteriaCode);
  629.         $criteriaLigneCom = array('commande' => $objetCommande'fournisseur' => $objetCollecteur'quantite' => $quantiteCommande);
  630.         $uneLigneCommande $em->getRepository($this->stockBundle 'LigneCommande')->getObjetLigneCommande($objetCollecteur->getId(), $quantiteCommande$dateCommande);
  631.         if(count($uneLigneCommande)!=0){
  632.             $uneLigneCommande $uneLigneCommande[0];
  633.         }
  634.         
  635.         if ($uneLigneCommande != null) {
  636.            // var_dump(strpos($codeCommande, "REG/"));exit;
  637.            $prixActuel = (int)$montantCommande+(int)$uneLigneCommande->getPrixRigueur()->getInfoPrixRigueur();
  638.             $dateJour = new \DateTime();
  639.             $objetPrix $this->ajouterPrix($em$prixActuel$objetProduit,$dateJour );
  640.             $uneLigneCommande->setPrixrigueur($objetPrix);
  641.             $uneLigneCommande->setTauxTva($montantCommande);
  642.             $em->persist($uneLigneCommande);
  643.             $em->flush();
  644.             //var_dump($codeCommande,$objetCollecteur->getNomFournisseur());
  645.             //exit;
  646.         }
  647.         return $uneLigneCommande;
  648.     }
  649.     public function ajouterLaLivraison($em$codeCommande$quantiteLivre$laDateComma=""$nomCollecteur=""$codeLivraison="",$ville ="Kpalime",$commandeReste) {
  650.         //objet collecteur
  651.         $resteAEnvoye 0;
  652.         $quantiteLivrerAEnregistre $quantiteLivre;
  653.         $quantiteLivre = (int) $quantiteLivre + (int)$this->recupererSurPlus($em$nomCollecteur);
  654.         $em->getConnection()->beginTransaction();
  655.         try {
  656.             
  657.             $ancienFournisseur $this->ajouterCollecteur($em$nomCollecteur,$ville);            
  658.             $arreter =1;
  659.             $uneLivraison null;
  660.             $infoLivrer = new \Entity\stock\InfoLivrer(); 
  661.             $infoLivrer->setNbreReste(0);
  662.             $infoLivrer->setNbreTotalLivre($quantiteLivre);
  663.             $infoLivrer->setRefBonLivraison($codeCommande);
  664.             $infoLivrer->setFournisseur($ancienFournisseur);
  665.             $infoLivrer->setRefBonReception($codeCommande);
  666.             $infoLivrer->setNbreSaisie($quantiteLivrerAEnregistre);
  667.             $infoLivrer->setDateLivraison($laDateComma);
  668.             $em->persist($infoLivrer);
  669.             $em->flush();       
  670.         
  671.                 
  672.         $LigneCommande $em->getRepository($this->stockBundle 'LigneCommande')->findBy(array('etatLigneCommande'=>1,'fournisseur'=>$ancienFournisseur));            
  673.            foreach ( $LigneCommande as $unObjetLigneCommande) {
  674.                 //var_dump($unObjetLigneCommande->getId());exit;
  675.                 if ($unObjetLigneCommande->getQuantiteReste() != 0) {                    
  676.                     $uneLivraison = new \Entity\stock\Livrer(); //Création de l'abjet Livrer
  677.                     if($arreter ==1){                        
  678.                         if ((int) $unObjetLigneCommande->getQuantiteReste() >= (int) $quantiteLivre) { //si La Quantite a livre est inférieur ou 
  679.                           // egale a la quantité commandée pour une commande
  680.                             //Calcul quantite totale
  681.                             $QuantiteTotal $unObjetLigneCommande->getQuantiteLivre() + $quantiteLivre;//Recuperation de la quantité total livrée pour le produit
  682.                             //set de la quantité total 
  683.                             $unObjetLigneCommande->setQuantiteLivre($QuantiteTotal);//Quant donné a l'objet  Ligne commande
  684.                             $uneLivraison->setNbreLivre($quantiteLivre);//On ecrit la quantité livre durant la livraison
  685.                             if ($unObjetLigneCommande->getQuantiteReste() == (int) $quantiteLivre) { //Si c'est pour soldé la livraison
  686.                                 //Tout les produits sont livrés Soldé                                       
  687.                                 $unObjetLigneCommande->setEtatLigneCommande(2);
  688.                                 //Mettre a jour la commande concenant ce produit
  689.                                 $this->mettreAJourCommande($em,$unObjetLigneCommande->getCommande()->getId());
  690.                                // $this->mettreAJourLigneCommande($em, $unObjetLigneCommande->getId());                                                                
  691.                                 $QuantiteTotalReste=0;
  692.                             } else {
  693.                                 $QuantiteTotalReste $unObjetLigneCommande->getQuantite() - $QuantiteTotal;   
  694.                             }
  695.                             $unObjetLigneCommande->setQuantiteReste($QuantiteTotalReste);
  696.                             $arreter =2;
  697.                             $quantiteLivre 0;
  698.                         } else { //Dans le cas ou la quantité a livrer est supérieur a ce qu'on doit livrer pour une commande
  699.                         
  700.                             //Recuperation de la quantité a livrer pour la commande
  701.                             $QteDoitLivrer $unObjetLigneCommande->getQuantite() - $unObjetLigneCommande->getQuantiteLivre();
  702.                             //Recuperation de la quantité  livrer
  703.                             //$QteLivrer = $unObjetLigneCommande->getQuantiteLivre()+$doitLivrer;
  704.                             
  705.                             $unObjetLigneCommande->setEtatLigneCommande(2); //Dans ca on solde a coup sur les livraisons
  706.                             $this->mettreAJourCommande($em,$unObjetLigneCommande->getCommande()->getId()); 
  707.                            // $this->mettreAJourLigneCommande($em, $unObjetLigneCommande->getId());
  708.                             $unObjetLigneCommande->setQuantiteLivre($unObjetLigneCommande->getQuantite());                            
  709.                            // $uneLivraison->setNbreLivre($unObjetLigneCommande->getQuantiteReste());//Rucuperation de la quantité livrer pour la commande
  710.                             $uneLivraison->setNbreLivre($QteDoitLivrer);//Rucuperation de la quantité livrer pour la commande
  711.                             $quantiteLivre $quantiteLivre $QteDoitLivrer;//$unObjetLigneCommande->getQuantiteReste();
  712.                             // var_dump($quantiteLivre,$unObjetLigneCommande->getId());exit;
  713.                             $unObjetLigneCommande->setQuantiteReste(0); //Comme on a tout livré On met la quantité restante a 0
  714.                             $QuantiteTotalReste=0;       
  715.                         }
  716.                          
  717.                         $em->persist($unObjetLigneCommande);
  718.                         $em->flush();
  719.                         
  720.                         $uneLivraison->setLignecommande($unObjetLigneCommande);
  721.                         $uneLivraison->setDateLivraison(new \DateTime());
  722.                         $uneLivraison->setEtatLivraison(1);
  723.                         $uneLivraison->setNbreReste($QuantiteTotalReste);
  724.             $uneLivraison->setNombreRestantLivrer($QuantiteTotalReste);
  725.                         $uneLivraison->setInfolivrer($infoLivrer);
  726.                         $uneLivraison->setRefBonLivraison('L'.$unObjetLigneCommande->getCommande()->getCodeCommande());
  727.                         $uneLivraison->setRefBonReception('L'.$unObjetLigneCommande->getCommande()->getCodeCommande());                       
  728.                         $em->persist($uneLivraison);
  729.                         $em->flush();
  730.                        
  731.                     }
  732.                 }
  733.             }
  734.             $em->getConnection()->commit();
  735.         } catch (Exception $exc) {
  736.             $em->getConnection()->rollBack();
  737.             throw $exc;
  738.         }
  739.                                 
  740.         return $quantiteLivre;
  741.     }
  742.     public function ajouterLaLivraisonResiduelle($em$codeCommande$quantiteLivre$laDateComma=""$nomCollecteur=""$codeLivraison="",$ville ="Kpalime",$idLigneCommande) {
  743.         //objet collecteur
  744.         
  745.         $em->getConnection()->beginTransaction();
  746.         try {
  747.             
  748.             $ancienFournisseur $this->ajouterCollecteur($em$nomCollecteur,$ville);            
  749.             $arreter =1;
  750.             $uneLivraison = new \Entity\stock\Livrer(); //Création de l'abjet Livrer
  751.             $infoLivrer = new \Entity\stock\InfoLivrer(); 
  752.             $infoLivrer->setNbreReste(0);
  753.             $infoLivrer->setNbreTotalLivre($quantiteLivre);
  754.             $infoLivrer->setRefBonLivraison($codeCommande);
  755.             $infoLivrer->setFournisseur($ancienFournisseur);
  756.             $infoLivrer->setRefBonReception($codeCommande);
  757.             $infoLivrer->setNbreSaisie($quantiteLivre);
  758.             $infoLivrer->setDateLivraison($laDateComma);
  759.             $em->persist($infoLivrer);
  760.             $em->flush();               
  761.                 
  762.                         $unObjetLigneCommande $em->getRepository($this->stockBundle 'LigneCommande')->find($idLigneCommande);            
  763.                         $unObjetLigneCommande->setQuantiteLivre($unObjetLigneCommande->getQuantite());
  764.                         $unObjetLigneCommande->setEtatLigneCommande(2); 
  765.                         $em->persist($unObjetLigneCommande);                        
  766.                         $em->flush();
  767.                         $this->mettreAJourCommande($em,$unObjetLigneCommande->getCommande()->getId());
  768.                         
  769.                         $uneLivraison->setLignecommande($unObjetLigneCommande);
  770.                         $uneLivraison->setDateLivraison(new \DateTime());
  771.                         $uneLivraison->setEtatLivraison(1);
  772.                         $uneLivraison->setNbreReste(0);
  773.                         $uneLivraison->setNbreLivre($quantiteLivre);
  774.             $uneLivraison->setNombreRestantLivrer(0);
  775.                         $uneLivraison->setInfolivrer($infoLivrer);
  776.                         $uneLivraison->setRefBonLivraison('L'.$unObjetLigneCommande->getCommande()->getCodeCommande());
  777.                         $uneLivraison->setRefBonReception('L'.$unObjetLigneCommande->getCommande()->getCodeCommande());                       
  778.                         $em->persist($uneLivraison);
  779.                         $em->flush();
  780.                        
  781.             $em->getConnection()->commit();
  782.         } catch (Exception $exc) {
  783.             $em->getConnection()->rollBack();
  784.             throw $exc;
  785.         }
  786.                                 
  787.         return $quantiteLivre;
  788.     }
  789.     /**
  790.      * Methode s'occupant de lister les Operations.
  791.      *
  792.      * @author armand.tevi@gmail.com
  793.      * @copyright ADMIN 2015
  794.      *
  795.      * @version 1
  796.      *
  797.      * @return twig d'ajout d'un abonne listeOperation.html.twig
  798.      */
  799.     public function exportOpertionAction(Request $request$type$etat$nomcol$datefin$datedeb$ville$util$silivre$numcom) {
  800.         //$session = $this->getRequest()->getSession();
  801.         $sessionData $this->infosConnecte($request$loginManager$paramRepositor,$connexionRepository$actionRepository);;
  802.         $prod $sessionData["produit_id"];
  803.         //var_dump($prod);exit;
  804.         $em $this->getDoctrine()->getManager();
  805.         //var_dump($currentConnete["listeActions_abonne"]);exit;
  806.         global $listeOperation$articles_per_page$last_page$previous_page$next_page$total;
  807.         //$typeOperation = $em->getRepository("adminStockBundle:TypeOperation")->findAll();
  808.         $total 10//$em->getRepository("adminStockBundle:Operation")->getTotalOperationsBrouillard($caisse, $datedeb, $datefin, $typeop, $typedate);
  809.         $listeOperation $em->getRepository($this->stockBundle 'Commande')->getListeRechercheCommande($nomcol$datefin$datedeb$ville$util$silivre$numcom,$prod);
  810.         $listeOperation3 $em->getRepository($this->stockBundle 'Commande')->getListeRechercheCommande($nomcol$datefin$datedeb$ville$util$silivre$numcom,$prod);
  811.         $listeOperation2 $em->getRepository($this->stockBundle 'Commande')->getListeRechercheInfoTotalCommande($nomcol$datefin$datedeb$ville$util$silivre$numcom,$prod);
  812.         
  813.         $excelService = new PHPExcel();
  814.         $excelService->getProperties()
  815.                 ->setTitle("DETAILS DES OPERATIONS DE GESTIONS DES AVANCES ET DE LIVRAISON DES COLLECTES DE CACAO ")
  816.                 ->setDescription("DETAILS DES OPERATIONS DE GESTIONS DES AVANCES ET DE LIVRAISON DES COLLECTES DE CACAO");
  817.         $excelService->getActiveSheet()->setTitle('Liste des Operations ');
  818.         $excelService->setActiveSheetIndex(0);
  819.         $lesCriteres $this->RecuperCritereRecherche($em$nomcol,   $datefin,$datedeb,  $ville$util$silivre$numcom);
  820.         //create the response
  821.         $excelService->setActiveSheetIndex(0)
  822.                 ->setCellValue('A1''')//DETAILS DES OPERATIONS DE GESTIONS DES AVANCES ET DE LIVRAISON DES COLLECTES DE CACAO
  823.                 ->setCellValue('B1''')
  824.                 ->setCellValue('C1''')
  825.                 ->setCellValue('E1''')
  826.                 ->setCellValue('F1''')
  827.                 ->setCellValue('G1''')
  828.                 ->setCellValue('H1''')
  829.                 ->setCellValue('I1''')
  830.                 ->setCellValue('J1''')
  831.                 ->setCellValue('K1''')
  832.                 ->setCellValue('L1''')
  833.                 ->setCellValue('M1''')
  834.                 ->setCellValue('N1''');
  835.                 
  836.         $excelService->setActiveSheetIndex(0)
  837.                 ->setCellValue('A3''Collecteur :')
  838.                 ->setCellValue('B3',$lesCriteres['nomCollecteur']);
  839.         $excelService->setActiveSheetIndex(0)
  840.                 ->setCellValue('A4''Ville :')
  841.                 ->setCellValue('B4'$lesCriteres['nomVille']);
  842.         $excelService->setActiveSheetIndex(0)
  843.                 ->setCellValue('A5''Gérant :')
  844.                 ->setCellValue('B5'$lesCriteres['nomGerant']);
  845.         
  846.         $excelService->setActiveSheetIndex(0)
  847.                 ->setCellValue('A6''Stuat. livrée :')
  848.                 ->setCellValue('B6'$lesCriteres['livre']);
  849.         
  850.         $excelService->setActiveSheetIndex(0)
  851.                 ->setCellValue('A7''Date début :')
  852.                 ->setCellValue('B7'$lesCriteres['dateDebut']);
  853.         
  854.         $excelService->setActiveSheetIndex(0)
  855.                 ->setCellValue('A8''Date fin')
  856.                 ->setCellValue('B8'$lesCriteres['dateFin']);
  857.         $excelService->setActiveSheetIndex(0)
  858.                 ->setCellValue('A10''N')
  859.                 ->setCellValue('B10''Liquidations')
  860.                 ->setCellValue('C10''Date')
  861.                 ->setCellValue('D10''Mois')
  862.                 ->setCellValue('E10''Année')
  863.                 ->setCellValue('F10''Zone')
  864.                 ->setCellValue('G10''Collecteurs')
  865.                 ->setCellValue('H10''Opérations')
  866.                 ->setCellValue('I10''Quantité')
  867.                 ->setCellValue('J10''Avce')
  868.                 ->setCellValue('K10''Livrée')
  869.                 ->setCellValue('L10''PU')
  870.                 ->setCellValue('M10''MONTANT');
  871.         
  872.         $aux 11;
  873.         
  874.         if ($type == 1) {
  875.             //var_dump(count($listeOperation),count($listeOperation));exit;
  876.             foreach ($listeOperation2 as $row) {
  877.                 $datop null;
  878.                 $daval null;
  879.                 
  880.                 if($row['typeOperation'] == 1){
  881.                 
  882.                 $excelService->setActiveSheetIndex(0)
  883.                         ->setCellValue('A' $aux$row['code']) //$row['dateOperation']
  884.                         ->setCellValue('B' $aux$row['codeCommandeLivraison'])
  885.                         ->setCellValue('C' $aux$row['date']->format("d/M/Y"))
  886.                         ->setCellValue('D' $aux$row['date']->format("m"))//$row['dateValeur']
  887.                         ->setCellValue('E' $aux$row['date']->format("Y"))
  888.                         ->setCellValue('F' $aux$row['zone'])
  889.                         ->setCellValue('G' $aux$row['collecteur'])
  890.                         ->setCellValue('H' $aux'Avance')
  891.                         ->setCellValue('I' $aux$row['quantite'])
  892.                         ->setCellValue('J' $aux$row['quantite'])
  893.                         ->setCellValue('K' $aux'')
  894.                         ->setCellValue('L' $aux$row['prixUnitaire'])
  895.                         ->setCellValue('M' $aux'-')
  896.                 ;
  897.                 
  898.                 }else{
  899.                      $excelService->setActiveSheetIndex(0)
  900.                         ->setCellValue('A' $aux$row['code']) //$row['dateOperation']
  901.                         ->setCellValue('B' $aux$row['codeCommandeLivraison'])
  902.                         ->setCellValue('C' $aux$row['date']->format("d/M/Y"))
  903.                         ->setCellValue('D' $aux$row['date']->format("m"))//$row['dateValeur']
  904.                         ->setCellValue('E' $aux$row['date']->format("Y"))
  905.                         ->setCellValue('F' $aux$row['zone'])
  906.                         ->setCellValue('G' $aux$row['collecteur'])
  907.                         ->setCellValue('H' $aux'Livraison')
  908.                         ->setCellValue('I' $aux$row['quantite'])
  909.                         ->setCellValue('J' $aux"")
  910.                         ->setCellValue('K' $aux$row['quantite'])
  911.                         ->setCellValue('L' $aux$row['prixUnitaire'])
  912.                         ->setCellValue('M' $aux'-');   
  913.                 }
  914.                 $this->applyStyleCell($excelService$aux);
  915.                 $aux++;
  916.                 
  917.                 $this->cellAutoSize($excelService);
  918.                 // Set active sheet index to the first sheet
  919.                 
  920.                 $excelService->getActiveSheet()->getStyle('M' $aux)->getNumberFormat()->applyFromArray(
  921.                         array(
  922.                             'code' => '# ### ### ### ###_-'
  923.                         )
  924.                 );
  925.                 
  926.             }
  927.             $response = new Response();
  928. //        
  929.         //elseif ($imprimer == 1) {
  930.         if ($type == 1) {           
  931.             //$response = $excelService->getResponse();
  932.             $response->headers->set('Content-Type''text/vnd.ms-excel; charset=utf-8');
  933.             $response->headers->set('Content-Disposition''attachment;filename=fichier_excel_operation_gestion_collect-' date("Y_m_d_His") . '.xls');
  934.             //$response->prepare();            
  935.             $response->sendHeaders();
  936.             $objWriter PHPExcel_IOFactory::createWriter($excelService'Excel5');
  937.             $objWriter->save('php://output');
  938.             exit();
  939.         }
  940.          
  941.         if ($type == 5) {
  942. //            var_dump(count($listeOperation2));exit;
  943.             foreach ($listeOperation3 as $row) {
  944.                 $datop null;
  945.                 $daval null;
  946.                
  947.                 
  948. //                if($row['typeOperation'] == 1){
  949.                 //var_
  950.                 $excelService->setActiveSheetIndex(0)
  951.                         ->setCellValue('A' $aux$row->getDateCommande()->format("d/m/Y")) //$row['dateOperation']
  952.                         ->setCellValue('B' $aux$row->getCodeCommande())
  953.                         ->setCellValue('C' $aux'')
  954.                         ->setCellValue('D' $aux'')//$row['dateValeur']
  955.                         ->setCellValue('E' $aux'')
  956.                         ->setCellValue('F' $aux$row->getLigneCommandes()[0]->getQuantite()*$row->getLigneCommandes()[0]->getPrixRigueur()->getInfoPrixRigueur())
  957.                         ->setCellValue('G' $aux'')
  958.                         ->setCellValue('H' $aux'')
  959.                         ->setCellValue('I' $aux'Avance à '.$row->getFournisseur()->getNomFournisseur())
  960.                         ->setCellValue('J' $aux'')
  961.                         ->setCellValue('K' $aux'')
  962.                         ->setCellValue('L' $aux'')
  963.                         ->setCellValue('M' $aux'')
  964.                 ;
  965.                 
  966.                 
  967.                 $this->applyStyleCell($excelService$aux);
  968.                 $aux++;
  969.                 
  970.                 $this->cellAutoSize($excelService);
  971.                 // Set active sheet index to the first sheet
  972.                 
  973.                 $excelService->getActiveSheet()->getStyle('M' $aux)->getNumberFormat()->applyFromArray(
  974.                         array(
  975.                             'code' => '# ### ### ### ###_-'
  976.                         )
  977.                 );
  978.                 $excelService->getActiveSheet()
  979.                     ->getStyle('A' $aux)
  980.                     ->getNumberFormat()
  981.                     ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH);
  982.             }
  983.             $response = new Response();
  984. //        
  985.         //elseif ($imprimer == 1) {
  986.         if ($type == 5) {           
  987.             //$response = $excelService->getResponse();
  988.             $response->headers->set('Content-Type''text/vnd.ms-excel; charset=utf-8');
  989.             $response->headers->set('Content-Disposition''attachment;filename=fichier_excel_operation_gestion_collect-' date("Y_m_d_His") . '.xls');
  990.             //$response->prepare();            
  991.             $response->sendHeaders();
  992.             $objWriter PHPExcel_IOFactory::createWriter($excelService'Excel5');
  993.             $objWriter->save('php://output');
  994.             exit();
  995.         }
  996.         // Quand le telechargement doit etre en csv
  997.         elseif ($type == 2) {
  998.             $this->data['listeCommande'] = $listeOperation;
  999.             $this->data['lesCriteres'] = $lesCriteres;
  1000.             return $this->render($this->stockBundleSlash($sessionData['typePresentation']). '/Operation/impressionLigneCommande.html.twig'$this->data$this->response);
  1001.         }
  1002.         // Quand le telechargement doit etre en fichier txt
  1003.         elseif ($type == 3) {
  1004.             $aux 0;
  1005.             $handle fopen('php://memory''r+');
  1006.             $header = array();
  1007.             $donneperation null;
  1008.             $donneperation = array();
  1009.             $i 0;
  1010.             $separateur chr(9);
  1011.             foreach ($listeOperation as $operation) {
  1012.                 $donneperation[$i] = "" $operation['dateOperation']->format("d/m/Y") . "" $separateur "" $operation['numMvt'] . "" $separateur "" $operation['libOperation'] . "" $separateur "" $operation['montant'] . "\r\n";
  1013.                 //var_dump($donneperation[$i]);exit;
  1014.                 fputcsv($handle$donneperation);
  1015.                 $i++;
  1016.             }
  1017.             $response $this->render('adminStockBundle:Operation:export_txt.html.twig', array('donneperation' => $donneperation), $this->response);
  1018.             $filename "export_" date("Y_m_d_His") . ".txt";
  1019.             $response->headers->set('Content-Type''text/txt');
  1020.             $response->headers->set('Content-Disposition''attachment; filename=' $filename);
  1021.             return $response;
  1022.         }
  1023.         // Quand le telechargement doit etre en fichier pdf
  1024.         elseif ($type == 4) {
  1025.             ob_start();
  1026.             $donneperation $this->get('templating')->render('adminStockBundle:Operation:impression.html.twig', array('locale' => $locale'listeOperation' => $listeOperation));
  1027.             $html2pdf = new HTML2PDF('P''A4''fr');
  1028.             $html2pdf->WriteHTML($donneperationtrue);
  1029.             exit;
  1030.             $fichier $html2pdf->Output('exemple.pdf');
  1031.             $response = new Response();
  1032.             $response->clearHttpHeaders();
  1033.             $response->setContent(file_get_contents($fichier));
  1034.             $response->headers->set('Content-Type''application/force-download');
  1035.             $response->headers->set('Content-disposition''filename=' $fichier);
  1036.             return $response;
  1037.         } elseif ($type == 10) {
  1038.             return $this->render('adminStockBundle:operation:brouillardCaisse.html.twig');
  1039.         }
  1040.     }
  1041.     /**
  1042.      * Methode s'occupant 'afficher la ligne d'une commande.
  1043.      *
  1044.      * @author armand.tevi@gmail.com
  1045.      * @copyright ADMIN 2015
  1046.      *
  1047.      * @version 1
  1048.      *
  1049.      * @return twig d'ajout d'un abonne detailOperation.html.twig
  1050.      */
  1051.     public function getInfoCommandeAction(Request $requestLoginManager $loginManager,ParamRepository $paramRepositor,ConnexionRepository $connexionRepository,ActionRepository $actionRepository,
  1052.     ModuleRepository $moduleRepository,ControleurRepository $controleurRepository,AbonneRepository $abonneRepository,ProfilRepository $profilRepository,OperationManager $operationManager) {
  1053.         $rep = array('etat' => 0'msg' => 'Operation bien reussi''logout' => FALSE);
  1054.         /*
  1055.          * Nom de l'action en cours
  1056.          */
  1057.         $nomAction __FUNCTION__;
  1058.         /*
  1059.          * Description de l'action de l'action en cours
  1060.          */
  1061.         $descAction "recuperation de la liste des operations d'une commande";
  1062.         /*
  1063.          * Préparation du message de log 
  1064.          */
  1065.         $this->logMessage .= ' [ ' $nomAction ' ] ';
  1066.         /*
  1067.          * Service de gestion des droits
  1068.          */
  1069.         
  1070.         /*
  1071.          * Informations de session
  1072.          */
  1073.         $sessionData $this->infosConnecte($request$loginManager$paramRepositor,$connexionRepository$actionRepository);;
  1074.         /*
  1075.          * Locale en cours
  1076.          */
  1077.         $locale $loginManager->getLocale();
  1078.         $this->data['locale'] = $locale;
  1079.         /*
  1080.          * On vérifie si l'utilisateur est connecté
  1081.          */
  1082.         $status $loginManager->isConnecte($nomAction$paramRepositor,$connexionRepository$actionRepository);
  1083.         if ($status['isConnecte']) {
  1084.             /*
  1085.              * Au cas ou l'utilisateur est connecté on vérifie s'il nest pas innactif. S'il est innactif
  1086.              * on garde en mémoire flash la route actuelle pour effectuer une redirection lors de la prochaine connexion
  1087.              */
  1088.             if ($status['isInnactif']) {
  1089.                 $rep['msg'] = "Vous avez accusé un long moment d'inactivité. Veuillez-vous connecter de nouveau";
  1090.                 $loginManager->logout(LoginManager::SESSION_DATA_NAME);
  1091.                 return new Response(json_encode($rep));
  1092.             }
  1093.             /*
  1094.              * Seuls les utilisateurs admins ont le droit d'acceder à cette action
  1095.              */
  1096.             if (!$status['isUser']) {
  1097.                 return new Response(json_encode($rep));
  1098.             }
  1099.         } else {
  1100.             $rep['msg'] = "Vous êtes déconnecté. Veuillez-vous connecter de nouveau";
  1101.             return new Response(json_encode($rep));
  1102.         }
  1103.         /*
  1104.          * Gestion des droits
  1105.          */
  1106.         if (!$loginManager->getOrSetActions(Module::MOD_GEST_FOURModule::MOD_GEST_FOUR_DESC$this->getNomClassRun(__CLASS__), $this->description$nomAction$descAction$sessionData['idProfil'], $moduleRepository$controleurRepository$actionRepository$profilRepository)) {
  1107.             $this->logMessage .= ' [ TENTATIVE DE VIOLATION DE DROITS ] ';
  1108.             $rep['msg'] = "Vous n'avez pas le droit de recuperer la liste des operations d'une commande";
  1109.             return new Response(json_encode($rep));
  1110.         }
  1111.         /*
  1112.          * Traitement de la requete qui vient de la vue
  1113.          * on vérifie si la requete est Ajax et si la methode est post
  1114.          */
  1115.         if (($request->isXmlHttpRequest()) && ($request->getMethod() == 'POST')) {
  1116.             //Recuperation du code de la commande 
  1117.             $codeCommande $request->get('code');
  1118.             $type $request->get('type');
  1119.             $em $this->getDoctrine()->getManager();
  1120.             /*
  1121.              * Service de gestion des caisse
  1122.              */
  1123.             //$operationManager = $this->get('operation_manager');
  1124.             //  var_dump($type);exit;   
  1125.             $listeLigneCommande $operationManager->getListeLigneCommande($codeCommande$type);
  1126.             //var_dump($listeLigneCommande);exit;
  1127.             if (count($listeLigneCommande) != 0) {
  1128.                 //$em->getRepository($this->stockBundle . 'Commande')->getInformationCommande($codeCommande);
  1129.                 $rep['reponse'] = $listeLigneCommande;
  1130.                 // var_dump($listeLigneCommande);exit;
  1131.                 $rep['etat'] = 1;
  1132.             }
  1133.         }
  1134.         return new Response(json_encode($rep));
  1135.     }
  1136.     /* @copyright ADMIN 2015
  1137.      *
  1138.      * @version 1
  1139.      *
  1140.      * @return twig d'ajout d'un abonne detailOperation.html.twig
  1141.      */
  1142.     public function getListeOperationCommandeAjaxAction(Request $request,  LoginManager $loginManager,ParamRepository $paramRepositor,ConnexionRepository $connexionRepository,ActionRepository $actionRepository,
  1143.     ModuleRepository $moduleRepository,ControleurRepository $controleurRepository,AbonneRepository $abonneRepository,ProfilRepository $profilRepository,OperationManager $operationManagerCommandeRepository $commandeRepository,
  1144.     LigneCommandeRepository $ligneCommandeRepositoryInventaireRepository $inventaireRepository  ) {
  1145.         $rep = array('etat' => 0'msg' => 'Operation bien reussi''logout' => FALSE);
  1146.         /*
  1147.          * Nom de l'action en cours
  1148.          */
  1149.         $nomAction __FUNCTION__;
  1150.         /*
  1151.          * Description de l'action de l'action en cours
  1152.          */
  1153.         $descAction "recuperation de la liste des operations d'une commande";
  1154.         /*
  1155.          * Préparation du message de log 
  1156.          */
  1157.         $this->logMessage .= ' [ ' $nomAction ' ] ';
  1158.         /*
  1159.          * Service de gestion des droits
  1160.          */
  1161.         
  1162.         /*
  1163.          * Informations de session
  1164.          */
  1165.         $sessionData $this->infosConnecte($request$loginManager$paramRepositor,$connexionRepository$actionRepository);;
  1166.         /*
  1167.          * Locale en cours
  1168.          */
  1169.         $locale $loginManager->getLocale();
  1170.         $this->data['locale'] = $locale;
  1171.         /*
  1172.          * On vérifie si l'utilisateur est connecté
  1173.          */
  1174.         $status $loginManager->isConnecte($nomAction$paramRepositor,$connexionRepository$actionRepository);
  1175.         if ($status['isConnecte']) {
  1176.             /*
  1177.              * Au cas ou l'utilisateur est connecté on vérifie s'il nest pas innactif. S'il est innactif
  1178.              * on garde en mémoire flash la route actuelle pour effectuer une redirection lors de la prochaine connexion
  1179.              */
  1180.             if ($status['isInnactif']) {
  1181.                 $rep['msg'] = "Vous avez accusé un long moment d'inactivité. Veuillez-vous connecter de nouveau";
  1182.                 $loginManager->logout(LoginManager::SESSION_DATA_NAME);
  1183.                 return new Response(json_encode($rep));
  1184.             }
  1185.             /*
  1186.              * Seuls les utilisateurs admins ont le droit d'acceder à cette action
  1187.              */
  1188.             if (!$status['isUser']) {
  1189.                 return new Response(json_encode($rep));
  1190.             }
  1191.         } else {
  1192.             $rep['msg'] = "Vous êtes déconnecté. Veuillez-vous connecter de nouveau";
  1193.             return new Response(json_encode($rep));
  1194.         }
  1195.         /*
  1196.          * Gestion des droits
  1197.          */
  1198.         if (!$loginManager->getOrSetActions(Module::MOD_GEST_FOURModule::MOD_GEST_FOUR_DESC$this->getNomClassRun(__CLASS__), $this->description$nomAction$descAction$sessionData['idProfil'], $moduleRepository$controleurRepository$actionRepository$profilRepository)) {
  1199.             $this->logMessage .= ' [ TENTATIVE DE VIOLATION DE DROITS ] ';
  1200.             $rep['msg'] = "Vous n'avez pas le droit de recuperer la liste des operations d'une commande";
  1201.             return new Response(json_encode($rep));
  1202.         }
  1203.         $tabLivrer = array();
  1204.         $tabLigneCommande = array();
  1205.         /*
  1206.          * Traitement de la requete qui vient de la vue
  1207.          * on vérifie si la requete est Ajax et si la methode est post
  1208.          */
  1209.         if (($request->isXmlHttpRequest()) && ($request->getMethod() == 'POST')) {
  1210.             //Recuperation du code de la commande 
  1211.             $idCommande $request->get('idcommande');
  1212.             $idAbonne $request->get('idabonne');
  1213.             $em $this->getDoctrine()->getManager();
  1214.             /*
  1215.              * Service de gestion des caisse
  1216.              */
  1217.             //$operationManager = $this->get('operation_manager');
  1218.             // $listeLigneCommande =  $em->getRepository($this->stockBundle . 'Operation')->getOperationsCaisseBrouillard(0, 1,0, 0, 0,$idCommande, $idAbonne,'CPTE001', '0')  ;
  1219.             $detailCommande $commandeRepository->getOneCommande($idCommande);
  1220.             $j 0;
  1221.             $tabInfoGeneral = array();
  1222.             foreach ($detailCommande[0]->getLigneCommandes() as $uneLigneCommande) {
  1223.                 $i 0;
  1224.                 $prixTotalReel 0;
  1225.                 $prixLivrer 0;
  1226.                 $reference 0;
  1227.                 $totalLivre 0;
  1228.                 foreach ($uneLigneCommande->getLivrers() as $uneLivraison) {
  1229.                         $tabLivrer[$uneLigneCommande->getId()][$i]['nbreLivre'] = $uneLivraison->getNbreLivre();
  1230.                         $tabLivrer[$uneLigneCommande->getId()][$i]['dateLivraison'] = $uneLivraison->getDateLivraison();
  1231.                         $tabLivrer[$uneLigneCommande->getId()][$i]['nbreReste'] = $uneLivraison->getNbreReste();
  1232.                         $tabLivrer[$uneLigneCommande->getId()][$i]['ref'] = $uneLivraison->getRefBonLivraison();
  1233.                         $tabLivrer[$uneLigneCommande->getId()][$i]['prixUnitaire'] = $uneLivraison->getLigneCommande()->getPrixrigueur()->getInfoPrixRigueur();
  1234.                         $prixTotal = (int) $uneLivraison->getNbreLivre() * $uneLivraison->getLigneCommande()->getPrixrigueur()->getInfoPrixRigueur();
  1235.                         $tabLivrer[$uneLigneCommande->getId()][$i]['prixTotal'] = (String) $prixTotal;
  1236.                         $i++;
  1237.                         $reference $uneLivraison->getRefBonLivraison();
  1238.                         $prixTotalReel $prixTotalReel $prixTotal;
  1239.                         $prixLivrer $uneLivraison->getPrixrigueur()->getInfoPrixRigueur();
  1240.                         $totalLivre $totalLivre $uneLivraison->getNbreLivre();
  1241.                 }
  1242.                 //Get Information dernierre commande
  1243.                 $ligneDernCommande $ligneCommandeRepository->findOneby(['produit'=>$uneLigneCommande->getProduit(),'suivantCommande'=>$uneLigneCommande->getId()]);
  1244.                 $tabLigneCommande[$j]["id"] = $uneLigneCommande->getId();
  1245.                 $tabLigneCommande[$j]["produit"] = $uneLigneCommande->getProduit()->getNomProduit();
  1246.                 $tabLigneCommande[$j]["produitId"] = $uneLigneCommande->getProduit()->getId();
  1247.                 $tabLigneCommande[$j]["siHeritage"] = $uneLigneCommande->getProduit()->isSiHeritage();
  1248.                 if($ligneDernCommande != null){
  1249.                     $tabLigneCommande[$j]["oldQuantite"] = $ligneDernCommande->getQuantite();
  1250.                     $tabLigneCommande[$j]["oldDateCommande"] = $ligneDernCommande->getCommande()->getDateCommande()->format("d/m/Y");
  1251.                     if($ligneDernCommande->getPrixRigueur() != null )
  1252.                         $tabLigneCommande[$j]["oldPrix"] = $ligneDernCommande->getPrixRigueur()->getInfoPrixRigueur();
  1253.                     else
  1254.                         $tabLigneCommande[$j]["oldPrix"] = "-";
  1255.                 }else{
  1256.                     $tabLigneCommande[$j]["oldQuantite"] = "-";
  1257.                     $tabLigneCommande[$j]["oldDateCommande"] = "-";
  1258.                     $tabLigneCommande[$j]["oldPrix"] = "-";
  1259.                 }
  1260.                 $inventaire $inventaireRepository->findOneBy(["etatInventaire"=>1"produit"=>$uneLigneCommande->getProduit()]);
  1261.                 if($inventaire != null){
  1262.                     $tabLigneCommande[$j]["inventaire"] =  $inventaire->getQuantiteSaisie() ;
  1263.                     $tabLigneCommande[$j]["dateInventaire"] =  $inventaire->getDateInventaire()->format("d/m/Y"); 
  1264.                     $dateInventaire $inventaire->getDateInventaire()->format("d/m/Y");
  1265.                 }else{
  1266.                     $tabLigneCommande[$j]["inventaire"] =  ;
  1267.                     $tabLigneCommande[$j]["dateInventaire"] =  "-";
  1268.                     $dateInventaire 0;
  1269.                 }
  1270.                 $inventaireA $inventaireRepository->findOneBy( ["lignecommande"=>$ligneDernCommande]);
  1271.                 if($inventaireA != null){
  1272.                     $tabLigneCommande[$j]["inventaireA"] =  $inventaireA->getQuantiteSaisie() ;
  1273.                     $tabLigneCommande[$j]["dateInventaireA"] =  $inventaireA->getDateInventaire()->format("d/m/Y"); 
  1274.                     //$dateInventaire = $inventaireA->getDateInventaire()->format("d/m/Y");
  1275.                 }else{
  1276.                     $tabLigneCommande[$j]["inventaireA"] =  ;
  1277.                     $tabLigneCommande[$j]["dateInventaireA"] =  "-";
  1278.                     //$dateInventaire = 0;
  1279.                 }
  1280.                 if($uneLigneCommande->getLivrers()[0] != null)
  1281.                      $tabLigneCommande[$j]["quantite"] = $uneLigneCommande->getLivrers()[0]->getNbreLivre();
  1282.                 else
  1283.                     $tabLigneCommande[$j]["quantite"] = $uneLigneCommande->getQuantite();
  1284.                 $tabLigneCommande[$j]["dateCommande"] = $detailCommande[0]->getDateCommande()->format("d/m/Y");
  1285.                 if($uneLigneCommande->getLivrers()[0] != null)
  1286.                     $tabLigneCommande[$j]["prix"] = $uneLigneCommande->getLivrers()[0]->getPrixRigueur()->getInfoPrixRigueur();
  1287.                 else
  1288.                     $tabLigneCommande[$j]["prix"] = $uneLigneCommande->getPrixRigueur()->getInfoPrixRigueur();
  1289.                 //$tabLigneCommande[$j]["prix"] = $uneLigneCommande->getPrixRigueur()->getInfoPrixRigueur();
  1290.                 $tabLigneCommande[$j]["nombreLivrer"] = $totalLivre ;
  1291.                 
  1292.                 $portion$commandeRepository->getPortionProduit(0,$dateInventaire $detailCommande[0]->getDateCommande()->format("d/m/Y"), 0000,0,4,20,1,4,$sessionData["abonneId"],0,$uneLigneCommande->getProduit()->getId());//$uneVille->getId()
  1293.                 $tabLigneCommande[$j]["portion"] = $portion;
  1294.                 //var_dump($portion);exit;
  1295.                 if($prixLivrer == 0)
  1296.                         $tabLigneCommande[$j]["nombrePrix"] = $uneLigneCommande->getPrixRigueur()->getInfoPrixRigueur();
  1297.                 else
  1298.                         $tabLigneCommande[$j]["nombrePrix"] = $prixLivrer;
  1299.                 $j++;
  1300.             }
  1301.             $tabInfoGeneral['prixTotalReel']= $prixTotalReel;
  1302.             $tabInfoGeneral['reference'] = $reference;
  1303.             $tabInfoGeneral['codeCommande'] =  $detailCommande[0]->getCodeCommande();
  1304.             $tabInfoGeneral['fournisseur'] =  $detailCommande[0]->getFournisseur()->getNomFournisseur();
  1305.             $tabInfoGeneral['dateCommande'] =  $detailCommande[0]->getDateCommande()->format("d/m/Y");
  1306.             $tabInfoGeneral['totalLivre'] = $totalLivre;
  1307.             //$tabInfoGeneral['portion'] = $portion;
  1308.             $rep['reponse'] = $tabLivrer;
  1309.             $rep['infoGenerale'] = $tabInfoGeneral;
  1310.             $rep['lignecommande'] = $tabLigneCommande;
  1311.             // var_dump($listeLigneCommande);exit;
  1312.             $rep['etat'] = 1;
  1313.         }
  1314.         return new Response(json_encode($rep));
  1315.     }
  1316.     /* @copyright ADMIN 2015
  1317.      *
  1318.      * @version 1
  1319.      *
  1320.      * @return twig d'ajout d'un abonne detailOperation.html.twig
  1321.      */
  1322.     public function getListeOperationCommandeVenteAjaxAction(Request $request,LoginManager $loginManager,ParamRepository $paramRepositor,ConnexionRepository $connexionRepository,ActionRepository $actionRepository,
  1323.     ModuleRepository $moduleRepository,ControleurRepository $controleurRepository,AbonneRepository $abonneRepository,CommandeRepository $commandeRepository ,LigneCommandeRepository $ligneCommandeRepository) {
  1324.         $rep = array('etat' => 0'msg' => 'Operation bien reussi''logout' => FALSE);
  1325.         /*
  1326.          * Nom de l'action en cours
  1327.          */
  1328.         $nomAction __FUNCTION__;
  1329.         /*
  1330.          * Description de l'action de l'action en cours
  1331.          */
  1332.         $descAction "recuperation de la liste des operations d'une commande";
  1333.         /*
  1334.          * Préparation du message de log 
  1335.          */
  1336.         $this->logMessage .= ' [ ' $nomAction ' ] ';
  1337.         /*
  1338.          * Service de gestion des droits
  1339.          */
  1340.         
  1341.         /*
  1342.          * Informations de session
  1343.          */
  1344.         $sessionData $this->infosConnecte($request$loginManager$paramRepositor,$connexionRepository$actionRepository);;
  1345.         /*
  1346.          * Locale en cours
  1347.          */
  1348.         $locale $loginManager->getLocale();
  1349.         $this->data['locale'] = $locale;
  1350.         /*
  1351.          * On vérifie si l'utilisateur est connecté
  1352.          */
  1353.         $status $loginManager->isConnecte($nomAction$paramRepositor,$connexionRepository$actionRepository);
  1354.         if ($status['isConnecte']) {
  1355.             /*
  1356.              * Au cas ou l'utilisateur est connecté on vérifie s'il nest pas innactif. S'il est innactif
  1357.              * on garde en mémoire flash la route actuelle pour effectuer une redirection lors de la prochaine connexion
  1358.              */
  1359.             if ($status['isInnactif']) {
  1360.                 $rep['msg'] = "Vous avez accusé un long moment d'inactivité. Veuillez-vous connecter de nouveau";
  1361.                 $loginManager->logout(LoginManager::SESSION_DATA_NAME);
  1362.                 return new Response(json_encode($rep));
  1363.             }
  1364.             /*
  1365.              * Seuls les utilisateurs admins ont le droit d'acceder à cette action
  1366.              */
  1367.             if (!$status['isUser']) {
  1368.                 return new Response(json_encode($rep));
  1369.             }
  1370.         } else {
  1371.             $rep['msg'] = "Vous êtes déconnecté. Veuillez-vous connecter de nouveau";
  1372.             return new Response(json_encode($rep));
  1373.         }
  1374.         /*
  1375.          * Gestion des droits
  1376.         
  1377.         if (!$loginManager->getOrSetActions(Module::MOD_GEST_FOUR, Module::MOD_GEST_FOUR_DESC, $this->getNomClassRun(__CLASS__), $this->description, $nomAction, $descAction, $sessionData['idProfil'], $moduleRepository, $controleurRepository, $actionRepository, $profilRepository)) {
  1378.             $this->logMessage .= ' [ TENTATIVE DE VIOLATION DE DROITS ] ';
  1379.             $rep['msg'] = "Vous n'avez pas le droit de recuperer la liste des operations d'une commande";
  1380.             return new Response(json_encode($rep));
  1381.         } */
  1382.         $tabLivrer = array();
  1383.         $tabLigneCommande = array();
  1384.         /*
  1385.          * Traitement de la requete qui vient de la vue
  1386.          * on vérifie si la requete est Ajax et si la methode est post
  1387.          */
  1388.         if (($request->isXmlHttpRequest()) && ($request->getMethod() == 'POST')) {
  1389.             //Recuperation du code de la commande 
  1390.             $idCommande $request->get('idcommande');
  1391.             $idAbonne $request->get('idabonne');
  1392.             $em $this->getDoctrine()->getManager();
  1393.             /*
  1394.              * Service de gestion des caisse
  1395.              */
  1396.             ////$operationManager = $this->get('operation_manager');
  1397.             // $listeLigneCommande =  $em->getRepository($this->stockBundle . 'Operation')->getOperationsCaisseBrouillard(0, 1,0, 0, 0,$idCommande, $idAbonne,'CPTE001', '0')  ;
  1398.             $detailCommande $commandeRepository->getOneCommande($idCommande);
  1399.             $j 0;
  1400.             $tabInfoGeneral = array();
  1401.             $tabLivrer = array();
  1402.             $tabLigneCommande = array();
  1403.             $prixTotalReel 0;
  1404.                 $reference 0;
  1405.                 $totalLivre 0;
  1406.             foreach ($detailCommande[0]->getLigneCommandes() as $uneLigneCommande) {
  1407.                 $i 0;
  1408.                 
  1409.                 foreach ($uneLigneCommande->getLivrers() as $uneLivraison) {
  1410.                     $tabLivrer[$uneLigneCommande->getId()][$i]['nbreLivre'] = $uneLivraison->getNbreLivre();
  1411.                     $tabLivrer[$uneLigneCommande->getId()][$i]['dateLivraison'] = $uneLivraison->getDateLivraison();
  1412.                     $tabLivrer[$uneLigneCommande->getId()][$i]['nbreReste'] = $uneLivraison->getNbreReste();
  1413.                     $tabLivrer[$uneLigneCommande->getId()][$i]['ref'] = $uneLivraison->getRefBonLivraison();
  1414.                     $tabLivrer[$uneLigneCommande->getId()][$i]['prixUnitaire'] = $uneLivraison->getLigneCommande()->getPrixrigueur()->getInfoPrixRigueur();
  1415.                     $prixTotal = (int) $uneLivraison->getNbreLivre() * $uneLivraison->getLigneCommande()->getPrixrigueur()->getInfoPrixRigueur();
  1416.                     $tabLivrer[$uneLigneCommande->getId()][$i]['prixTotal'] = (String) $prixTotal;
  1417.                     $i++;
  1418.                     $reference $uneLivraison->getRefBonLivraison();
  1419.                     $prixTotalReel$prixTotalReel $prixTotal;
  1420.                     $totalLivre $totalLivre $uneLivraison->getNbreLivre();
  1421.                 }
  1422.                 //Get Information dernierre commande
  1423.                 $ligneDernCommande $ligneCommandeRepository->findOneby(['produit'=>$uneLigneCommande->getProduit(),'suivantCommande'=>$uneLigneCommande->getId()]);
  1424.                 $tabLigneCommande[$j]["id"] = $uneLigneCommande->getId();
  1425.                 $tabLigneCommande[$j]["produit"] = $uneLigneCommande->getProduit()->getNomProduit();
  1426.                 if($ligneDernCommande != null){
  1427.                     $tabLigneCommande[$j]["oldQuantite"] = $ligneDernCommande->getQuantite();
  1428.                     $tabLigneCommande[$j]["oldDateCommande"] = $ligneDernCommande->getCommande()->getDateCommande()->format("d/m/Y");
  1429.                     $tabLigneCommande[$j]["oldPrix"] = $ligneDernCommande->getPrixRigueur()->getInfoPrixRigueur();
  1430.                 }else{
  1431.                     $tabLigneCommande[$j]["oldQuantite"] = "-";
  1432.                     $tabLigneCommande[$j]["oldDateCommande"] = "-";
  1433.                     $tabLigneCommande[$j]["oldPrix"] = "-";
  1434.                 }
  1435.                 $tabLigneCommande[$j]["quantite"] = $uneLigneCommande->getQuantite();
  1436.                 $tabLigneCommande[$j]["dateCommande"] = $detailCommande[0]->getDateCommande()->format("d/m/Y");
  1437.                 $tabLigneCommande[$j]["prix"] = $uneLigneCommande->getPrixRigueur()->getInfoPrixRigueur();
  1438.                 $tabLigneCommande[$j]["nombreLivrer"] = $totalLivre ;
  1439.                 $tabLigneCommande[$j]["nombrePrix"] = $uneLigneCommande->getPrixRigueur()->getInfoPrixRigueur();
  1440.                 $j++;
  1441.             }
  1442.             $tabInfoGeneral['prixTotalReel']= $prixTotalReel;
  1443.             $tabInfoGeneral['reference'] = $reference;
  1444.             $tabInfoGeneral['codeCommande'] =  $detailCommande[0]->getCodeCommande();
  1445.             $tabInfoGeneral['fournisseur'] =   "TEST";//$detailCommande[0]->getFournisseur()->getNomFournisseur();
  1446.             $tabInfoGeneral['dateCommande'] =  $detailCommande[0]->getDateCommande()->format("d/m/Y");
  1447.             $tabInfoGeneral['totalLivre'] = $totalLivre;
  1448.             $rep['reponse'] = $tabLivrer;
  1449.             $rep['infoGenerale'] = $tabInfoGeneral;
  1450.             $rep['lignecommande'] = $tabLigneCommande;
  1451.             // var_dump($listeLigneCommande);exit;
  1452.             $rep['etat'] = 1;
  1453.         }
  1454.         return new Response(json_encode($rep));
  1455.     }
  1456.     /* @copyright ADMIN 2015
  1457.      *
  1458.      * @version 1
  1459.      *
  1460.      * @return twig d'ajout d'un abonne detailOperation.html.twig
  1461.      */
  1462.     public function setPourcentageLigneCommandeAction(Request $request) {
  1463.         $rep = array('etat' => 0'msg' => 'Operation bien reussi''logout' => FALSE);
  1464.         /*
  1465.          * Nom de l'action en cours
  1466.          */
  1467.         $nomAction __FUNCTION__;
  1468.         /*
  1469.          * Description de l'action de l'action en cours
  1470.          */
  1471.         $descAction "rApplicqué des pourcentages sur une  ligne de commande";
  1472.         /*
  1473.          * Préparation du message de log 
  1474.          */
  1475.         $this->logMessage .= ' [ ' $nomAction ' ] ';
  1476.         /*
  1477.          * Service de gestion des droits
  1478.          */
  1479.         
  1480.         /*
  1481.          * Informations de session
  1482.          */
  1483.         $sessionData $this->infosConnecte($request$loginManager$paramRepositor,$connexionRepository$actionRepository);;
  1484.         /*
  1485.          * Locale en cours
  1486.          */
  1487.         $locale $loginManager->getLocale();
  1488.         $this->data['locale'] = $locale;
  1489.         /*
  1490.          * On vérifie si l'utilisateur est connecté
  1491.          */
  1492.         $status $loginManager->isConnecte($nomAction$paramRepositor,$connexionRepository$actionRepository);
  1493.         if ($status['isConnecte']) {
  1494.             /*
  1495.              * Au cas ou l'utilisateur est connecté on vérifie s'il nest pas innactif. S'il est innactif
  1496.              * on garde en mémoire flash la route actuelle pour effectuer une redirection lors de la prochaine connexion
  1497.              */
  1498.             if ($status['isInnactif']) {
  1499.                 $rep['msg'] = "Vous avez accusé un long moment d'inactivité. Veuillez-vous connecter de nouveau";
  1500.                 $loginManager->logout(LoginManager::SESSION_DATA_NAME);
  1501.                 return new Response(json_encode($rep));
  1502.             }
  1503.             /*
  1504.              * Seuls les utilisateurs admins ont le droit d'acceder à cette action
  1505.              */
  1506.             if (!$status['isUser']) {
  1507.                 return new Response(json_encode($rep));
  1508.             }
  1509.         } else {
  1510.             $rep['msg'] = "Vous êtes déconnecté. Veuillez-vous connecter de nouveau";
  1511.             return new Response(json_encode($rep));
  1512.         }
  1513.         /*
  1514.          * Gestion des droits
  1515.         
  1516.         if (!$loginManager->getOrSetActions(Module::MOD_GEST_FOUR, Module::MOD_GEST_FOUR_DESC, $this->getNomClassRun(__CLASS__), $this->description, $nomAction, $descAction, $sessionData['idProfil'], $moduleRepository, $controleurRepository, $actionRepository, $profilRepository)) {
  1517.             $this->logMessage .= ' [ TENTATIVE DE VIOLATION DE DROITS ] ';
  1518.             $rep['msg'] = "Vous n'avez pas le droit de recuperer la liste des operations d'une commande";
  1519.             return new Response(json_encode($rep));
  1520.         } */
  1521.         $tabLivrer = array();
  1522.         $tabLigneCommande = array();
  1523.         /*
  1524.          * Traitement de la requete qui vient de la vue
  1525.          * on vérifie si la requete est Ajax et si la methode est post
  1526.          */
  1527.         if (($request->isXmlHttpRequest()) && ($request->getMethod() == 'POST')) {
  1528.             //Recuperation du code de la commande 
  1529.             $idLigneCmde$request->get('idLigneCmde');
  1530.             
  1531.             $pourcentage$request->get('pourcentage');
  1532.             //var_dump($idLigneCmde, $pourcentage);exit;
  1533.             $em $this->getDoctrine()->getManager();
  1534.             /*
  1535.              * Service de gestion des caisse
  1536.              */
  1537.             $objetUtilisateur =  $em->getRepository($this->userBundle 'Utilisateur')->find($sessionData['id']);
  1538.             //$operationManager = $this->get('operation_manager');
  1539.             // $listeLigneCommande =  $em->getRepository($this->stockBundle . 'Operation')->getOperationsCaisseBrouillard(0, 1,0, 0, 0,$idCommande, $idAbonne,'CPTE001', '0')  ;
  1540.             $detailLigneCommande $em->getRepository($this->stockBundle 'LigneCommande')->find($idLigneCmde);
  1541.             $objetCommande$detailLigneCommande->getCommande();
  1542.             $prix = -1*$detailLigneCommande->getPrixRigueur()->getInfoPrixRigueur()*$pourcentage/100;
  1543.             $objetPrixRigueur $this->savePrix($em$prix$detailLigneCommande->getProduit(), 2$objetUtilisateur) ;
  1544.             $codeVente "R".$detailLigneCommande->getCodeGenere();
  1545.             $this->saveLigneCommande($em$codeVente$detailLigneCommande->getCommande()->getInfoLivrers()[0], $detailLigneCommande->getCommande(), $detailLigneCommande->getProduit(), $objetPrixRigueur$detailLigneCommande->getQuantite(), $detailLigneCommande->getId(), 2,$this->ligneCommandeRepository) ;
  1546.             $j 0;
  1547.             $tabInfoGeneral = array();
  1548.             foreach ($objetCommande->getLigneCommandes() as $uneLigneCommande) {
  1549.                 $i 0;
  1550.                 $prixTotalReel 0;
  1551.                 $reference 0;
  1552.                 $totalLivre 0;
  1553.                 foreach ($uneLigneCommande->getLivrers() as $uneLivraison) {
  1554.                     $tabLivrer[$uneLigneCommande->getId()][$i]['nbreLivre'] = $uneLivraison->getNbreLivre();
  1555.                     $tabLivrer[$uneLigneCommande->getId()][$i]['dateLivraison'] = $uneLivraison->getDateLivraison();
  1556.                     $tabLivrer[$uneLigneCommande->getId()][$i]['nbreReste'] = $uneLivraison->getNbreReste();
  1557.                     $tabLivrer[$uneLigneCommande->getId()][$i]['ref'] = $uneLivraison->getRefBonLivraison();
  1558.                     $tabLivrer[$uneLigneCommande->getId()][$i]['prixUnitaire'] = $uneLivraison->getLigneCommande()->getPrixrigueur()->getInfoPrixRigueur();
  1559.                     $prixTotal = (int) $uneLivraison->getNbreLivre() * $uneLivraison->getLigneCommande()->getPrixrigueur()->getInfoPrixRigueur();
  1560.                     $tabLivrer[$uneLigneCommande->getId()][$i]['prixTotal'] = (String) $prixTotal;
  1561.                     $i++;
  1562.                     $reference $uneLivraison->getRefBonLivraison();
  1563.                     $prixTotalReel$prixTotalReel $prixTotal;
  1564.                     $totalLivre $totalLivre $uneLivraison->getNbreLivre();
  1565.                 }
  1566.                 //Get Information dernierre commande
  1567.                 $ligneDernCommande $em->getRepository($this->stockBundle 'LigneCommande')->findOneby(['produit'=>$uneLigneCommande->getProduit(),'suivantCommande'=>$uneLigneCommande->getId()]);
  1568.                 $tabLigneCommande[$j]["id"] = $uneLigneCommande->getId();
  1569.                 $tabLigneCommande[$j]["produit"] = $uneLigneCommande->getProduit()->getNomProduit();
  1570.                 if($ligneDernCommande != null){
  1571.                     $tabLigneCommande[$j]["oldQuantite"] = $ligneDernCommande->getQuantite();
  1572.                     $tabLigneCommande[$j]["oldDateCommande"] = $ligneDernCommande->getCommande()->getDateCommande()->format("d/m/Y");
  1573.                     $tabLigneCommande[$j]["oldPrix"] = $ligneDernCommande->getPrixRigueur()->getInfoPrixRigueur();
  1574.                 }else{
  1575.                     $tabLigneCommande[$j]["oldQuantite"] = "-";
  1576.                     $tabLigneCommande[$j]["oldDateCommande"] = "-";
  1577.                     $tabLigneCommande[$j]["oldPrix"] = "-";
  1578.                 }
  1579.                 $tabLigneCommande[$j]["quantite"] = $uneLigneCommande->getQuantite();
  1580.                 $tabLigneCommande[$j]["dateCommande"] = $objetCommande->getDateCommande()->format("d/m/Y");
  1581.                 $tabLigneCommande[$j]["prix"] = $uneLigneCommande->getPrixRigueur()->getInfoPrixRigueur();
  1582.                 $tabLigneCommande[$j]["nombreLivrer"] = $totalLivre ;
  1583.                 $tabLigneCommande[$j]["nombrePrix"] = $uneLigneCommande->getPrixRigueur()->getInfoPrixRigueur();
  1584.                 $j++;
  1585.             }
  1586.             
  1587.             
  1588.             $montantTotalCommande $em->getRepository($this->stockBundle 'LigneCommande')->sumLigneCommande($objetCommande->getId());
  1589.             $objetCommande->setMontantCommande($montantTotalCommande); //
  1590.             $em->persist($objetCommande);    
  1591.             $em->flush($objetCommande);
  1592.             
  1593.             
  1594.             $tabInfoGeneral['prixTotalReel']= $prixTotalReel;
  1595.             $tabInfoGeneral['reference'] = $reference;
  1596.             $tabInfoGeneral['codeCommande'] =  $objetCommande->getCodeCommande();
  1597.             $tabInfoGeneral['commandeId'] =  $objetCommande->getId();
  1598.             $tabInfoGeneral['fournisseur'] =   "TEST";//$detailCommande[0]->getFournisseur()->getNomFournisseur();
  1599.             $tabInfoGeneral['dateCommande'] =  $objetCommande->getDateCommande()->format("d/m/Y");
  1600.             $tabInfoGeneral['totalLivre'] = $totalLivre;
  1601.             $rep['reponse'] = $tabLivrer;
  1602.             $rep['infoGenerale'] = $tabInfoGeneral;
  1603.             $rep['lignecommande'] = $tabLigneCommande;
  1604.             // var_dump($listeLigneCommande);exit;
  1605.             $rep['etat'] = 1;
  1606.         }
  1607.         return new Response(json_encode($rep));
  1608.     }
  1609.        /* @copyright ADMIN 2015
  1610.      *
  1611.      * @version 1
  1612.      *
  1613.      * @return twig d'ajout d'un abonne detailOperation.html.twig
  1614.      */
  1615.      public function setDeleteLigneCommandeAction(Request $requestLoginManager $loginManager,ParamRepository $paramRepositor,ConnexionRepository $connexionRepository,ActionRepository $actionRepository,
  1616.      ModuleRepository $moduleRepository,ControleurRepository $controleurRepository,AbonneRepository $abonneRepositoryUtilisateurRepository $utilisateurRepository,
  1617.      LigneCommandeRepository  $ligneCommandeRepository) {
  1618.         //var_dump($objetCommande->getId());exit;
  1619.         $rep = array('etat' => 0'msg' => 'Operation bien reussi''logout' => FALSE);
  1620.         /*
  1621.          * Nom de l'action en cours
  1622.          */
  1623.         $nomAction __FUNCTION__;
  1624.         /*
  1625.          * Description de l'action de l'action en cours
  1626.          */
  1627.         $descAction "supprimer une  ligne de commande";
  1628.         /*
  1629.          * Préparation du message de log 
  1630.          */
  1631.         $this->logMessage .= ' [ ' $nomAction ' ] ';
  1632.         /*
  1633.          * Service de gestion des droits
  1634.          */
  1635.         
  1636.         /*
  1637.          * Informations de session
  1638.          */
  1639.         $sessionData $this->infosConnecte($request$loginManager$paramRepositor,$connexionRepository$actionRepository);;
  1640.         /*
  1641.          * Locale en cours
  1642.          */
  1643.         $locale $loginManager->getLocale();
  1644.         $this->data['locale'] = $locale;
  1645.         $j 0;
  1646.         $tabInfoGeneral = array();
  1647.         /*
  1648.          * On vérifie si l'utilisateur est connecté
  1649.          */
  1650.         $status $loginManager->isConnecte($nomAction$paramRepositor,$connexionRepository$actionRepository);
  1651.         if ($status['isConnecte']) {
  1652.             /*
  1653.              * Au cas ou l'utilisateur est connecté on vérifie s'il nest pas innactif. S'il est innactif
  1654.              * on garde en mémoire flash la route actuelle pour effectuer une redirection lors de la prochaine connexion
  1655.              */
  1656.             if ($status['isInnactif']) {
  1657.                 $rep['msg'] = "Vous avez accusé un long moment d'inactivité. Veuillez-vous connecter de nouveau";
  1658.                 $loginManager->logout(LoginManager::SESSION_DATA_NAME);
  1659.                 return new Response(json_encode($rep));
  1660.             }
  1661.             /*
  1662.              * Seuls les utilisateurs admins ont le droit d'acceder à cette action
  1663.              */
  1664.             if (!$status['isUser']) {
  1665.                 return new Response(json_encode($rep));
  1666.             }
  1667.         } else {
  1668.             $rep['msg'] = "Vous êtes déconnecté. Veuillez-vous connecter de nouveau";
  1669.             return new Response(json_encode($rep));
  1670.         }
  1671.         /*
  1672.          * Gestion des droits
  1673.         
  1674.         if (!$loginManager->getOrSetActions(Module::MOD_GEST_FOUR, Module::MOD_GEST_FOUR_DESC, $this->getNomClassRun(__CLASS__), $this->description, $nomAction, $descAction, $sessionData['idProfil'], $moduleRepository, $controleurRepository, $actionRepository, $profilRepository)) {
  1675.             $this->logMessage .= ' [ TENTATIVE DE VIOLATION DE DROITS ] ';
  1676.             $rep['msg'] = "Vous n'avez pas le droit de recuperer la liste des operations d'une commande";
  1677.             return new Response(json_encode($rep));
  1678.         } */
  1679.         $tabLivrer = array();
  1680.         $tabLigneCommande = array();
  1681.         /*
  1682.          * Traitement de la requete qui vient de la vue
  1683.          * on vérifie si la requete est Ajax et si la methode est post
  1684.          */
  1685.         if (($request->isXmlHttpRequest()) && ($request->getMethod() == 'POST')) {
  1686.             //Recuperation du code de la commande 
  1687.             $idLigneCmde$request->get('idLigneCmde');
  1688.             
  1689.           
  1690.             //var_dump($idLigneCmde, $pourcentage);exit;
  1691.             $em $this->getDoctrine()->getManager();
  1692.             /*
  1693.              * Service de gestion des caisse
  1694.              */
  1695.             $objetUtilisateur =  $utilisateurRepository->find($sessionData['id']);
  1696.             //$operationManager = $this->get('operation_manager');
  1697.             // $listeLigneCommande =  $em->getRepository($this->stockBundle . 'Operation')->getOperationsCaisseBrouillard(0, 1,0, 0, 0,$idCommande, $idAbonne,'CPTE001', '0')  ;
  1698.             
  1699.             $detailLigneCommande $ligneCommandeRepository->find($idLigneCmde);
  1700.             //var_dump($detailLigneCommande);exit;
  1701.             $objetCommande$detailLigneCommande->getCommande();
  1702.             $em->remove($detailLigneCommande  );
  1703.             $em->flush();
  1704.             $prixTotalReel =0;
  1705.             $i 0;
  1706.             $prixTotalReel 0;
  1707.             $reference 0;
  1708.             $totalLivre 0;
  1709.             foreach ($objetCommande->getLigneCommandes() as $uneLigneCommande) {
  1710.                 
  1711.                 foreach ($uneLigneCommande->getLivrers() as $uneLivraison) {
  1712.                     $tabLivrer[$uneLigneCommande->getId()][$i]['nbreLivre'] = $uneLivraison->getNbreLivre();
  1713.                     $tabLivrer[$uneLigneCommande->getId()][$i]['dateLivraison'] = $uneLivraison->getDateLivraison();
  1714.                     $tabLivrer[$uneLigneCommande->getId()][$i]['nbreReste'] = $uneLivraison->getNbreReste();
  1715.                     $tabLivrer[$uneLigneCommande->getId()][$i]['ref'] = $uneLivraison->getRefBonLivraison();
  1716.                     $tabLivrer[$uneLigneCommande->getId()][$i]['prixUnitaire'] = $uneLivraison->getLigneCommande()->getPrixrigueur()->getInfoPrixRigueur();
  1717.                     $prixTotal = (int) $uneLivraison->getNbreLivre() * $uneLivraison->getLigneCommande()->getPrixrigueur()->getInfoPrixRigueur();
  1718.                     $tabLivrer[$uneLigneCommande->getId()][$i]['prixTotal'] = (String) $prixTotal;
  1719.                     $i++;
  1720.                     $reference $uneLivraison->getRefBonLivraison();
  1721.                     $prixTotalReel$prixTotalReel $prixTotal;
  1722.                     $totalLivre $totalLivre $uneLivraison->getNbreLivre();
  1723.                 }
  1724.                 //Get Information dernierre commande
  1725.                 $ligneDernCommande $ligneCommandeRepository->findOneby(['produit'=>$uneLigneCommande->getProduit(),'suivantCommande'=>$uneLigneCommande->getId()]);
  1726.                 $tabLigneCommande[$j]["id"] = $uneLigneCommande->getId();
  1727.                 $tabLigneCommande[$j]["produit"] = $uneLigneCommande->getProduit()->getNomProduit();
  1728.                 if($ligneDernCommande != null){
  1729.                     $tabLigneCommande[$j]["oldQuantite"] = $ligneDernCommande->getQuantite();
  1730.                     $tabLigneCommande[$j]["oldDateCommande"] = $ligneDernCommande->getCommande()->getDateCommande()->format("d/m/Y");
  1731.                     $tabLigneCommande[$j]["oldPrix"] = $ligneDernCommande->getPrixRigueur()->getInfoPrixRigueur();
  1732.                 }else{
  1733.                     $tabLigneCommande[$j]["oldQuantite"] = "-";
  1734.                     $tabLigneCommande[$j]["oldDateCommande"] = "-";
  1735.                     $tabLigneCommande[$j]["oldPrix"] = "-";
  1736.                 }
  1737.                 $tabLigneCommande[$j]["quantite"] = $uneLigneCommande->getQuantite();
  1738.                 $tabLigneCommande[$j]["dateCommande"] = $objetCommande->getDateCommande()->format("d/m/Y");
  1739.                 $tabLigneCommande[$j]["prix"] = $uneLigneCommande->getPrixRigueur()->getInfoPrixRigueur();
  1740.                 $tabLigneCommande[$j]["nombreLivrer"] = $totalLivre ;
  1741.                 $tabLigneCommande[$j]["nombrePrix"] = $uneLigneCommande->getPrixRigueur()->getInfoPrixRigueur();
  1742.                 $j++;
  1743.             }
  1744.             
  1745.             //var_dump($objetCommande->getId());exit;
  1746.             
  1747.             $montantTotalCommande $ligneCommandeRepository->sumLigneCommande($objetCommande->getId());
  1748.             
  1749.             
  1750.             $objetCommande->setMontantCommande($montantTotalCommande); //
  1751.             $em->persist($objetCommande);    
  1752.             $em->flush($objetCommande);
  1753.             //var_dump($montantTotalCommande );exit;
  1754.             
  1755.             $tabInfoGeneral['prixTotalReel']= $prixTotalReel;
  1756.             $tabInfoGeneral['reference'] = $reference;
  1757.             $tabInfoGeneral['codeCommande'] =  $objetCommande->getCodeCommande();
  1758.             $tabInfoGeneral['commandeId'] =  $objetCommande->getId();
  1759.             $tabInfoGeneral['fournisseur'] =   "XXXXX";//$detailCommande[0]->getFournisseur()->getNomFournisseur();
  1760.             $tabInfoGeneral['dateCommande'] =  $objetCommande->getDateCommande()->format("d/m/Y");
  1761.             $tabInfoGeneral['totalLivre'] = $totalLivre;
  1762.             $rep['reponse'] = $tabLivrer;
  1763.             $rep['infoGenerale'] = $tabInfoGeneral;
  1764.             $rep['lignecommande'] = $tabLigneCommande;
  1765.             // var_dump($listeLigneCommande);exit;
  1766.             $rep['etat'] = 1;
  1767.         }
  1768.         return new Response(json_encode($rep));
  1769.     }
  1770.     /**
  1771.      * Methode s'occupant 'de faire les traitements du paiement fait avec le mode  paiement espece
  1772.      *
  1773.      * @author armand.tevi@gmail.com
  1774.      * @copyright ADMIN 2015
  1775.      *
  1776.      * @version 1
  1777.      *
  1778.      * @return twig d'ajout d'un abonne detailOperation.html.twig
  1779.      */
  1780.     public function traiteCommandeAction(Request $request,LoginManager $loginManager,ParamRepository $paramRepositor,
  1781.     ConnexionRepository $connexionRepository,ActionRepository $actionRepository,  OperationManager $operationManager,
  1782.     ModuleRepository $moduleRepository,ControleurRepository $controleurRepository,ProfilRepository $profilRepositoryCaisseRepository $caisseRepositoryTypeOperationRepository $typeOperationRepositoryUtilisateurRepository $utilisateurRepository,
  1783.     
  1784.     ) {
  1785.         $rep = array('etat' => FALSE'msg' => 'Erreur survenue lors du traitement''logout' => FALSE);
  1786.         /*
  1787.          * Nom de l'action en cours
  1788.          */
  1789.         $nomAction __FUNCTION__;
  1790.         /*
  1791.          * Description de l'action de l'action en cours
  1792.          */
  1793.         $descAction "Traitement de l'opération courante ";
  1794.         /*
  1795.          * Préparation du message de log 
  1796.          */
  1797.         $this->logMessage .= ' [ ' $nomAction ' ] ';
  1798.         /*
  1799.          * Service de gestion des droits
  1800.          */
  1801.         
  1802.         /*
  1803.          * Informations de session
  1804.          */
  1805.         $sessionData $this->infosConnecte($request$loginManager$paramRepositor,$connexionRepository$actionRepository);;
  1806.         /*
  1807.          * Locale en cours
  1808.          */
  1809.         $locale $loginManager->getLocale();
  1810.         $this->data['locale'] = $locale;
  1811.         /*
  1812.          * On vérifie si l'utilisateur est connecté
  1813.          */
  1814.         $status $loginManager->isConnecte($nomAction$paramRepositor,$connexionRepository$actionRepository);
  1815.         if ($status['isConnecte']) {
  1816.             /*
  1817.              * Au cas ou l'utilisateur est connecté on vérifie s'il nest pas innactif. S'il est innactif
  1818.              * on garde en mémoire flash la route actuelle pour effectuer une redirection lors de la prochaine connexion
  1819.              */
  1820.             if ($status['isInnactif']) {
  1821.                 $rep['msg'] = "Vous avez accusé un long moment d'inactivité. Veuillez-vous connecter de nouveau";
  1822.                 $loginManager->logout(LoginManager::SESSION_DATA_NAME);
  1823.                 return new Response(json_encode($rep));
  1824.             }
  1825.             /*
  1826.              * Seuls les utilisateurs admins ont le droit d'acceder à cette action
  1827.              */
  1828.             if (!$status['isUser']) {
  1829.                 return new Response(json_encode($rep));
  1830.             }
  1831.         } else {
  1832.             $rep['msg'] = "Vous êtes déconnecté. Veuillez-vous connecter de nouveau";
  1833.             return new Response(json_encode($rep));
  1834.         }
  1835.         /*
  1836.          * Gestion des droits
  1837.          */
  1838.         if (!$loginManager->getOrSetActions(Module::MOD_GEST_FOURModule::MOD_GEST_FOUR_DESC$this->getNomClassRun(__CLASS__), $this->description$nomAction$descAction$sessionData['idProfil'], $moduleRepository$controleurRepository$actionRepository$profilRepository)) {
  1839.             $this->logMessage .= ' [ TENTATIVE DE VIOLATION DE DROITS ] ';
  1840.             $rep['msg'] = "Vous n'avez pas le droit de faire le paiement ";
  1841.             return new Response(json_encode($rep));
  1842.         }
  1843.         /*
  1844.          * Traitement de la requete qui vient de la vue
  1845.          * on vérifie si la requete est Ajax et si la methode est post
  1846.          */
  1847.         if (($request->isXmlHttpRequest()) && ($request->getMethod() == 'POST')) {
  1848.             $em $this->getDoctrine()->getManager();
  1849.             // Recuperation du type operation 
  1850.             //Recuperation du de linfo util 
  1851.             
  1852.             $concatInfo ="";
  1853.             $montantEsp $request->get('montantEsp');
  1854.             $idAbonne $request->get('idabonne');
  1855.             $idTypeOp $request->get('idTypeOp');
  1856.             $infoDepoCheq $request->get('infoDepoCheq');
  1857.             if($request->get('fournisseurId') != ""){
  1858.                 $fournisseurId $request->get('fournisseurId');
  1859.                 $producteurId null;
  1860.             }else{
  1861.                 $fournisseurId null;
  1862.             }
  1863.             
  1864.             if($request->get('producteurId') != null &&  $request->get('producteurId') != '0'){
  1865.                 $producteurId $request->get('producteurId');
  1866.                 $fournisseurId null;
  1867.             }else{
  1868.                 $producteurId null;
  1869.             }
  1870.             //var_dump($fournisseurId, $producteurId );exit;
  1871.                 
  1872.            // $montantCheq = $request->get('montantCheq');
  1873.             $montantEsp preg_replace('/\D/'''$montantEsp);
  1874.             $numCheque $request->get('numCheque');
  1875.             //$operationManager = $this->get('operation_manager');
  1876.             //var_dump($producteurId );exit;
  1877.             $idVille $request->get('idVille');
  1878.          //recuperation de la ville 
  1879.             $objetUtilisateur $utilisateurRepository->find($sessionData['id']);
  1880.             //var_dump($idTypeOp);exit;
  1881.             $objetTypeOperation $typeOperationRepository->find($idTypeOp);
  1882.             //var_dump($objetTypeOperation);exit;
  1883.             $infoDepo =  $objetTypeOperation->getLibTypeOperation()." : ".$request->get('infoDepoEsp');
  1884.            
  1885.             if($idVille == 0){
  1886.                 if($objetUtilisateur->getVille() != null)
  1887.                          $idVille $objetUtilisateur->getVille()->getId();
  1888.             }
  1889.             //recuperation de l'identifiant du produit
  1890.             $tabCompteId =  $operationManager->getCompteCaisse($em,$objetTypeOperation->getCaisse()->getId(), $caisseRepository);//getCompteVille($em,$idVille);
  1891.             
  1892.             $idProduit null;            
  1893.             $tabCompteMontant $operationManager->getRecuperationCompte($em,$idTypeOp,$montantEsp,$typeOperationRepository);            
  1894.             $compteAuxi $tabCompteId['compte'];
  1895.             $d = new \DateTime(); //$sessionData['dateChoisie'];
  1896.             $dateChoisie $d->format('Y/m/d H:i:s');
  1897.             if($request->get('producteurId') != null &&  $request->get('producteurId') != '0'){
  1898.                 $typeProducteur 3;
  1899.                 //recupérer le compte du producteur
  1900.                 $objetCaisse $caisseRepository->findOneby(['typeCaisse'=>$typeProducteur'abonne'=>$objetUtilisateur->getAbonne()]);
  1901.                 $tabCompteId['id'] = $objetCaisse->getId(); 
  1902.             }
  1903.             
  1904.             $an $d->format('Y');
  1905.             $m $d->format('m');
  1906.             $j $d->format('d');
  1907.             $refFacture $this->getRefLivrer($em1$an$m$entite 'LIVRER'$taille 5$j);
  1908.           
  1909.            
  1910.             $operationManager->geneLigneOperationComptable(null$tabCompteId['id'], $tabCompteMontant['montant'], $infoDepo$telDepo ''$refFacture$numCheque$tabCompteMontant['compte'], $idTypeOp$piece 0$nomCompte ''$typePaie=1$idProduit$compteAuxi$dateChoisie,$idVille$sessionData["abonneId"],null,null$utilisateurRepository,$caisseRepository$producteurId$fournisseurId);
  1911.             //if($idTypeOp == 109){ 
  1912.                 //$this->genereLigneSuivieLivraison($em, $objetUtilisateur->getVille(),$montantEsp,1, "Avance pour achat de cacao ", NULL, NULL);
  1913.             //} 
  1914.             $rep['etat'] = true;
  1915.             $rep['reponse']['reponse'] = $infoDepo;
  1916.             $rep['reponse']['montantEsp'] = $montantEsp;
  1917.             $rep['reponse']['infoDepoCheq'] = $infoDepoCheq;
  1918.             //$rep['reponse']['montantCheq'] = $montantCheq;
  1919.             $rep['reponse']['numCheque'] = $numCheque;
  1920.             $rep['reponse']['nomCompte'] = $nomCompte;
  1921.         }
  1922.         return new Response(json_encode($rep));
  1923.     }
  1924.     /**
  1925.      * Methode s'occupant 'de faire les traitements du paiement fait avec le mode  paiement espece
  1926.      *
  1927.      * @author armand.tevi@gmail.com
  1928.      * @copyright ADMIN 2015
  1929.      *
  1930.      * @version 1
  1931.      *
  1932.      * @return twig d'ajout d'un abonne detailOperation.html.twig
  1933.      */
  1934.     public function traiteCommandeChequeAction(Request $request) {
  1935.         $rep = array('etat' => FALSE'msg' => 'Erreur survenue lors du traitement''logout' => FALSE);
  1936.         /**
  1937.          * Nom de l'action en cours
  1938.          */
  1939.         $nomAction __FUNCTION__;
  1940.         /*
  1941.          * Description de l'action de l'action en cours
  1942.          */
  1943.         $descAction "traitement du paiement avec cheque";
  1944.         /*
  1945.          * Préparation du message de log 
  1946.          */
  1947.         $this->logMessage .= ' [ ' $nomAction ' ] ';
  1948.         /*
  1949.          * Service de gestion des droits
  1950.          */
  1951.         
  1952.         /*
  1953.          * Informations de session
  1954.          */
  1955.         $sessionData $this->infosConnecte($request$loginManager$paramRepositor,$connexionRepository$actionRepository);;
  1956.         /*
  1957.          * Locale en cours
  1958.          */
  1959.         $locale $loginManager->getLocale();
  1960.         $this->data['locale'] = $locale;
  1961.         /*
  1962.          * On vérifie si l'utilisateur est connecté
  1963.          */
  1964.         $status $loginManager->isConnecte($nomAction$paramRepositor,$connexionRepository$actionRepository);
  1965.         if ($status['isConnecte']) {
  1966.             /*
  1967.              * Au cas ou l'utilisateur est connecté on vérifie s'il nest pas innactif. S'il est innactif
  1968.              * on garde en mémoire flash la route actuelle pour effectuer une redirection lors de la prochaine connexion
  1969.              */
  1970.             if ($status['isInnactif']) {
  1971.                 $rep['msg'] = "Vous avez accusé un long moment d'inactivité. Veuillez-vous connecter de nouveau";
  1972.                 $loginManager->logout(LoginManager::SESSION_DATA_NAME);
  1973.                 return new Response(json_encode($rep));
  1974.             }
  1975.             /*
  1976.              * Seuls les utilisateurs admins ont le droit d'acceder à cette action
  1977.              */
  1978.             if (!$status['isUser']) {
  1979.                 return new Response(json_encode($rep));
  1980.             }
  1981.         } else {
  1982.             $rep['msg'] = "Vous êtes déconnecté. Veuillez-vous connecter de nouveau";
  1983.             return new Response(json_encode($rep));
  1984.         }
  1985.         /*
  1986.          * Gestion des droits
  1987.          */
  1988.         if (!$loginManager->getOrSetActions(Module::MOD_GEST_FOURModule::MOD_GEST_FOUR_DESC$this->getNomClassRun(__CLASS__), $this->description$nomAction$descAction$sessionData['idProfil'], $moduleRepository$controleurRepository$actionRepository$profilRepository)) {
  1989.             $this->logMessage .= ' [ TENTATIVE DE VIOLATION DE DROITS ] ';
  1990.             $rep['msg'] = "Vous n'avez pas le droit de faire le paiement ";
  1991.             return new Response(json_encode($rep));
  1992.         }
  1993.         /*
  1994.          * Traitement de la requete qui vient de la vue
  1995.          * on vérifie si la requete est Ajax et si la methode est post
  1996.          */
  1997.         if (($this->request->isXmlHttpRequest()) && ($this->request->getMethod() == 'POST')) {
  1998.             
  1999.         }
  2000.         return new Response(json_encode($rep));
  2001.     }
  2002.     /**
  2003.      * Methode s'occupant de l'ajout du operation.
  2004.      *
  2005.      * @author armand.tevi@gmail.com
  2006.      * @copyright ADMIN 2015
  2007.      *
  2008.      * @version 1
  2009.      *
  2010.      * @return twig d'ajout d'un abonne ajouterOperation.html.twig
  2011.      */
  2012.     public function afficherFactureAction(Request $request) {
  2013.         return $this->render($this->stockBundleSlash($sessionData['typePresentation']). '/Operation/templateFacture.html.twig'$this->data$this->response);
  2014.     }
  2015.     /**
  2016.      * Methode s'occupant d'imprimer .
  2017.      *
  2018.      * @author armand.tevi@gmail.com
  2019.      * @copyright ADMIN 2015
  2020.      *
  2021.      * @version 1
  2022.      *
  2023.      * @return twig d'ajout d'un abonne ajouterOperation.html.twig
  2024.      */
  2025.     public function traiteRecuAction(Request $request$id) {
  2026.         $em $this->getDoctrine()->getManager();
  2027.         //Recuperation des informations concernant le client
  2028.         $infoClient $em->getRepository($this->stockBundle 'Commande')->getClientCommande($id);
  2029.         //Recuperation des informations concernant les lignes commande
  2030.         $ligneCommande $em->getRepository($this->stockBundle 'Commande')->getLigneCommande($id);
  2031.         //Recuperation des informations concernant les operation de la commande 
  2032.         $ligneOperation $em->getRepository($this->stockBundle 'Operation')->getListeOperationCommande($id);
  2033.         /*
  2034.          * Preparation des informations à traiter sur les twig 
  2035.          */
  2036.         $this->data['infoClient'] = $infoClient;
  2037.         $this->data['ligneCommande'] = $ligneCommande;
  2038.         $this->data['ligneOperation'] = $ligneOperation;
  2039.         return $this->render($this->stockBundleSlash($sessionData['typePresentation']). '/Operation/recuPaiement.html.twig'$this->data$this->response);
  2040.     }
  2041.     /**
  2042.      * Methode s'occupant de lister les Operations.
  2043.      *
  2044.      * @author armand.tevi@gmail.com
  2045.      * @copyright ADMIN 2015
  2046.      *
  2047.      * @version 1
  2048.      *
  2049.      * @return twig d'ajout d'un abonne listeOperation.html.twig
  2050.      */
  2051.     public function listerOperationAction(Request $request) {
  2052.         /*
  2053.          * Nom de l'action en cours
  2054.          */
  2055.         $nomAction __FUNCTION__;
  2056.         /*
  2057.          * Description de l'action de l'action en cours
  2058.          */
  2059.         $descAction "Affichage de la liste des operations";
  2060.         /*
  2061.          * Préparation du message de log 
  2062.          */
  2063.         $this->logMessage .= ' [ ' $nomAction ' ] ';
  2064.         /*
  2065.          * Service de gestion des droits
  2066.          */
  2067.         
  2068.         /*
  2069.          * Informations de session
  2070.          */
  2071.         $sessionData $this->infosConnecte($request$loginManager$paramRepositor,$connexionRepository$actionRepository);;
  2072.         /*
  2073.          * Locale en cours
  2074.          */
  2075.         $locale $loginManager->getLocale();
  2076.         $this->data['locale'] = $locale;
  2077.         /*
  2078.          * On vérifie si l'utilisateur est connecté
  2079.          */
  2080.         $status $loginManager->isConnecte($nomAction$paramRepositor,$connexionRepository$actionRepository);
  2081.         if ($status['isConnecte']) {
  2082.             /*
  2083.              * Au cas ou l'utilisateur est connecté on vérifie s'il nest pas innactif. S'il est innactif
  2084.              * on garde en mémoire flash la route actuelle pour effectuer une redirection lors de la prochaine connexion
  2085.              */
  2086.             if ($status['isInnactif']) {
  2087.                 $routeName $request->get('_route');
  2088.                 $routeParams $request->get('_route_params');
  2089.                 $this->get('session')->getFlashBag()->add('restoreUrl'$this->generateUrl($routeName$routeParams));
  2090.                 $this->get('session')->getFlashBag()->add('ina'$this->translator->trans("site.long.periode"));
  2091.                 return $this->redirect($this->generateUrl('app_logout'));
  2092.             }
  2093.             /*
  2094.              * Seuls les utilisateurs admins ont le droit d'acceder à cette action
  2095.              */
  2096.             if (!$status['isUser']) {
  2097.                 return $this->redirect($this->generateUrl('app_logout'));
  2098.             }
  2099.         } else {
  2100.             return $this->redirect($this->generateUrl('app_logout'));
  2101.         }
  2102.         /*
  2103.          * Gestion des droits
  2104.          */
  2105.         if (!$loginManager->getOrSetActions(Module::MOD_GEST_FOURModule::MOD_GEST_FOUR_DESC$this->getNomClassRun(__CLASS__), $this->description$nomAction$descAction$sessionData['idProfil'], $moduleRepository$controleurRepository$actionRepository$profilRepository)) {
  2106.             $this->logMessage .= ' [ TENTATIVE DE VIOLATION DE DROITS ] ';
  2107.             $this->get('session')->getFlashBag()->add('access'"Vous n'avez pas le droit d'accéder à cette page");
  2108.             return $this->redirect($this->generateUrl('app_admin_user_access_refuse'));
  2109.         }
  2110.         try {
  2111.             /*
  2112.              * Récupération des la liste des critères
  2113.              */
  2114.             $em $this->getDoctrine()->getManager();
  2115.             $listeOperation $em->getRepository($this->stockBundle 'Operation')->getAllOperation();
  2116.         } catch (\Exception $e) {
  2117.             var_dump($e->getMessage());
  2118.             exit;
  2119.         }
  2120.         // var_dump($listeOperation);exit;
  2121.         /*
  2122.          * Préparation des informations que nous allons traiter  sur le twig
  2123.          */
  2124.         $this->data['listeOperation'] = $listeOperation;
  2125.         $this->data['locale'] = $locale;
  2126.         return $this->render($this->stockBundleSlash($sessionData['typePresentation']). '/Operation/listeOperation.html.twig'$this->data$this->response);
  2127.     }
  2128.     public function mettreAJourCommande($em$idCom) {
  2129.         $laCommande $em->getRepository($this->stockBundle 'Commande')->find($idCom);
  2130.         $laCommande->setEtatCommande(\Types\user\TypeEtat::INACTIF);
  2131.         $laCommande->setMontantResteCommande(\Types\user\TypeEtat::APRODUIRE);
  2132.         $em->persist($laCommande);
  2133.         $em->flush();
  2134.     }
  2135.     public function cellAutoSize($excelService) {
  2136.         foreach (range('A''M') as $columnID) {
  2137.             $excelService->getActiveSheet()->getColumnDimension($columnID)
  2138.                     ->setAutoSize(true);
  2139.         }
  2140.     }
  2141.     public function applyStyleCell($excelService$aux) {
  2142.         if ($aux == 0) {
  2143.             $color 'ddebf7';
  2144.         } else {
  2145.             $color 'ffffff';
  2146.         }
  2147.         $styleArray = array(
  2148.             'font' => array(
  2149.                 'color' => array('rgb' => '000'),
  2150.                 'size' => 13,
  2151.                 
  2152.                 'type' => PHPExcel_Style_Fill::FILL_SOLID,
  2153.                 'startcolor' => array(
  2154.                     'rgb' => $color
  2155.                 )
  2156.         ));
  2157.         $styleArray_2 = array(
  2158.             'font' => array(
  2159.                 'color' => array('rgb' => 'f00'),
  2160.                 'size' => 14,
  2161.                 'bold' => true
  2162.         ));
  2163. //        foreach (range('A', 'M') as $columnID) {
  2164. //
  2165. //            $excelService->getActiveSheet()
  2166. //                    ->getStyle($columnID . $aux)->applyFromArray($styleArray);
  2167. //            var_dump($columnID . $aux);exit;
  2168. //            $excelService->getActiveSheet()->getStyle($columnID . $aux)->getFill()
  2169. //                    ->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
  2170. //                    ->getStartColor()
  2171. //                    ->setRGB($color);
  2172.         //}
  2173.         
  2174.             $excelService->getActiveSheet()
  2175.                ->getStyle('A10:M10')->applyFromArray($styleArray_2);
  2176.             
  2177.             $excelService->getActiveSheet()
  2178.                ->getStyle('A3:B3')->applyFromArray($styleArray);
  2179.             $excelService->getActiveSheet()
  2180.                ->getStyle('A4:B4')->applyFromArray($styleArray);
  2181.             $excelService->getActiveSheet()
  2182.                ->getStyle('A5:B5')->applyFromArray($styleArray);
  2183.             $excelService->getActiveSheet()
  2184.                ->getStyle('A6:B6')->applyFromArray($styleArray);
  2185.             
  2186.             $excelService->getActiveSheet()
  2187.                        ->getStyle('A'$aux.':'.'M'.$aux)->applyFromArray($styleArray);
  2188.                 
  2189.             $excelService->getActiveSheet()
  2190.                 ->getStyle('A'$aux.':'.'M'.$aux)
  2191.                 ->getFill()
  2192.                 ->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
  2193.                 ->getStartColor()
  2194.                 ->setRGB($color);
  2195.        
  2196.          
  2197.     }
  2198.         /**
  2199.      * Methode s'occupant de lister les Operations.
  2200.      *
  2201.      * @author armand.tevi@gmail.com
  2202.      * @copyright ADMIN 2015
  2203.      *
  2204.      * @version 1
  2205.      *
  2206.      * @return twig d'ajout d'un abonne listeOperation.html.twig
  2207.      */
  2208.     public function listeSuivieLivraisonAction(Request $request$type,$datefin$datedeb$ville) {
  2209.                                /*
  2210.          * Nom de l'action en cours
  2211.          */
  2212.         $nomAction __FUNCTION__;
  2213.         /*
  2214.          * Description de l'action de l'action en cours
  2215.          */
  2216.         $descAction "Liste des opérations préfinancements et livraisons ";
  2217.         $locale ='fr';
  2218.         $valRetour =$this->gestionDroitUtil($request$nomAction$descAction,$this->moduleTitre,$this->moduleDesc$loginManager,$paramRepositor,$connexionRepository$actionRepository$moduleRepository$controleurRepository$profilRepository );
  2219.         if($valRetour==1){
  2220.             return $this->redirect($this->generateUrl('app_logout'));
  2221.         }elseif($valRetour==2){
  2222.             return $this->redirect($this->generateUrl('app_admin_user_access_refuse'));
  2223.         }
  2224.         $sessionData $this->infosConnecte($request$loginManager$paramRepositor,$connexionRepository$actionRepository);;
  2225.          $prod $sessionData["produit_id"];
  2226.         $em $this->getDoctrine()->getManager();
  2227.         $total 10//$em->getRepository("adminStockBundle:Operation")->getTotalOperationsBrouillard($caisse, $datedeb, $datefin, $typeop, $typedate);
  2228.         if ($request->getMethod() == 'POST') {
  2229.             $datefin strtolower($request->get('datefin_'));
  2230.             $request->attributes->set('datefin_'$datefin);
  2231.             $datedeb strtolower($request->get('datedeb_'));
  2232.             $request->attributes->set('datedeb_'$datedeb);
  2233.             $ville strtolower($request->get('ville_'));
  2234.             $request->attributes->set('ville_'$ville);
  2235.         }
  2236.         $listeOperation $em->getRepository($this->stockBundle 'Operation')->getOperationsSuivieLivraison($datedeb$datefin$typeop '0'$ville);                
  2237.         $excelService = new PHPExcel();
  2238.         $excelService->getProperties()
  2239.                 ->setTitle("OPERATIONS DE LIVRAISON ")
  2240.                 ->setDescription("LISTE DES OPERATIONS DE LIVRAISON");
  2241.         $excelService->getActiveSheet()->setTitle('Liste des Operations ');
  2242.         $excelService->setActiveSheetIndex(0);
  2243.         $lesCriteres $this->RecuperCritereRechercheSuivie($em,$datefin,$datedeb,  $ville);
  2244.         //create the response
  2245.         $excelService->setActiveSheetIndex(0)
  2246.                 ->setCellValue('A1''')//DETAILS DES OPERATIONS DE GESTIONS DES AVANCES ET DE LIVRAISON DES COLLECTES DE CACAO
  2247.                 ->setCellValue('B1''')
  2248.                 ->setCellValue('C1''')
  2249.                 ->setCellValue('E1''')
  2250.                 ->setCellValue('F1''')
  2251.                 ->setCellValue('G1''')
  2252.                 ->setCellValue('H1''')
  2253.                 ->setCellValue('I1''');
  2254.                 
  2255.         $excelService->setActiveSheetIndex(0)
  2256.                 ->setCellValue('A3''Ville :')
  2257.                 ->setCellValue('B3'$lesCriteres['nomVille']);
  2258.         
  2259.         $excelService->setActiveSheetIndex(0)
  2260.                 ->setCellValue('A4''Date début :')
  2261.                 ->setCellValue('B4'$lesCriteres['dateDebut']);
  2262.         
  2263.         $excelService->setActiveSheetIndex(0)
  2264.                 ->setCellValue('A5''Date fin')
  2265.                 ->setCellValue('B5'$lesCriteres['dateFin']);
  2266.         $excelService->setActiveSheetIndex(0)
  2267.                 ->setCellValue('A7''Zone')
  2268.                 ->setCellValue('B7''Date')
  2269.                 ->setCellValue('C7''Type operation')
  2270.                 ->setCellValue('D7''intitulé')
  2271.                 ->setCellValue('E7''Montant')
  2272.                 ->setCellValue('F7''Montant')
  2273.                 ->setCellValue('G7''Solde')
  2274.                 ->setCellValue('H7''Stock en route')
  2275.                 ->setCellValue('I7''Sortie');
  2276.         $locale ="fr";
  2277.         $aux 8;
  2278.         if ($type == 1) {
  2279.             foreach ($listeOperation as $row) {
  2280.                 $datop null;
  2281.                 $daval null;
  2282.                 
  2283.                 if( $row->getTypeoperation() == 1){
  2284.                 
  2285.                 $excelService->setActiveSheetIndex(0)
  2286.                         ->setCellValue('A' $aux$row->getVille()->getNomVille()) //$row['dateOperation']
  2287.                         ->setCellValue('B' $aux$row->getDateSuivie()->format("d/M/Y"))
  2288.                         ->setCellValue('C' $aux"Achat")
  2289.                         ->setCellValue('D' $aux$row->getInstitule())//$row['dateValeur']
  2290.                         ->setCellValue('E' $aux$row->getMontant())
  2291.                         ->setCellValue('F' $aux"")
  2292.                         ->setCellValue('G' $aux"")
  2293.                         ->setCellValue('H' $aux"")
  2294.                         ->setCellValue('I' $aux"")
  2295.                 ;
  2296.                 
  2297.                 }else{
  2298.                      $excelService->setActiveSheetIndex(0)
  2299.                         ->setCellValue('A' $aux$row->getVille()->getNomVille()) //$row['dateOperation']
  2300.                         ->setCellValue('B' $aux$row->getDateSuivie()->format("d/M/Y"))
  2301.                         ->setCellValue('C' $aux"Achat")
  2302.                         ->setCellValue('D' $aux$row->getInstitule())//$row['dateValeur']
  2303.                         ->setCellValue('E' $aux$row->getMontant())
  2304.                         ->setCellValue('F' $aux"")
  2305.                         ->setCellValue('G' $aux"")
  2306.                         ->setCellValue('H' $aux"")
  2307.                         ->setCellValue('I' $aux"");  
  2308.                 }
  2309.                 $this->applyStyleCell($excelService$aux);
  2310.                 $aux++;
  2311.                 
  2312.                 $this->cellAutoSize($excelService);
  2313.                 // Set active sheet index to the first sheet
  2314.                 
  2315.                 $excelService->getActiveSheet()->getStyle('E' $aux)->getNumberFormat()->applyFromArray(
  2316.                         array(
  2317.                             'code' => '# ### ### ### ###_-'
  2318.                         )
  2319.                 );
  2320.                 
  2321.             }
  2322.             $response = new Response();
  2323. //        
  2324.         //elseif ($imprimer == 1) {
  2325.         if ($type == 1) {           
  2326.             //$response = $excelService->getResponse();
  2327.             $response->headers->set('Content-Type''text/vnd.ms-excel; charset=utf-8');
  2328.             $response->headers->set('Content-Disposition''attachment;filename=fichier_excel_operation_gestion_collect-' date("Y_m_d_His") . '.xls');
  2329.             //$response->prepare();            
  2330.             $response->sendHeaders();
  2331.             $objWriter PHPExcel_IOFactory::createWriter($excelService'Excel5');
  2332.             $objWriter->save('php://output');
  2333.             exit();
  2334.         }
  2335.         // Quand le telechargement doit etre en csv
  2336.         elseif ($type == 2) {
  2337.             $this->data['listeCommande'] = $listeOperation;
  2338.             $this->data['lesCriteres'] = $lesCriteres;
  2339.             return $this->render($this->stockBundleSlash($sessionData['typePresentation']). '/Operation/impressionLigneCommande.html.twig'$this->data$this->response);
  2340.         }
  2341.         // Quand le telechargement doit etre en fichier txt
  2342.         elseif ($type == 3) {
  2343.             $aux 0;
  2344.             $handle fopen('php://memory''r+');
  2345.             $header = array();
  2346.             $donneperation null;
  2347.             $donneperation = array();
  2348.             $i 0;
  2349.             $separateur chr(9);
  2350.             foreach ($listeOperation as $operation) {
  2351.                 $donneperation[$i] = "" $operation['dateOperation']->format("d/m/Y") . "" $separateur "" $operation['numMvt'] . "" $separateur "" $operation['libOperation'] . "" $separateur "" $operation['montant'] . "\r\n";
  2352.                 //var_dump($donneperation[$i]);exit;
  2353.                 fputcsv($handle$donneperation);
  2354.                 $i++;
  2355.             }
  2356.             $response $this->render('adminStockBundle:Operation:export_txt.html.twig', array('donneperation' => $donneperation), $this->response);
  2357.             $filename "export_" date("Y_m_d_His") . ".txt";
  2358.             $response->headers->set('Content-Type''text/txt');
  2359.             $response->headers->set('Content-Disposition''attachment; filename=' $filename);
  2360.             return $response;
  2361.         }
  2362.         // Quand le telechargement doit etre en fichier pdf
  2363.         elseif ($type == 4) {
  2364.             ob_start();
  2365.             $donneperation $this->get('templating')->render('adminStockBundle:Operation:impression.html.twig', array('locale' => $locale'listeOperation' => $listeOperation));
  2366.             $html2pdf = new HTML2PDF('P''A4''fr');
  2367.             $html2pdf->WriteHTML($donneperationtrue);
  2368.             exit;
  2369.             $fichier $html2pdf->Output('exemple.pdf');
  2370.             $response = new Response();
  2371.             $response->clearHttpHeaders();
  2372.             $response->setContent(file_get_contents($fichier));
  2373.             $response->headers->set('Content-Type''application/force-download');
  2374.             $response->headers->set('Content-disposition''filename=' $fichier);
  2375.             return $response;
  2376.         } else {
  2377.              $listeVille $em->getRepository($this->stockBundle 'Ville')->getAllActiveVille($prod);
  2378.             //Recuperer la liste des villes
  2379.             $this->data['datefin_'] = $datefin;
  2380.             $this->data['datedeb_'] = $datedeb;
  2381.             $this->data['ville_'] = $ville;
  2382.             $this->data['afficher'] = 1;
  2383.             $this->data['listeVille'] = $listeVille;
  2384.             $this->data['listeOperation'] = $listeOperation;
  2385.             return $this->render('adminStockBundle:InfoLivrer:suivieLivraison.html.twig',$this->data);
  2386.         }
  2387.     }  
  2388.     
  2389.     public function exportOpertionPaiementMobileAction(Request $request,$datedeb$datefin$four$ville$prix,$prod$typepaiement$type){ 
  2390.         
  2391.         //(Request $request, $type, $etat, $nomcol, $datefin, $datedeb, $ville, $util, $silivre, $numcom) {
  2392.         //$session = $this->getRequest()->getSession();
  2393.         
  2394.         $sessionData $this->infosConnecte($request$loginManager$paramRepositor,$connexionRepository$actionRepository);;
  2395.         $prod $sessionData["produit_id"];
  2396.         //var_dump($prod);exit;
  2397.         $em $this->getDoctrine()->getManager();
  2398.         //var_dump($currentConnete["listeActions_abonne"]);exit;
  2399.         global $listeOperation$articles_per_page$last_page$previous_page$next_page$total;
  2400.         //$typeOperation = $em->getRepository("adminStockBundle:TypeOperation")->findAll();
  2401.         $total 10//$em->getRepository("adminStockBundle:Operation")->getTotalOperationsBrouillard($caisse, $datedeb, $datefin, $typeop, $typedate);
  2402.         //$listeOperation = $em->getRepository($this->stockBundle . 'Commande')->getListeRechercheCommande($nomcol, $datefin, $datedeb, $ville, $util, $silivre, $numcom,$prod);
  2403.          $listeOperation $em->getRepository($this->stockBundle 'InfoLivrer')->getRechercheInfoLivrerPaiementMobile($four$ville$datedeb$datefin$prix,0,$prod,$typepaiement);
  2404.               
  2405.         
  2406.         $excelService = new PHPExcel();
  2407.         $excelService->getProperties()
  2408.                 ->setTitle("Opérations de payement mobile ")
  2409.                 ->setDescription("Opérations de payement mobile");
  2410.         $excelService->getActiveSheet()->setTitle('Liste des Operations ');
  2411.         $excelService->setActiveSheetIndex(0);
  2412.         //$lesCriteres = $this->RecuperCritereRecherche($em, $nomcol,   $datefin,$datedeb,  $ville, $util, $silivre, $numcom);
  2413.         //create the response
  2414.         $excelService->setActiveSheetIndex(0)
  2415.                 ->setCellValue('A1''Numéro Tel')//DETAILS DES OPERATIONS DE GESTIONS DES AVANCES ET DE LIVRAISON DES COLLECTES DE CACAO
  2416.                 ->setCellValue('B1''Prénom')
  2417.                 ->setCellValue('C1''Nom')
  2418.                 ->setCellValue('D1''Montant')
  2419.                 ->setCellValue('E1''CFA')
  2420.                 ->setCellValue('F1''Motif de paiement');
  2421.         
  2422.         $aux 2;
  2423.         
  2424.         if ($type == 1) {
  2425.             //var_dump(count($listeOperation),count($listeOperation));exit;
  2426.             foreach ($listeOperation as $row) {
  2427.                 $datop null;
  2428.                 $daval null;
  2429.                 //Montant paiement
  2430.                 $montant $row->getPrixrigueur()->getInfoPrixRigueur()*$row->getNbreTotalLivre();
  2431.                 $infoIdentite $row->getLivrers()[0]->getLigneCommande()->getProducteur()->getUtilisateur()->getNom();
  2432.                 $tabIdentite explode(" "$infoIdentite);
  2433.                 //var_dump(count($row->getLivrers()));exit;
  2434.                 $excelService->setActiveSheetIndex(0)
  2435.                         ->setCellValue('A' $aux"228".$row->getLivrers()[0]->getLigneCommande()->getProducteur()->getUtilisateur()->getTel1()) //$row['dateOperation']
  2436.                         ->setCellValue('B' $aux$tabIdentite[1])
  2437.                         ->setCellValue('C' $aux$tabIdentite[0])
  2438.                         ->setCellValue('D' $aux$montant)//$row['dateValeur']
  2439.                         ->setCellValue('E' $aux"952")
  2440.                         ->setCellValue('F' $aux"Paiement achat produit agricole")                       
  2441.                 ;               
  2442.                 
  2443.                 //$this->applyStyleCell($excelService, $aux);
  2444.                 
  2445.                 
  2446.                 $this->cellAutoSize($excelService);
  2447.                 // Set active sheet index to the first sheet                
  2448.                 $excelService->getActiveSheet()->getStyle('D' $aux)->getNumberFormat()->applyFromArray(
  2449.                         array(
  2450.                             'code' => '# ### ### ### ###_-'
  2451.                         )
  2452.                 );
  2453.                 $aux++;                
  2454.             }
  2455.             $response = new Response();
  2456. //        
  2457.         
  2458.         if ($type == 3) {           
  2459.             //$response = $excelService->getResponse();
  2460.             $response->headers->set('Content-Type''text/vnd.ms-excel; charset=utf-8');
  2461.             $response->headers->set('Content-Disposition''attachment;filename=fichier_excel_operation_gestion_collect-' date("Y_m_d_His") . '.csv');
  2462.             //$response->prepare();            
  2463.             $response->sendHeaders();
  2464.             $objWriter PHPExcel_IOFactory::createWriter($excelService'Excel5');
  2465.             $objWriter->save('php://output');
  2466.             exit();
  2467.         }
  2468.          
  2469.       if ($type == 5) {           
  2470.             //$response = $excelService->getResponse();
  2471.             $response->headers->set('Content-Type''text/vnd.ms-excel; charset=utf-8');
  2472.             $response->headers->set('Content-Disposition''attachment;filename=fichier_excel_operation_gestion_collect-' date("Y_m_d_His") . '.xls');
  2473.             //$response->prepare();            
  2474.             $response->sendHeaders();
  2475.             $objWriter PHPExcel_IOFactory::createWriter($excelService'Excel5');
  2476.             $objWriter->save('php://output');
  2477.             exit();
  2478.         }
  2479.         // Quand le telechargement doit etre en csv
  2480.         elseif ($type == 2) {
  2481.             $this->data['listeCommande'] = $listeOperation;
  2482.             $this->data['lesCriteres'] = $lesCriteres;
  2483.             return $this->render($this->stockBundleSlash($sessionData['typePresentation']). '/Operation/impressionLigneCommande.html.twig'$this->data$this->response);
  2484.         }
  2485.         // Quand le telechargement doit etre en fichier txt
  2486.         elseif ($type == 1) {
  2487.             $aux 0;
  2488.             $handle fopen('php://memory''r+');
  2489.             $header = array();
  2490.             $donneperation null;
  2491.             $donneperation = array();
  2492.              $separateur chr(59);
  2493.             $i 0;
  2494.              $donneperation[$i] = "" "Numero" $separateur "Nom" $separateur "Prenom" $separateur "montant" $separateur "motif".$separateur "statut""";
  2495.                 
  2496.              foreach ($listeOperation as $row) {
  2497.                   ++$i;
  2498.                 $datop null;
  2499.                 $daval null;
  2500.                 //Montant paiement
  2501.                 $montant $row->getPrixrigueur()->getInfoPrixRigueur()*$row->getNbreTotalLivre();
  2502.                 $infoIdentite $row->getLivrers()[0]->getLigneCommande()->getProducteur()->getUtilisateur()->getNom();
  2503.                 $tabIdentite explode(" "$infoIdentite);             
  2504.                 $donneperation[$i] = "" "228".$row->getLivrers()[0]->getLigneCommande()->getProducteur()->getUtilisateur()->getTel1() . "" $separateur "" $tabIdentite[1] . "" $separateur "" .  $tabIdentite[0] . "" $separateur "" $montant ."" $separateur "952".$separateur "Paiement achat produit agricole""";
  2505.                 fputcsv($handle$donneperation);   
  2506.             }
  2507.            
  2508.             $response $this->render('adminStockBundle:Operation:export_csv.html.twig', array('donneperation' => $donneperation), $this->response);
  2509.             $filename "export_" date("Y_m_d_His") . ".csv";
  2510.             $response->headers->set('Content-Type''text/csv');
  2511.             $response->headers->set('Content-Disposition''attachment; filename=' $filename);
  2512.             return $response;
  2513.         }
  2514.         // Quand le telechargement doit etre en fichier pdf
  2515.         elseif ($type == 4) {
  2516.             ob_start();
  2517.             $donneperation $this->get('templating')->render('adminStockBundle:Operation:impression.html.twig', array('locale' => $locale'listeOperation' => $listeOperation));
  2518.             $html2pdf = new HTML2PDF('P''A4''fr');
  2519.             $html2pdf->WriteHTML($donneperationtrue);
  2520.             exit;
  2521.             $fichier $html2pdf->Output('exemple.pdf');
  2522.             $response = new Response();
  2523.             $response->clearHttpHeaders();
  2524.             $response->setContent(file_get_contents($fichier));
  2525.             $response->headers->set('Content-Type''application/force-download');
  2526.             $response->headers->set('Content-disposition''filename=' $fichier);
  2527.             return $response;
  2528.         } elseif ($type == 10) {
  2529.             return $this->render('adminStockBundle:operation:brouillardCaisse.html.twig');
  2530.         }
  2531.     }
  2532.    
  2533. }