src/Services/stock/OperationManager.php line 127

Open in your IDE?
  1. <?php
  2. /*
  3.  * Description of LoginManager
  4.  * Service de gestion des connexions et des droits des utilisateurs.
  5.  *
  6.  * @author Jerome
  7.  */
  8. namespace App\Services\stock;
  9. use \Doctrine\ORM\EntityManagerInterface;
  10. use \PDO;
  11. use App\ControllerModel\user\paramUtilTrait;
  12. /**
  13.  * ConfigManager
  14.  * 
  15.  * Service de gestion des configurations de l'application
  16.  * 
  17.  */
  18. class OperationManager {
  19. use paramUtilTrait;
  20.     
  21.     /*
  22.      *
  23.      * @var \Doctrine\ORM\EntityManagerInterface  $em : gestionnaire d'entité
  24.      * 
  25.      */
  26.     private $em;
  27.    
  28.     /*
  29.      * le constructeur qui initialise les attributs
  30.      * 
  31.      * @param \Doctrine\ORM\EntityManager $em
  32.      */
  33.     public function __construct(EntityManagerInterface $em) {
  34.         $this->em $em;       
  35.     }
  36.     
  37.  /*
  38.      * Retourne un nom par defaut lors de la création d'un nouveau param
  39.      * @return type
  40.      */
  41.     public function getListeLigneCommande($code=0,$type=0) {
  42.             $sql '
  43.                     SELECT * FROM commande c 
  44.                              JOIN lignecommande l on c.id = l.commande_id                             
  45.                              JOIN produit p on p.id = l.produit_id  ';
  46.             if($type == 2){
  47.                  $sql .= ' JOIN abonne a on c.abonne_id = a.id '
  48.             }else if($type == 1){
  49.                  $sql .= ' JOIN fournisseur f on c.fournisseur_id = f.id ';
  50.             }
  51.             $sql .= '                         
  52.                              JOIN livrer li on li.lignecommande_id = l.id where  c.code_commande = :code';
  53.             $stmt $this->em->getConnection()->prepare($sql);
  54.              // var_dump($sql)   ;exit;
  55.             try {
  56.                 $stmt->bindValue(':code'$codePDO::PARAM_STR);
  57.                 $stmt->execute();
  58.                 $result $stmt->fetchAll(PDO::FETCH_ASSOC);
  59.             } catch (\Exception $e) {
  60.                 var_dump($e->getMessage());
  61.                 exit;
  62.             }
  63.             return $result ;
  64.         
  65.     }  
  66.     
  67. /*
  68.      * Retourne un nom par defaut lors de la création d'un nouveau param
  69.      * @return type
  70.      */
  71.     public function geneLigneOperation($commande_id=0,$caisse_id=0,$montant=0$nom_deposant=0$ref_facture) {
  72.         
  73.         $date_operation'2013-03-26';
  74.         $date_valeur'2013-03-26';
  75.         $comptabilise=0;
  76.         $piece_operation 0;
  77.         
  78.       
  79.         
  80.         $sql "
  81.                 INSERT  INTO  operation(commande_id,caisse_id, date_operation, 
  82.                                         date_valeur, piece_operation, montant, 
  83.                                         comptabilise, nom_deposant,etat_operation,ref_facture)
  84.                               values(:commande_id,:caisse_id,:date_operation,
  85.                                     :date_valeur,:piece_operation,:montant,
  86.                                     :comptabilise,:nom_deposant,1, :ref_facture) ";
  87.         $stmt $this->em->getConnection()->prepare($sql);
  88.         
  89.         try {
  90.             $stmt->bindParam(':caisse_id'$caisse_idPDO::PARAM_STR);
  91.             $stmt->bindParam(':commande_id'$commande_idPDO::PARAM_STR);
  92.             
  93.             $stmt->bindParam(':date_operation'$date_operationPDO::PARAM_STR);
  94.             
  95.             $stmt->bindParam(':piece_operation'$piece_operationPDO::PARAM_INT);
  96.             
  97.             $stmt->bindParam(':date_valeur'$date_valeurPDO::PARAM_STR);
  98.             $stmt->bindParam(':montant'$montantPDO::PARAM_STR);
  99.             $stmt->bindParam(':comptabilise'$comptabilisePDO::PARAM_STR);
  100.             $stmt->bindParam(':nom_deposant'$nom_deposantPDO::PARAM_STR);
  101.             $stmt->bindParam(':ref_facture'$ref_facturePDO::PARAM_STR);
  102.              //var_dump($commande_id,$caisse_id,$date_operation,$piece_operation,$date_valeur,$montant,$comptabilise,$nom_deposant,$ref_facture); exit;             
  103.             $stmt->execute();                       
  104.         } catch (\Exception $e) {
  105.             var_dump($e->getMessage());
  106.             return false ;
  107.         }
  108.         return true ;
  109.         
  110.     }    
  111.     
  112.     
  113.   /*
  114.      * Retourne un nom par defaut lors de la création d'un nouveau param
  115.      * @return type
  116.      */
  117.     public function geneLigneOperationComptableNouveau($commande_id 0$caisse_id 0$montant $nom_deposant 0,$tel_deposant=''$ref_facture,$num_cheque=0$compte_cheque=0$idTypeOp 0,$piece_operation =0,$compte_client='',$type_paye='',$idProduit='',$compte_auxi='',$datechoix='',$idVille=''$idAbonne='',$idUtil=Null,$analytique=0,$idPres=0) {        
  118.         // requete d'insertion de l'ecrirure comptable   dans table tmp 
  119.         $res 0;
  120.         $comptabilise 0;                           
  121.         $sqltypeOp "";
  122.         $sqltypeOp .= " select t.idtypeoperation , t.libtypeoperation , s.sens, s.compte, t.codeoperation, p.libelle
  123.                                   from schemacomptable s inner join typeoperation t
  124.                                        on t.idtypeoperation = s.idtypeoperation
  125.                                     inner join plancomptable p
  126.                                        on s.compte = p.compte
  127.                                   where t.idtypeoperation = :idtypeop   
  128.                                   order by s.sens desc ";
  129.         $stmttypeop $this->em->getConnection()->prepare($sqltypeOp);
  130.         $stmttypeop->bindParam(':idtypeop'$idTypeOpPDO::PARAM_INT);
  131.         try {
  132.             $stmttypeop->execute();
  133.             $listetypeOp $stmttypeop->fetchAll(PDO::FETCH_ASSOC);
  134.         } catch (\Exception $e) {
  135.             //var_dump($e->getMessage());
  136.             exit;
  137.         }
  138.         
  139.         
  140.         if (is_array($listetypeOp) && count($listetypeOp) > 0) {
  141.             
  142.             $sql " INSERT  INTO  operation
  143.                                         ( commande_id,caisse_id, date_operation, 
  144.                                         date_valeur, piece_operation, montant, 
  145.                                         comptabilise, nom_deposant,tel_deposant,
  146.                                         etat_operation,ref_facture, compte, cheque,
  147.                                         sensoperation,compte_client, idtypeoperation,num_mvt, lib_operation,
  148.                                         type_traite_operation, produit_id, compte_auxiliaire, ville_id, id_abonne, utilisateur_id, plan_analytique, prestataire_id)
  149.                               values
  150.                                         (:commande_id,:caisse_id,:date_operation,
  151.                                         :date_valeur,:piece_operation,:montant,
  152.                                         :comptabilise,:nom_deposant,:tel_deposant,
  153.                                         1, :ref_facture,:compte,:cheque,
  154.                                         :sensoperation, :compte_client, :idtypeoperation, :num_mvt, :lib_operation
  155.                                         ,:type_traite_operation, :produit_id, :compte_auxiliaire, :ville_id, :id_abonne, :utilisateur_id, :plan_analytique, :prestataire_id) ";
  156.             // exit;
  157.             
  158.             $stmt $this->em->getConnection()->prepare($sql);
  159.             //if($idCaisse != 0)
  160.             // $datechoix = implode('/', array_reverse( explode('/',$datechoix) ) ) ;
  161.             
  162.             //$dateAutor = new \DateTime($datechoix); 
  163.            
  164.             //$dateAutor->setDate((int) substr($dateo, 0, 4), (int) substr($dateo, 5, 2), (int) substr($dateo, 8, 2));
  165.             // $dateAutor = $dateAutor->format('Y-m-d H:i:s');
  166.            
  167.             // $dateAutor->setDate((int) substr($dateo, 0, 4), (int) substr($dateo, 5, 2), (int) substr($dateo, 8, 2));
  168.            $an=substr($dateAutor04);
  169.            $m=substr($dateAutor52);
  170.            $datev $dateAutor;
  171.            $idUser=1;
  172.            $idCaisse=1;
  173.            $util $this->em->getRepository("adminUserBundle:Utilisateur")->find($idUser);
  174.            $cash $this->em->getRepository("adminStockBundle:Caisse")->find($idCaisse);
  175.             
  176.             $j=0;
  177.             foreach ($listetypeOp as $key => $value) {
  178.                 // var_dump($dateAutor);exit; 
  179.                 $i 1;              
  180.                 $datevaleur $datev;
  181.                 // $lib =  '' ;//$this->em->getRepository("adminStockBundle:TypeOperation")->find($idTypeOp);
  182.                 //$annule = $lib->getId();               
  183.                 $lib ''.$nom_deposant[$value['sens']];   
  184.                 
  185.                 $cle "";
  186. //                        if (strtolower($value['codeoperation']) == 'ccc') $comptabilise = 2;                                               
  187.                 $datej 111;//$this->GetDatJulienne($this->em);
  188.                 $numMvt $this->getNumMvt($this->em1$an$m$entite 'LIVRER'$taille 5);;
  189.          
  190.                 $leComptePlanC $value['compte'];//$compte_cheque[$j];
  191.                 $leMontantPaye =$montant[$j];
  192.                                             
  193.                 if ($i == 1) {
  194.                     $stmt->bindParam(':caisse_id'$caisse_idPDO::PARAM_STR); //var_dump($caisse_id);
  195.                     $stmt->bindParam(':commande_id'$commande_idPDO::PARAM_STR);//var_dump($commande_id);
  196.                     $stmt->bindParam(':date_operation'$datechoixPDO::PARAM_STR);//var_dump($dateAutor);
  197.                     $stmt->bindParam(':piece_operation'$piece_operationPDO::PARAM_INT);//var_dump($piece_operation);
  198.                     $stmt->bindParam(':sensoperation'$value['sens'], PDO::PARAM_STR);//var_dump($value['sens']);
  199.                     $stmt->bindParam(':date_valeur'$datevPDO::PARAM_STR);//var_dump($datev);
  200.                     $stmt->bindParam(':montant'$leMontantPayePDO::PARAM_STR);//var_dump($leMontantPaye);
  201.                     $stmt->bindParam(':comptabilise'$comptabilisePDO::PARAM_STR);//var_dump($comptabilise);
  202.                     $stmt->bindParam(':nom_deposant'$libPDO::PARAM_STR);//var_dump($nom_deposant);
  203.                     $stmt->bindParam(':tel_deposant'$tel_deposantPDO::PARAM_STR);//var_dump($tel_deposant);
  204.                     $stmt->bindParam(':compte'$leComptePlanCPDO::PARAM_STR);//var_dump($leComptePlanC);
  205.                     $stmt->bindParam(':compte_client'$compte_clientPDO::PARAM_STR);//var_dump($compte_client);
  206.                     $stmt->bindParam(':cheque'$num_chequePDO::PARAM_STR);//var_dump($num_cheque);
  207.                     $stmt->bindParam(':idtypeoperation'$idTypeOpPDO::PARAM_STR);//var_dump($idTypeOp);
  208.                     $stmt->bindParam(':ref_facture'$ref_facturePDO::PARAM_STR);//var_dump($ref_facture);
  209.                     $stmt->bindParam(':num_mvt'"MVT".$ref_facturePDO::PARAM_STR);//var_dump($numMvt);
  210.                     $stmt->bindParam(':lib_operation'$libPDO::PARAM_STR);//var_dump($lib);
  211.                     $stmt->bindParam(':type_traite_operation'$type_payePDO::PARAM_STR);//var_dump($lib);
  212.                     $stmt->bindParam(':produit_id'$idProduitPDO::PARAM_INT);//var_dump($lib);
  213.                     $stmt->bindParam(':compte_auxiliaire'$compte_auxiPDO::PARAM_INT);//var_dump($lib);
  214.                     $stmt->bindParam(':ville_id'$idVillePDO::PARAM_INT);//var_dump($lib);
  215.                     $stmt->bindParam(':id_abonne'$idAbonnePDO::PARAM_INT);//var_dump($lib);
  216.                     $stmt->bindParam(':utilisateur_id'$idUtilPDO::PARAM_INT);//var_dump($lib);
  217.                     $stmt->bindParam(':plan_analytique'$analytiquePDO::PARAM_STR);//var_dump($lib);
  218.                     $stmt->bindParam(':fournisseur_id'$idPresPDO::PARAM_INT);//var_dump($lib);
  219.                   // var_dump($caisse_id,$commande_id,$dateAutor,$piece_operation,$value['sens'],$datev,$leMontantPaye,$comptabilise,$nom_deposant,$tel_deposant,$leComptePlanC,$leComptePlanC,$compte_client,$num_cheque,$idTypeOp,$ref_facture,$numMvt,$lib,$type_paye,$id_abonne,$compte_auxi);exit;
  220.                 }
  221.                  
  222.                 try {
  223.                   $stmt->execute();
  224.                 } catch (\Exception $e) {
  225.                     $res 1;
  226.                     //var_dump($e->getMessage());
  227.                     exit;
  228.                 }
  229.                // var_dump($numMvt);exit;
  230.                 $i++;
  231.                 $j++;
  232.             }
  233.         }
  234.         //exit;
  235.         // retourner le numero de piece pour l'impression de l'ecriture
  236.         if ($res == 0)
  237.             $resulat 1;//$numpiece;
  238.         else
  239.             $resulat null;
  240.         return $resulat;
  241.     }
  242.     
  243.     /*
  244.      * Retourne un nom par defaut lors de la création d'un nouveau param
  245.      * @return type
  246.      */
  247.     public function geneLigneOperationComptable($commande_id 0$caisse_id 0$montant $nom_deposant 0,$tel_deposant=''$ref_facture,$num_cheque=0$compte_cheque=0$idTypeOp 0,$piece_operation =0,$compte_client='',$type_paye='',$idProduit='',$compte_auxi='',$datechoix='',$idVille=''$idAbonne='',$infolivrer_id=0$client=null$utilisateurRepository,$caisseRepository$producteurId=null,$fournisseurId=null$activiteId=null$surfaceAnneeId=null) {
  248.         
  249.         // requete d'insertion de l'ecrirure comptable   dans table tmp 
  250.         //var_dump($idAbonne);exit;
  251.         
  252.         $res 0;
  253.         $comptabilise 0;                           
  254.         $sqltypeOp "";
  255.         $sqltypeOp .= " select t.idtypeoperation , t.libtypeoperation , s.sens, s.compte, t.codeoperation, p.libelle
  256.                                   from schemacomptable s inner join typeoperation t
  257.                                        on t.idtypeoperation = s.idtypeoperation
  258.                                     inner join plancomptable p
  259.                                        on s.compte = p.compte
  260.                                   where t.idtypeoperation = :idtypeop   
  261.                                   order by s.sens desc "//$montantddddd;
  262.                                   
  263.         $stmttypeop $this->em->getConnection()->prepare($sqltypeOp);
  264.         $stmttypeop->bindParam(':idtypeop'$idTypeOpPDO::PARAM_INT);
  265.         try {
  266.             //$stmttypeop->execute();
  267.             //$listetypeOp = $stmttypeop->fetchAll(PDO::FETCH_ASSOC);
  268.             $listetypeOp $stmttypeop->executeQuery()->fetchAll();
  269.         } catch (\Exception $e) {
  270.             var_dump($e->getMessage());
  271.             exit;
  272.         }
  273.         
  274.        
  275.         
  276.         if (is_array($listetypeOp) && count($listetypeOp) > 0) {
  277.              
  278.            
  279.             $sql " INSERT  INTO  operation
  280.                                         ( commande_id,caisse_id, date_operation, 
  281.                                         date_valeur, piece_operation, montant, 
  282.                                         comptabilise, nom_deposant,tel_deposant,
  283.                                         etat_operation,ref_facture, compte, cheque,
  284.                                         sensoperation,compte_client, idtypeoperation,num_mvt, lib_operation,
  285.                                         type_traite_operation, produit_id, compte_auxiliaire,  abonne_id, infolivrer_id, type_operation,client_id,producteur_id, fournisseur_id, activite_id, surfaceannee_id)
  286.                               values
  287.                                         (:commande_id,:caisse_id,:date_operation,
  288.                                         :date_valeur,:piece_operation,:montant,
  289.                                         :comptabilise,:nom_deposant,:tel_deposant,
  290.                                         1, :ref_facture,:compte,:cheque,
  291.                                         :sensoperation, :compte_client, :idtypeoperation, :num_mvt, :lib_operation
  292.                                         ,:type_traite_operation, :produit_id, :compte_auxiliaire,  :abonne_id, :infolivrer_id, :typeoperation, :client_id, :producteurId, :fournisseurId, :activiteId, :surfaceAnneeId) "//:ville_id, //ville_id,
  293.              //exit;
  294.             
  295.             $stmt $this->em->getConnection()->prepare($sql);
  296.             //if($idCaisse != 0)
  297.            // $datechoix = implode('/', array_reverse( explode('/',$datechoix) ) ) ;
  298.             
  299.             $dateAutor $datechoix
  300.            
  301.             //$dateAutor->setDate((int) substr($dateo, 0, 4), (int) substr($dateo, 5, 2), (int) substr($dateo, 8, 2));
  302.            // $dateAutor = $dateAutor->format('Y-m-d H:i:s');
  303.            
  304.            // $dateAutor->setDate((int) substr($dateo, 0, 4), (int) substr($dateo, 5, 2), (int) substr($dateo, 8, 2));
  305.            $an=substr($dateAutor04);
  306.            $m=substr($dateAutor52);
  307.            $datev $dateAutor;
  308.            $idUser=1;
  309.            $idCaisse=1;
  310.            $util $utilisateurRepository->find($idUser);
  311.            $cash $caisseRepository->find($idCaisse);
  312.             
  313.             $j=0;
  314.             foreach ($listetypeOp as $key => $value) {
  315.                // var_dump($dateAutor);exit; 
  316.                 $i 1;
  317.                
  318.                 $datevaleur $datev;
  319.                 $lib '' ;//$this->em->getRepository("adminStockBundle:TypeOperation")->find($idTypeOp);
  320.                 //$annule = $lib->getId();
  321.                 if($lib == ''){
  322.                     $lib ''.$nom_deposant;
  323.                 }else{
  324.                     $lib='-';
  325.                 }
  326.                 $cle "";
  327. //                        if (strtolower($value['codeoperation']) == 'ccc') $comptabilise = 2;                                               
  328.                 $datej 111;//$this->GetDatJulienne($this->em);
  329.                 $numMvt $this->getNumMvt($this->em1$an$m$entite 'LIVRER'$taille 5);
  330.          
  331.                 $leComptePlanC $value['compte'];//$compte_cheque[$j];
  332.                 $leMontantPaye =$montant[$j];
  333.                // try {
  334.                                         
  335.                 if ($i == 1) {
  336.                     
  337.                     $stmt->bindParam(':caisse_id'$caisse_idPDO::PARAM_STR); //var_dump($caisse_id);
  338.                    // if($commande_id != null )
  339.                     $stmt->bindParam(':commande_id'$commande_idPDO::PARAM_STR);//var_dump($commande_id);
  340.                     $stmt->bindParam(':date_operation'$dateAutorPDO::PARAM_STR);//var_dump($dateAutor);
  341.                     
  342.                     $stmt->bindParam(':piece_operation'$piece_operationPDO::PARAM_INT);//var_dump($piece_operation);
  343.                     $stmt->bindParam(':sensoperation'$value['sens'], PDO::PARAM_STR);//var_dump($value['sens']);
  344.                     $stmt->bindParam(':date_valeur'$datevPDO::PARAM_STR);//var_dump($datev);
  345.                     $stmt->bindParam(':montant'$leMontantPayePDO::PARAM_STR);//var_dump($leMontantPaye);
  346.                     $stmt->bindParam(':comptabilise'$comptabilisePDO::PARAM_STR);//var_dump($comptabilise);
  347.                     $stmt->bindParam(':nom_deposant'$nom_deposantPDO::PARAM_STR);//var_dump($nom_deposant);
  348.                     $stmt->bindParam(':tel_deposant'$tel_deposantPDO::PARAM_STR);//var_dump($tel_deposant);
  349.                     $stmt->bindParam(':compte'$leComptePlanCPDO::PARAM_STR);//var_dump($leComptePlanC);
  350.                     $stmt->bindParam(':compte_client'$compte_clientPDO::PARAM_STR);//var_dump($compte_client);
  351.                     $stmt->bindParam(':cheque'$num_chequePDO::PARAM_STR);//var_dump($num_cheque);
  352.                     $stmt->bindParam(':idtypeoperation'$idTypeOpPDO::PARAM_STR);//var_dump($idTypeOp);
  353.                     $stmt->bindParam(':typeoperation'$idTypeOpPDO::PARAM_STR);//var_dump($idTypeOp);
  354.                     $stmt->bindParam(':ref_facture'$ref_facturePDO::PARAM_STR);//var_dump($ref_facture);
  355.                     $stmt->bindParam(':num_mvt'$numMvtPDO::PARAM_STR);//var_dump($numMvt);
  356.                     $stmt->bindParam(':lib_operation'$libPDO::PARAM_STR);//var_dump($lib);
  357.                     $stmt->bindParam(':type_traite_operation'$type_payePDO::PARAM_STR);//var_dump($lib);
  358.                     $stmt->bindParam(':produit_id'$idProduitPDO::PARAM_INT);//var_dump($lib);
  359.                     $stmt->bindParam(':compte_auxiliaire'$compte_auxiPDO::PARAM_INT);//var_dump($lib);
  360.                     $stmt->bindParam(':producteurId'$producteurIdPDO::PARAM_INT);//var_dump($lib);
  361.                     $stmt->bindParam(':fournisseurId'$fournisseurIdPDO::PARAM_INT);//var_dump($lib);
  362.                     
  363.                     
  364.                    // if($idVille!=0)
  365.                        // $stmt->bindParam(':ville_id', $idVille, PDO::PARAM_INT);//var_dump($lib);
  366.                     //else
  367.                         //$stmt->bindParam(':ville_id', 1, PDO::PARAM_INT);//var_dump($lib);
  368.                     
  369.                     $stmt->bindParam(':abonne_id'$idAbonnePDO::PARAM_INT);//var_dump($lib);
  370.                     $stmt->bindParam(':client_id'$clientPDO::PARAM_INT);//var_dump($lib);
  371.                     $stmt->bindParam(':activiteId'$activiteIdPDO::PARAM_INT);//var_dump($lib);
  372.                     $stmt->bindParam(':surfaceAnneeId'$surfaceAnneeIdPDO::PARAM_INT);
  373.                     
  374.                     
  375.                     
  376.                     if($infolivrer_id == 0){
  377.                         $infolivrer_id NULL;
  378.                     }
  379.                     
  380.                     $stmt->bindParam(':infolivrer_id',$infolivrer_idPDO::PARAM_INT);//var_dump($lib);
  381.                     
  382.                     //    var_dump($infolivrer_id);exit;
  383.                //  var_dump($caisse_id,$commande_id,$dateAutor,$piece_operation,$value['sens'],$datev,$leMontantPaye,$comptabilise,$nom_deposant,$tel_deposant,$leComptePlanC,$leComptePlanC,$compte_client,$num_cheque,$idTypeOp,$ref_facture,$numMvt,$lib,$type_paye,$compte_auxi);exit;
  384.                 //  var_dump($i);exit;
  385.                 
  386.                 }
  387.                  
  388.               
  389.                     
  390.                   $stmt->execute();
  391.                  // var_dump(1);exit;  
  392.                   //var_dump(1);exit;
  393.                 //  var_dump($compte_cheque);exit;
  394.                 /*} catch (\Exception $e) {
  395.                     $res = 1;
  396.                     var_dump($e->getMessage());
  397.                     exit;
  398.                 }*/
  399.                // var_dump($numMvt);exit;
  400.                 $i++;
  401.                 $j++;
  402.             }
  403.         }
  404.         //exit;
  405.         // retourner le numero de piece pour l'impression de l'ecriture
  406.         if ($res == 0)
  407.             $resulat 1;//$numpiece;
  408.         else
  409.             $resulat null;
  410.         return $resulat;
  411.     }
  412.     
  413.     /*
  414.      * Retourne un nom par defaut lors de la création d'un nouveau param
  415.      * @return type
  416.      */
  417.     public function geneLigneOperationComptableDynamique($commande_id 0$caisse_id 0$montant $nom_deposant 0,$tel_deposant=''$ref_facture,$num_cheque=0$compte_cheque=0$idTypeOp 0,$piece_operation =0,$compte_client='',$type_paye='',$idProduit='',$compte_auxi='',$datechoix='',$idVille=''$idAbonne='',$infolivrer_id=0$client=null) {
  418.         
  419.         // requete d'insertion de l'ecrirure comptable   dans table tmp 
  420.         //var_dump($idAbonne);exit;
  421.         
  422.         $res 0;
  423.         $comptabilise 0;                           
  424.         $sqltypeOp "";
  425.         $sqltypeOp .= " select t.idtypeoperation , t.libtypeoperation , s.sens, s.compte, t.codeoperation, p.libelle
  426.                                   from schemacomptable s inner join typeoperation t
  427.                                        on t.idtypeoperation = s.idtypeoperation
  428.                                     inner join plancomptable p
  429.                                        on s.compte = p.compte
  430.                                   where t.idtypeoperation = :idtypeop   
  431.                                   order by s.sens desc "//$montantddddd;
  432.                                   
  433.         $stmttypeop $this->em->getConnection()->prepare($sqltypeOp);
  434.         $stmttypeop->bindParam(':idtypeop'$idTypeOpPDO::PARAM_INT);
  435.         try {
  436.             $stmttypeop->execute();
  437.             $listetypeOp $stmttypeop->fetchAll(PDO::FETCH_ASSOC);
  438.         } catch (\Exception $e) {
  439.             var_dump($e->getMessage());
  440.             exit;
  441.         }
  442.         
  443.        
  444.         
  445.         if (is_array($listetypeOp) && count($listetypeOp) > 0) {
  446.              
  447.            
  448.             $sql " INSERT  INTO  operation
  449.                                         ( commande_id,caisse_id, date_operation, 
  450.                                         date_valeur, piece_operation, montant, 
  451.                                         comptabilise, nom_deposant,tel_deposant,
  452.                                         etat_operation,ref_facture, compte, cheque,
  453.                                         sensoperation,compte_client, idtypeoperation,num_mvt, lib_operation,
  454.                                         type_traite_operation, produit_id, compte_auxiliaire, ville_id, abonne_id, infolivrer_id, type_operation,client_id)
  455.                               values
  456.                                         (:commande_id,:caisse_id,:date_operation,
  457.                                         :date_valeur,:piece_operation,:montant,
  458.                                         :comptabilise,:nom_deposant,:tel_deposant,
  459.                                         1, :ref_facture,:compte,:cheque,
  460.                                         :sensoperation, :compte_client, :idtypeoperation, :num_mvt, :lib_operation
  461.                                         ,:type_traite_operation, :produit_id, :compte_auxiliaire, :ville_id, :abonne_id, :infolivrer_id, :typeoperation, :client_id) ";
  462.              //exit;
  463.             
  464.             $stmt $this->em->getConnection()->prepare($sql);
  465.             //if($idCaisse != 0)
  466.            // $datechoix = implode('/', array_reverse( explode('/',$datechoix) ) ) ;
  467.             
  468.             $dateAutor $datechoix
  469.            
  470.             //$dateAutor->setDate((int) substr($dateo, 0, 4), (int) substr($dateo, 5, 2), (int) substr($dateo, 8, 2));
  471.            // $dateAutor = $dateAutor->format('Y-m-d H:i:s');
  472.            
  473.            // $dateAutor->setDate((int) substr($dateo, 0, 4), (int) substr($dateo, 5, 2), (int) substr($dateo, 8, 2));
  474.            $an=substr($dateAutor04);
  475.            $m=substr($dateAutor52);
  476.            $datev $dateAutor;
  477.            $idUser=1;
  478.            $idCaisse=1;
  479.            $util $this->em->getRepository("adminUserBundle:Utilisateur")->find($idUser);
  480.            $cash $this->em->getRepository("adminStockBundle:Caisse")->find($idCaisse);
  481.             
  482.             $j=0;
  483.             foreach ($listetypeOp as $key => $value) {
  484.                // var_dump($dateAutor);exit; 
  485.                 $i 1;
  486.                
  487.                 $datevaleur $datev;
  488.                 $lib '' ;//$this->em->getRepository("adminStockBundle:TypeOperation")->find($idTypeOp);
  489.                 //$annule = $lib->getId();
  490.                 if($lib == ''){
  491.                     $lib ''.$nom_deposant;
  492.                 }else{
  493.                     $lib='-';
  494.                 }
  495.                 $cle "";
  496. //                        if (strtolower($value['codeoperation']) == 'ccc') $comptabilise = 2;                                               
  497.                 $datej 111;//$this->GetDatJulienne($this->em);
  498.                 $numMvt $this->getNumMvt($this->em1$an$m$entite 'LIVRER'$taille 5);
  499.          
  500.                 $leComptePlanC $value['compte'];//$compte_cheque[$j];
  501.                 $leMontantPaye =$montant[$j];
  502.                // try {
  503.                                         
  504.                 if ($i == 1) {
  505.                     
  506.                     $stmt->bindParam(':caisse_id'$caisse_idPDO::PARAM_STR); //var_dump($caisse_id);
  507.                    // if($commande_id != null )
  508.                     $stmt->bindParam(':commande_id'$commande_idPDO::PARAM_STR);//var_dump($commande_id);
  509.                     $stmt->bindParam(':date_operation'$dateAutorPDO::PARAM_STR);//var_dump($dateAutor);
  510.                     
  511.                     $stmt->bindParam(':piece_operation'$piece_operationPDO::PARAM_INT);//var_dump($piece_operation);
  512.                     $stmt->bindParam(':sensoperation'$value['sens'], PDO::PARAM_STR);//var_dump($value['sens']);
  513.                     $stmt->bindParam(':date_valeur'$datevPDO::PARAM_STR);//var_dump($datev);
  514.                     $stmt->bindParam(':montant'$leMontantPayePDO::PARAM_STR);//var_dump($leMontantPaye);
  515.                     $stmt->bindParam(':comptabilise'$comptabilisePDO::PARAM_STR);//var_dump($comptabilise);
  516.                     $stmt->bindParam(':nom_deposant'$nom_deposantPDO::PARAM_STR);//var_dump($nom_deposant);
  517.                     $stmt->bindParam(':tel_deposant'$tel_deposantPDO::PARAM_STR);//var_dump($tel_deposant);
  518.                     $stmt->bindParam(':compte'$leComptePlanCPDO::PARAM_STR);//var_dump($leComptePlanC);
  519.                     $stmt->bindParam(':compte_client'$compte_clientPDO::PARAM_STR);//var_dump($compte_client);
  520.                     $stmt->bindParam(':cheque'$num_chequePDO::PARAM_STR);//var_dump($num_cheque);
  521.                     $stmt->bindParam(':idtypeoperation'$idTypeOpPDO::PARAM_STR);//var_dump($idTypeOp);
  522.                     $stmt->bindParam(':typeoperation'$idTypeOpPDO::PARAM_STR);//var_dump($idTypeOp);
  523.                     $stmt->bindParam(':ref_facture'$ref_facturePDO::PARAM_STR);//var_dump($ref_facture);
  524.                     $stmt->bindParam(':num_mvt'$numMvtPDO::PARAM_STR);//var_dump($numMvt);
  525.                     $stmt->bindParam(':lib_operation'$libPDO::PARAM_STR);//var_dump($lib);
  526.                     $stmt->bindParam(':type_traite_operation'$type_payePDO::PARAM_STR);//var_dump($lib);
  527.                     $stmt->bindParam(':produit_id'$idProduitPDO::PARAM_INT);//var_dump($lib);
  528.                     $stmt->bindParam(':compte_auxiliaire'$compte_auxiPDO::PARAM_INT);//var_dump($lib);
  529.                     $stmt->bindParam(':ville_id'$idVillePDO::PARAM_INT);//var_dump($lib);
  530.                     $stmt->bindParam(':abonne_id'$idAbonnePDO::PARAM_INT);//var_dump($lib);
  531.                     $stmt->bindParam(':client_id'$clientPDO::PARAM_INT);//var_dump($lib);
  532.                     
  533.                     if($infolivrer_id == 0){
  534.                         $infolivrer_id NULL;
  535.                     }
  536.                     
  537.                     $stmt->bindParam(':infolivrer_id',$infolivrer_idPDO::PARAM_INT);//var_dump($lib);
  538.                     
  539.                     //    var_dump($infolivrer_id);exit;
  540.                //  var_dump($caisse_id,$commande_id,$dateAutor,$piece_operation,$value['sens'],$datev,$leMontantPaye,$comptabilise,$nom_deposant,$tel_deposant,$leComptePlanC,$leComptePlanC,$compte_client,$num_cheque,$idTypeOp,$ref_facture,$numMvt,$lib,$type_paye,$compte_auxi);exit;
  541.                 //  var_dump($i);exit;
  542.                 
  543.                 }
  544.                  
  545.               
  546.                     
  547.                   $stmt->execute();
  548.                  // var_dump(1);exit;  
  549.                   //var_dump(1);exit;
  550.                 //  var_dump($compte_cheque);exit;
  551.                 /*} catch (\Exception $e) {
  552.                     $res = 1;
  553.                     var_dump($e->getMessage());
  554.                     exit;
  555.                 }*/
  556.                // var_dump($numMvt);exit;
  557.                 $i++;
  558.                 $j++;
  559.             }
  560.         }
  561.         //exit;
  562.         // retourner le numero de piece pour l'impression de l'ecriture
  563.         if ($res == 0)
  564.             $resulat 1;//$numpiece;
  565.         else
  566.             $resulat null;
  567.         return $resulat;
  568.     }
  569.     
  570.     
  571.     
  572. public function soldeCaisseDate(\Doctrine\ORM\EntityManager $emc,$idCaisse,$datedeb$datefin$idprod=0,$idab=0,$compte='0'){                 
  573.     
  574.         // requete d'insertion de l'ecrirure comptable
  575.         $datedebarray $this->traiterDateFormat($datedeb);
  576.         
  577.         $datefinarray $this->traiterDateFormat($datefin);
  578.         //var_dump($datedeb, $datefin);exit;
  579.         $paramdeb implode("-"$datedebarray);
  580.         $paramfin implode("-"$datefinarray); 
  581.         $sql =  " select c.id, c.nom_caisse ,".
  582.                 "    sum(case ".
  583.                 "            when sensoperation = 'C' then montant ".
  584.                 "        end) as soldecredit, ".
  585.                 "    sum(case ".
  586.                 "            when sensoperation = 'D' then montant ".
  587.                 "        end) as soldedebit ".
  588.                 " from operation o inner join caisse c ".
  589.                 "    on c.id =o.caisse_id  ".
  590.                 "    ".
  591.                 " where 1=1 ";       
  592.         ( $idCaisse == )? $sql.= '' $sql.= ' and c.id =:idcaisse';
  593.         ( $compte == '0' )? $sql.= '' $sql.= ' and o.compte =:compte';
  594.         if($idab !=0){
  595.             $sql.= ' and o.id_abonne =:idab';
  596.         }else{
  597.             ( $idprod == )? $sql.= '' $sql.= ' and o.produit_id =:idprod';
  598.         }
  599.         
  600.         // ($date != null && $date != '')? $sql.=" AND  o.date_operation <= " . " '" . $date . "' " :  $sql.= '' ;
  601.         $datedeb != && $datedeb != "" ) ? $sql .= " AND  o.date_valeur >= " " '" $paramdeb "' " $sql .= '';
  602.         ( $datefin != && $datefin != "" ) ? $sql .= " AND  o.date_valeur <= " " '" $paramfin "' " $sql .= '';
  603.         
  604.         $sql .=' group by c.id ';
  605.         $liste null;
  606.         
  607.         //var_dump( $sql,$idprod );exit;
  608.         // on ne passe les ecritures que si l'entity manager et le numero de piece sont pas null
  609.         if ( $this->em != null ) {
  610.               // recuperation de la connection 
  611.               $stmt $this->em->getConnection()->prepare($sql);              
  612.               ( $idCaisse == )? $sql.= '' $stmt->bindValue(':idcaisse',$idCaissePDO::PARAM_INT); 
  613.               ( $compte == '0' )? $sql.= '' $stmt->bindValue(':compte',$comptePDO::PARAM_INT); 
  614.               if($idab !=0){
  615.                  $stmt->bindValue(':idab',$idabPDO::PARAM_INT); 
  616.                 }else{
  617.                    ( $idprod == )? $sql.= '' $stmt->bindValue(':idprod',$idprodPDO::PARAM_INT); 
  618.                 }             
  619.               try{
  620.                 $stmt->execute(); 
  621.                 $liste $stmt->fetchAll(PDO::FETCH_ASSOC);
  622.               }catch ( \Exception $e){
  623.                  //var_dump(substr($e->getMessage(),600,800));exit;  
  624.               }             
  625.         }  
  626.         
  627.         return $liste 
  628.     }
  629.     
  630.     
  631.     public function soldeCaisseProducteurDate(\Doctrine\ORM\EntityManager $emc,$idCaisse,$datedeb$datefin$idprod=0,$idab=0,$compte='0'$producteurId=0$fournisseurId=0,$sens=0$typeCompe=0$annee=0){                 
  632.     
  633.         // requete d'insertion de l'ecrirure comptable
  634.         $datedebarray $this->traiterDateFormat($datedeb);
  635.         
  636.         $datefinarray $this->traiterDateFormat($datefin);
  637.         //var_dump($datedeb, $datefin);exit;
  638.         $paramdeb implode("-"$datedebarray);
  639.         $paramfin implode("-"$datefinarray); 
  640.         $sql =  " select ".
  641.                 "    sum(case ".
  642.                 "            when sensoperation = 'C' then montant ".
  643.                 "        end) as soldecredit, ".
  644.                 "    sum(case ".
  645.                 "            when sensoperation = 'D' then montant ".
  646.                 "        end) as soldedebit ".
  647.                 " FROM operation  o
  648.                 
  649.                   INNER JOIN plancomptable cpte on cpte.compte = o.compte  ".
  650.                 "    
  651.                      INNER JOIN producteur p on p.id = o.producteur_id  ".
  652.                 "    ".
  653.                 " where 1=1 ";       
  654.         ( $idCaisse == )? $sql.= '' $sql.= ' and c.id =:idcaisse';
  655.         ( $compte == '0' )? $sql.= '' $sql.= ' and o.compte =:compte';
  656.         ( $producteurId == '0' )? $sql.= '' $sql.= ' and p.id =:producteurId';
  657.         ( $sens == )? $sql.= '' $sql.= ' and o.sensoperation =:sens';
  658.         ( $typeCompe == )? $sql.= '' $sql.= ' and cpte.liea =:typeCompe';
  659.         ( $annee == )? $sql.= '' $sql.= ' and YEAR(o.date_valeur) =:annee';
  660.         
  661.         if($idab !=0){
  662.             $sql.= ' and o.id_abonne =:idab';
  663.         }else{
  664.             ( $idprod == )? $sql.= '' $sql.= ' and o.produit_id =:idprod';
  665.         }
  666.         
  667.         // ($date != null && $date != '')? $sql.=" AND  o.date_operation <= " . " '" . $date . "' " :  $sql.= '' ;
  668.         $datedeb != && $datedeb != "" ) ? $sql .= " AND  o.date_valeur >= " " '" $paramdeb "' " $sql .= '';
  669.         ( $datefin != && $datefin != "" ) ? $sql .= " AND  o.date_valeur <= " " '" $paramfin "' " $sql .= '';
  670.         
  671.         //$sql .=' group by c.id ';
  672.         $liste null;
  673.         
  674.         //var_dump( $sql,$idprod );exit;
  675.         // on ne passe les ecritures que si l'entity manager et le numero de piece sont pas null
  676.         if ( $this->em != null ) {
  677.               // recuperation de la connection 
  678.               $stmt $this->em->getConnection()->prepare($sql);              
  679.               ( $idCaisse == )? $sql.= '' $stmt->bindValue(':idcaisse',$idCaissePDO::PARAM_INT); 
  680.               ( $compte == '0' )? $sql.= '' $stmt->bindValue(':compte',$comptePDO::PARAM_STR); 
  681.               ( $producteurId == '0' )? $sql.= '' $stmt->bindValue(':producteurId',$producteurIdPDO::PARAM_INT); 
  682.               ( $sens == '0' )? $sql.= '' $stmt->bindValue(':sens',$sensPDO::PARAM_STR); 
  683.               ( $typeCompe == '0' )? $sql.= '' $stmt->bindValue(':typeCompe',$typeCompePDO::PARAM_INT);
  684.               ( $annee == '0' )? $sql.= '' $stmt->bindValue(':annee',$anneePDO::PARAM_INT); 
  685.             
  686.             
  687.               if($idab !=0){
  688.                  $stmt->bindValue(':idab',$idabPDO::PARAM_INT); 
  689.                 }else{
  690.                    ( $idprod == )? $sql.= '' $stmt->bindValue(':idprod',$idprodPDO::PARAM_INT); 
  691.                 }             
  692.               try{
  693.                 
  694.                 $liste =  $stmt->executeQuery()->fetchAll(); //$stmt->execute();  $stmt->fetchAll(PDO::FETCH_ASSOC);
  695.               }catch ( \Exception $e){
  696.                  //var_dump(substr($e->getMessage(),600,800));exit;  
  697.               }             
  698.         }  
  699.         
  700.         return $liste 
  701.     }
  702.     public function soldeCaisseFournisseurDate(\Doctrine\ORM\EntityManager $emc,$idCaisse,$datedeb$datefin$idprod=0,$idab=0,$compte='0',  $fournisseurId=0){                 
  703.     
  704.         // requete d'insertion de l'ecrirure comptable
  705.         $datedebarray $this->traiterDateFormat($datedeb);
  706.         
  707.         $datefinarray $this->traiterDateFormat($datefin);
  708.         //var_dump($datedeb, $datefin);exit;
  709.         $paramdeb implode("-"$datedebarray);
  710.         $paramfin implode("-"$datefinarray); 
  711.         $sql =  " select c.id, c.nom_caisse ,".
  712.                 "    sum(case ".
  713.                 "            when sensoperation = 'C' then montant ".
  714.                 "        end) as soldecredit, ".
  715.                 "    sum(case ".
  716.                 "            when sensoperation = 'D' then montant ".
  717.                 "        end) as soldedebit ".
  718.                 " from operation o inner join caisse c ".
  719.                 "    on c.id =o.caisse_id 
  720.                      INNER JOIN fournisseur p on p.id = o.fournisseur_id  ".
  721.                 "    ".
  722.                 " where 1=1 ";       
  723.         ( $idCaisse == )? $sql.= '' $sql.= ' and c.id =:idcaisse';
  724.         ( $compte == '0' )? $sql.= '' $sql.= ' and o.compte =:compte';
  725.         ( $fournisseurId == '0' )? $sql.= '' $sql.= ' and p.id =:fournisseurId';
  726.         
  727.         if($idab !=0){
  728.             $sql.= ' and o.id_abonne =:idab';
  729.         }else{
  730.             ( $idprod == )? $sql.= '' $sql.= ' and o.produit_id =:idprod';
  731.         }
  732.         
  733.         // ($date != null && $date != '')? $sql.=" AND  o.date_operation <= " . " '" . $date . "' " :  $sql.= '' ;
  734.         $datedeb != && $datedeb != "" ) ? $sql .= " AND  o.date_valeur >= " " '" $paramdeb "' " $sql .= '';
  735.         ( $datefin != && $datefin != "" ) ? $sql .= " AND  o.date_valeur <= " " '" $paramfin "' " $sql .= '';
  736.         
  737.         $sql .=' group by c.id ';
  738.         $liste null;
  739.         
  740.         //var_dump( $sql,$idprod );exit;
  741.         // on ne passe les ecritures que si l'entity manager et le numero de piece sont pas null
  742.         if ( $this->em != null ) {
  743.               // recuperation de la connection 
  744.               $stmt $this->em->getConnection()->prepare($sql);              
  745.               ( $idCaisse == )? $sql.= '' $stmt->bindValue(':idcaisse',$idCaissePDO::PARAM_INT); 
  746.               ( $compte == '0' )? $sql.= '' $stmt->bindValue(':compte',$comptePDO::PARAM_INT); 
  747.               ( $fournisseurId == '0' )? $sql.= '' $stmt->bindValue(':fournisseurId',$fournisseurIdPDO::PARAM_INT); 
  748.             
  749.               if($idab !=0){
  750.                  $stmt->bindValue(':idab',$idabPDO::PARAM_INT); 
  751.                 }else{
  752.                    ( $idprod == )? $sql.= '' $stmt->bindValue(':idprod',$idprodPDO::PARAM_INT); 
  753.                 }             
  754.               try{
  755.                 
  756.                 $liste =  $stmt->executeQuery()->fetchAll(); //$stmt->execute();  $stmt->fetchAll(PDO::FETCH_ASSOC);
  757.               }catch ( \Exception $e){
  758.                  //var_dump(substr($e->getMessage(),600,800));exit;  
  759.               }             
  760.         }  
  761.         
  762.         return $liste 
  763.     }
  764.     
  765.     
  766. public function soldeCaisseParSercice(\Doctrine\ORM\EntityManager $emc,$idCaisse,$date,$idprod=0,$idab=0,$compte='0'){                 
  767.          $date implode('-'array_reverseexplode('-',$date) ) ) ;
  768.         // requete d'insertion de l'ecrirure comptable
  769.         $sql =  " select p.nom_produit ,".
  770.                 "    sum(case ".
  771.                 "            when sensoperation = 'C' then montant ".
  772.                 "        end) as soldecredit, ".
  773.                 "    sum(case ".
  774.                 "            when sensoperation = 'D' then montant ".
  775.                 "        end) as soldedebit ".
  776.                 " from operation o inner join caisse c ".
  777.                 "    on c.id =o.caisse_id inner join produit p on p.id =o.produit_id  ".
  778.                 "    ".
  779.                 " where  p.etat_produit !=6 and 1=1";       
  780.         ( $idCaisse == )? $sql.= '' $sql.= ' and c.id =:idcaisse';
  781.         ( $compte == '0' )? $sql.= '' $sql.= ' and o.compte =:compte';
  782.         if($idab !=0){
  783.         $sql.= ' and o.id_abonne =:idab';
  784.         }else{
  785.             ( $idprod == )? $sql.= '' $sql.= ' and o.produit_id =:idprod';
  786.         }
  787.         
  788.         ( $date != '')? $sql.=" AND  o.date_operation <= " " '" $date "' " :  $sql.= '' ;
  789.         
  790.         $sql .=' group by p.nom_produit';
  791.         $liste null;
  792.         
  793.         // on ne passe les ecritures que si l'entity manager et le numero de piece sont pas null
  794.         if ( $this->em != null ) {
  795.               // recuperation de la connection 
  796.               $stmt $this->em->getConnection()->prepare($sql);              
  797.               ( $idCaisse == )? $sql.= '' $stmt->bindValue(':idcaisse',$idCaissePDO::PARAM_INT); 
  798.               ( $compte == '0' )? $sql.= '' $stmt->bindValue(':compte',$comptePDO::PARAM_INT); 
  799.               if($idab !=0){
  800.                  $stmt->bindValue(':idab',$idabPDO::PARAM_INT); 
  801.                 }else{
  802.                    ( $idprod == )? $sql.= '' $stmt->bindValue(':idprod',$idprodPDO::PARAM_INT); 
  803.                 }             
  804.               try{
  805.                 $stmt->execute(); 
  806.                 $liste $stmt->fetchAll(PDO::FETCH_ASSOC);
  807.               }catch ( \Exception $e){
  808.                  //var_dump(substr($e->getMessage(),600,800));exit;  
  809.               }             
  810.         }  
  811.         
  812.         return $liste 
  813.     }    
  814.     
  815.     
  816.     
  817. public function soldeCaisseDesSercice(\Doctrine\ORM\EntityManager $emc,$idCaisse,$date,$idprod=0,$idab=0,$compte='0'){                 
  818.          $date implode('-'array_reverseexplode('-',$date) ) ) ;
  819.         // requete d'insertion de l'ecrirure comptable
  820.         $sql =  " select p.nom_produit ,".
  821.                 "    sum(case ".
  822.                 "            when sensoperation = 'C' then montant ".
  823.                 "        end) as soldecredit, ".
  824.                 "    sum(case ".
  825.                 "            when sensoperation = 'D' then montant ".
  826.                 "        end) as soldedebit ".
  827.                 " from operation o inner join caisse c ".
  828.                 "    on c.id =o.caisse_id inner join produit p on p.id =o.produit_id  ".
  829.                 "    ".
  830.                 " where  p.etat_produit !=6 and 1=1 ";       
  831.         ( $idCaisse == )? $sql.= '' $sql.= ' and c.id =:idcaisse';
  832.         ( $compte == '0' )? $sql.= '' $sql.= ' and o.compte =:compte';
  833.         if($idab !=0){
  834.         $sql.= ' and o.id_abonne =:idab';
  835.         }else{
  836.             ( $idprod == )? $sql.= '' $sql.= ' and o.produit_id =:idprod';
  837.         }
  838.         
  839.         ( $date != '')? $sql.=" AND  o.date_operation = " " '" $date "' " :  $sql.= '' ;
  840.         
  841.         $sql .=' group by p.nom_produit';
  842.         $liste null;
  843.         
  844.         // on ne passe les ecritures que si l'entity manager et le numero de piece sont pas null
  845.         if ( $this->em != null ) {
  846.               // recuperation de la connection 
  847.               $stmt $this->em->getConnection()->prepare($sql);              
  848.               ( $idCaisse == )? $sql.= '' $stmt->bindValue(':idcaisse',$idCaissePDO::PARAM_INT); 
  849.               ( $compte == '0' )? $sql.= '' $stmt->bindValue(':compte',$comptePDO::PARAM_INT); 
  850.               if($idab !=0){
  851.                  $stmt->bindValue(':idab',$idabPDO::PARAM_INT); 
  852.                 }else{
  853.                    ( $idprod == )? $sql.= '' $stmt->bindValue(':idprod',$idprodPDO::PARAM_INT); 
  854.                 }             
  855.               try{
  856.                 $stmt->execute(); 
  857.                 $liste $stmt->fetchAll(PDO::FETCH_ASSOC);
  858.               }catch ( \Exception $e){
  859.                  //var_dump(substr($e->getMessage(),600,800));exit;  
  860.               }             
  861.         }  
  862.         
  863.         return $liste 
  864.     }    
  865. public function soldeCaisseDesSerciceAutres(\Doctrine\ORM\EntityManager $emc,$idCaisse,$date,$idprod=0,$idab=0,$compte='0'){                 
  866.          $date implode('-'array_reverseexplode('-',$date) ) ) ;
  867.         // requete d'insertion de l'ecrirure comptable
  868.         $sql =  " select p.nom_produit , o.lib_operation as detail, ".
  869.                 "  o.montant, o.sensoperation ".
  870.                 " from operation o inner join caisse c ".
  871.                 "    on c.id =o.caisse_id inner join produit p on p.id =o.produit_id  ".
  872.                 "    ".
  873.                 " where  p.etat_produit =6 and 1=1 ";       
  874.         ( $idCaisse == )? $sql.= '' $sql.= ' and c.id =:idcaisse';
  875.         ( $compte == '0' )? $sql.= '' $sql.= ' and o.compte =:compte';
  876.         if($idab !=0){
  877.         $sql.= ' and o.id_abonne =:idab';
  878.         }else{
  879.             ( $idprod == )? $sql.= '' $sql.= ' and o.produit_id =:idprod';
  880.         }
  881.         
  882.         ( $date != '')? $sql.=" AND  o.date_operation = " " '" $date "' " :  $sql.= '' ;
  883.         
  884.         //$sql .=' group by p.nom_produit';
  885.       
  886.       
  887.         $liste null;
  888.         
  889.         // on ne passe les ecritures que si l'entity manager et le numero de piece sont pas null
  890.         if ( $this->em != null ) {
  891.               // recuperation de la connection 
  892.               $stmt $this->em->getConnection()->prepare($sql);              
  893.               ( $idCaisse == )? $sql.= '' $stmt->bindValue(':idcaisse',$idCaissePDO::PARAM_INT); 
  894.               ( $compte == '0' )? $sql.= '' $stmt->bindValue(':compte',$comptePDO::PARAM_INT); 
  895.               if($idab !=0){
  896.                  $stmt->bindValue(':idab',$idabPDO::PARAM_INT); 
  897.                 }else{
  898.                    ( $idprod == )? $sql.= '' $stmt->bindValue(':idprod',$idprodPDO::PARAM_INT); 
  899.                 }             
  900.               try{
  901.                 $stmt->execute(); 
  902.                 $liste $stmt->fetchAll(PDO::FETCH_ASSOC);
  903.               }catch ( \Exception $e){
  904.                  //var_dump(substr($e->getMessage(),600,800));exit;  
  905.               }             
  906.         }  
  907.         
  908.         return $liste 
  909.     }    
  910.     
  911.  public function somEntreeSortieDate(\Doctrine\ORM\EntityManager $emc,$idCaisse,$date){                 
  912.         $sql =  " select c.id, 
  913.                     sum(case 
  914.                             when operation = 'D' then montant
  915.                             when operation = 'C' then 0
  916.                         end) as sommedebit,
  917.                     sum(case 
  918.                             when operation = 'D' then 0
  919.                             when operation = 'C' then montant
  920.                         end) as sommecredit
  921.                   from operation o inner join caisse c
  922.                     on c.compte = o.compte
  923.                     ";       
  924.         ( $idCaisse == )? $sql.= '' $sql.= ' and c.idcaisse =:idcaisse';
  925.        // ( trim($date)=='' || $date != null)? $sql.= '' : $sql.=" AND  o.dateOperation = " . " '" . $date . "' ";
  926.         ($date != null && trim($date) != '')? $sql.=" AND  o.dateOperation = " " '" $date "' " :  $sql.= '' ;
  927.         $sql .= " ";
  928.         $sql .= " group by c.id";
  929.         
  930.         $liste null;
  931.         // on ne passe les ecritures que si l'entity manager et le numero de piece sont pas null
  932.         if ( $this->em != null ) {
  933.               // recuperation de la connection 
  934.               $stmt $this->em->getConnection()->prepare($sql);              
  935.               ( $idCaisse == )? $sql.= '' $stmt->bindValue(':idcaisse',$idCaissePDO::PARAM_INT);  
  936.              
  937.               try{
  938.                 $stmt->execute(); 
  939.                 $liste $stmt->fetchAll(PDO::FETCH_ASSOC);
  940.               }catch ( \Exception $e){
  941.                  //var_dump($e->getMessage());exit;  
  942.               }             
  943.         }  
  944.        // //var_dump($liste); exit ;
  945.         return $liste 
  946.     }
  947.     
  948.     
  949.     public function totalOperationParMois(\Doctrine\ORM\EntityManager $emc,$idCaisse$type,$compte){                 
  950.         
  951.         // requete d'insertion de l'ecrirure comptable
  952.          $sql =  " select c.id,c.compte,cpte.libelle as libellecompte, 
  953.                 YEAR(o.date_valeur) as lyear, MONTH(o.date_valeur) as lmonth,
  954.                 CAST(CONCAT_WS( '-', YEAR(o.date_valeur), MONTH(o.date_valeur),'01' ) AS DATE) as premierDate,
  955.                 sum(case when o.sensoperation = 'C' then o.montant end) as solde 
  956.                 FROM caisse c left join operation o on o.caisse_id = c.id 
  957.                 
  958.                 inner join plancomptable cpte on cpte.compte = c.compte  
  959.                 
  960.                 WHERE 1=1 and o.compte =:compte  ";       
  961.            // ( $idCaisse == 0 )? $sql.= '' : $sql.= " and c.id =:idcaisse";
  962.                
  963.                 $type == )? $sql.= '' $sql.= " and o.id_abonne =:type";
  964.                 
  965.         
  966.         $sql .=" GROUP BY lyear, lmonth
  967.                         ";
  968.         //var_dump($compte,$sql);exit;
  969.         // on ne passe les ecritures que si l'entity manager et le numero de piece sont pas null
  970.         if ( $this->em != null ) {        $liste null;
  971.               // recuperation de la connection 
  972.               $stmt $this->em->getConnection()->prepare($sql);              
  973.                     // ( $idCaisse == 0 )? $sql.= '' : $stmt->bindValue(':idcaisse',$idCaisse, PDO::PARAM_INT);   
  974.                     $type == )? $sql.= '' $stmt->bindValue(':type',$typePDO::PARAM_INT);   
  975.                     $stmt->bindValue(':compte',$comptePDO::PARAM_INT);   
  976.               try{
  977.                 $liste $stmt->executeQuery(); 
  978.                 //= $stmt->fetchAssociative(PDO::FETCH_ASSOC);
  979.               }catch ( \Exception $e){
  980.                  //var_dump(substr($e->getMessage(),600,800));exit;  
  981.               }             
  982.         }   
  983.             
  984.        // var_dump($liste);exit;
  985.         return $liste 
  986.     }        
  987.      /*
  988.      * Retourne un nom par defaut lors de la création d'un nouveau param
  989.      * @return type
  990.      */
  991.     public function getRecuperationCompte(\Doctrine\ORM\EntityManager $emc,$idTypeOp,$montantEsp$typeOperationRepository) {
  992.         
  993.         $lesComptes = array();
  994.         $lesMontants = array();
  995.         $tabCompteMontant =array();
  996.         $i 0;
  997.         $unTypeop $typeOperationRepository->find($idTypeOp);
  998.         foreach ($unTypeop->getSchemas() as $unGenreTypeOp) {
  999.              $lesComptes[$i] = $unGenreTypeOp->getPlancomptable()->getCompte();
  1000.              $lesMontants[$i] = $montantEsp;
  1001.              $i++;
  1002.          }
  1003.          $tabCompteMontant['compte'] = $lesComptes;
  1004.          $tabCompteMontant['montant'] = $lesMontants;
  1005.          return $tabCompteMontant ;
  1006.         
  1007.     } 
  1008.     
  1009.     
  1010.     /*
  1011.      * Retourne un nom par defaut lors de la création d'un nouveau param
  1012.      * @return type
  1013.      */
  1014.     public function getCompteVille(\Doctrine\ORM\EntityManager $emc,$idVille$villeRepository$caisseRepository) {
  1015.         $tabCompteId = array();
  1016.         $objetVille $villeRepository->find($idVille);
  1017.         $criteria = array('ville' => $objetVille);
  1018.         $objetCaisse $caisseRepository->findOneBy($criteria);
  1019.         $tabCompteId['compte'] = $objetCaisse->getPlanComptable()->getCompte();
  1020.         $tabCompteId['id'] = $objetCaisse->getId();
  1021.         return $tabCompteId ;
  1022.         
  1023.     } 
  1024.      /*
  1025.      * Retourne un nom par defaut lors de la création d'un nouveau param
  1026.      * @return type
  1027.      */
  1028.     public function getCompteCaisse(\Doctrine\ORM\EntityManager $emc,$idcaisse $caisseRepository) {
  1029.         $tabCompteId = array();
  1030.         $objetCaisse $caisseRepository->find($idcaisse);
  1031.         $tabCompteId['compte'] = $objetCaisse->getPlanComptable()->getCompte();
  1032.         $tabCompteId['id'] = $objetCaisse->getId();
  1033.         return $tabCompteId ;
  1034.         
  1035.     } 
  1036.     /*
  1037.      * Retourne un nom par defaut lors de la création d'un nouveau param
  1038.      * @return type
  1039.      */
  1040.     public function getTabLibelle(\Doctrine\ORM\EntityManager $emc,$idOper$compte,$libelleCaisse$libelleOperation$typeOperationRepository$schemaRepository ) {
  1041.         $tabLibelle = array();
  1042.         $objetTypOperation $typeOperationRepository->find($idOper);
  1043.         $objetSchemaComptable $schemaRepository->findBy(array("typeoperation"=>$objetTypOperation));
  1044.         
  1045.         foreach ($objetSchemaComptable as $uneSchemaComptable) {
  1046.             
  1047.             if($uneSchemaComptable->getSens() == 'D' ){
  1048.                 $tabLibelle[$uneSchemaComptable->getSens()] = $libelleCaisse;
  1049.             }else{
  1050.                 $tabLibelle[$uneSchemaComptable->getSens()] = $libelleOperation;
  1051.             }
  1052.         }
  1053.         
  1054.         return $tabLibelle ;
  1055.         
  1056.     } 
  1057.     
  1058.     
  1059.     
  1060.     public function getName() {
  1061.         return 'OperationManager';
  1062.     }    
  1063.    
  1064. }