src/Services/stock/OperationManager.php line 79

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.      * Retourne un nom par defaut lors de la création d'un nouveau param
  414.      * @return type
  415.      */
  416.      public function geneLigneOperationComptableDevise($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$infoclient=0,$infoaction=0$devise=0$utilisateurRepository,$caisseRepository$producteurId=null,$fournisseurId=null$activiteId=null$surfaceAnneeId=null) {
  417.         
  418.         // requete d'insertion de l'ecrirure comptable   dans table tmp 
  419.         //var_dump($idAbonne);exit;
  420.         
  421.         $res 0;
  422.         $comptabilise 0;                           
  423.         $sqltypeOp "";
  424.         $sqltypeOp .= " select t.idtypeoperation , t.libtypeoperation , s.sens, s.compte, t.codeoperation, p.libelle
  425.                                   from schemacomptable s inner join typeoperation t
  426.                                        on t.idtypeoperation = s.idtypeoperation
  427.                                     inner join plancomptable p
  428.                                        on s.compte = p.compte
  429.                                   where t.idtypeoperation = :idtypeop   
  430.                                   order by s.sens desc "//$montantddddd;
  431.                                   
  432.         $stmttypeop $this->em->getConnection()->prepare($sqltypeOp);
  433.         $stmttypeop->bindParam(':idtypeop'$idTypeOpPDO::PARAM_INT);
  434.         try {
  435.             //$stmttypeop->execute();
  436.             //$listetypeOp = $stmttypeop->fetchAll(PDO::FETCH_ASSOC);
  437.             $listetypeOp $stmttypeop->executeQuery()->fetchAll();
  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,  abonne_id, infolivrer_id, type_operation,client_id,producteur_id, fournisseur_id, activite_id, surfaceannee_id, info_client, info_action, devise_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,  :abonne_id, :infolivrer_id, :typeoperation, :client_id, :producteurId, :fournisseurId, :activiteId, :surfaceAnneeId, :infoclient, :infoaction, :devise) "//:ville_id, //ville_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 $utilisateurRepository->find($idUser);
  480.            $cash $caisseRepository->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(':producteurId'$producteurIdPDO::PARAM_INT);//var_dump($lib);
  530.                     $stmt->bindParam(':fournisseurId'$fournisseurIdPDO::PARAM_INT);//var_dump($lib);
  531.                    // if($idVille!=0)
  532.                        // $stmt->bindParam(':ville_id', $idVille, PDO::PARAM_INT);//var_dump($lib);
  533.                     //else
  534.                         //$stmt->bindParam(':ville_id', 1, PDO::PARAM_INT);//var_dump($lib);
  535.                     
  536.                     $stmt->bindParam(':abonne_id'$idAbonnePDO::PARAM_INT);//var_dump($lib);
  537.                     $stmt->bindParam(':client_id'$clientPDO::PARAM_INT);//var_dump($lib);
  538.                     $stmt->bindParam(':activiteId'$activiteIdPDO::PARAM_INT);//var_dump($lib);
  539.                     $stmt->bindParam(':surfaceAnneeId'$surfaceAnneeIdPDO::PARAM_INT);
  540.                     $stmt->bindParam(':infoclient'$infoclientPDO::PARAM_INT);//var_dump($lib);
  541.                     $stmt->bindParam(':infoaction'$infoactionPDO::PARAM_INT);//var_dump($lib);
  542.                     $stmt->bindParam(':devise'$devisePDO::PARAM_INT);
  543.                     
  544.                     if($infolivrer_id == 0){
  545.                         $infolivrer_id NULL;
  546.                     }
  547.                     
  548.                     $stmt->bindParam(':infolivrer_id',$infolivrer_idPDO::PARAM_INT);//var_dump($lib);
  549.                     
  550.                     //    var_dump($infolivrer_id);exit;
  551.                //  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;
  552.                 //  var_dump($i);exit;
  553.                 
  554.                 }
  555.                  
  556.               
  557.                     
  558.                   $stmt->execute();
  559.                  // var_dump(1);exit;  
  560.                   //var_dump(1);exit;
  561.                 //  var_dump($compte_cheque);exit;
  562.                 /*} catch (\Exception $e) {
  563.                     $res = 1;
  564.                     var_dump($e->getMessage());
  565.                     exit;
  566.                 }*/
  567.                // var_dump($numMvt);exit;
  568.                 $i++;
  569.                 $j++;
  570.             }
  571.         }
  572.         //exit;
  573.         // retourner le numero de piece pour l'impression de l'ecriture
  574.         if ($res == 0)
  575.             $resulat 1;//$numpiece;
  576.         else
  577.             $resulat null;
  578.         return $resulat;
  579.     }
  580.     
  581.     /*
  582.      * Retourne un nom par defaut lors de la création d'un nouveau param
  583.      * @return type
  584.      */
  585.     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) {
  586.         
  587.         // requete d'insertion de l'ecrirure comptable   dans table tmp 
  588.         //var_dump($idAbonne);exit;
  589.         
  590.         $res 0;
  591.         $comptabilise 0;                           
  592.         $sqltypeOp "";
  593.         $sqltypeOp .= " select t.idtypeoperation , t.libtypeoperation , s.sens, s.compte, t.codeoperation, p.libelle
  594.                                   from schemacomptable s inner join typeoperation t
  595.                                        on t.idtypeoperation = s.idtypeoperation
  596.                                     inner join plancomptable p
  597.                                        on s.compte = p.compte
  598.                                   where t.idtypeoperation = :idtypeop   
  599.                                   order by s.sens desc "//$montantddddd;
  600.                                   
  601.         $stmttypeop $this->em->getConnection()->prepare($sqltypeOp);
  602.         $stmttypeop->bindParam(':idtypeop'$idTypeOpPDO::PARAM_INT);
  603.         try {
  604.             $stmttypeop->execute();
  605.             $listetypeOp $stmttypeop->fetchAll(PDO::FETCH_ASSOC);
  606.         } catch (\Exception $e) {
  607.             var_dump($e->getMessage());
  608.             exit;
  609.         }
  610.         
  611.        
  612.         
  613.         if (is_array($listetypeOp) && count($listetypeOp) > 0) {
  614.              
  615.            
  616.             $sql " INSERT  INTO  operation
  617.                                         ( commande_id,caisse_id, date_operation, 
  618.                                         date_valeur, piece_operation, montant, 
  619.                                         comptabilise, nom_deposant,tel_deposant,
  620.                                         etat_operation,ref_facture, compte, cheque,
  621.                                         sensoperation,compte_client, idtypeoperation,num_mvt, lib_operation,
  622.                                         type_traite_operation, produit_id, compte_auxiliaire, ville_id, abonne_id, infolivrer_id, type_operation,client_id)
  623.                               values
  624.                                         (:commande_id,:caisse_id,:date_operation,
  625.                                         :date_valeur,:piece_operation,:montant,
  626.                                         :comptabilise,:nom_deposant,:tel_deposant,
  627.                                         1, :ref_facture,:compte,:cheque,
  628.                                         :sensoperation, :compte_client, :idtypeoperation, :num_mvt, :lib_operation
  629.                                         ,:type_traite_operation, :produit_id, :compte_auxiliaire, :ville_id, :abonne_id, :infolivrer_id, :typeoperation, :client_id) ";
  630.              //exit;
  631.             
  632.             $stmt $this->em->getConnection()->prepare($sql);
  633.             //if($idCaisse != 0)
  634.            // $datechoix = implode('/', array_reverse( explode('/',$datechoix) ) ) ;
  635.             
  636.             $dateAutor $datechoix
  637.            
  638.             //$dateAutor->setDate((int) substr($dateo, 0, 4), (int) substr($dateo, 5, 2), (int) substr($dateo, 8, 2));
  639.            // $dateAutor = $dateAutor->format('Y-m-d H:i:s');
  640.            
  641.            // $dateAutor->setDate((int) substr($dateo, 0, 4), (int) substr($dateo, 5, 2), (int) substr($dateo, 8, 2));
  642.            $an=substr($dateAutor04);
  643.            $m=substr($dateAutor52);
  644.            $datev $dateAutor;
  645.            $idUser=1;
  646.            $idCaisse=1;
  647.            $util $this->em->getRepository("adminUserBundle:Utilisateur")->find($idUser);
  648.            $cash $this->em->getRepository("adminStockBundle:Caisse")->find($idCaisse);
  649.             
  650.             $j=0;
  651.             foreach ($listetypeOp as $key => $value) {
  652.                // var_dump($dateAutor);exit; 
  653.                 $i 1;
  654.                
  655.                 $datevaleur $datev;
  656.                 $lib '' ;//$this->em->getRepository("adminStockBundle:TypeOperation")->find($idTypeOp);
  657.                 //$annule = $lib->getId();
  658.                 if($lib == ''){
  659.                     $lib ''.$nom_deposant;
  660.                 }else{
  661.                     $lib='-';
  662.                 }
  663.                 $cle "";
  664. //                        if (strtolower($value['codeoperation']) == 'ccc') $comptabilise = 2;                                               
  665.                 $datej 111;//$this->GetDatJulienne($this->em);
  666.                 $numMvt $this->getNumMvt($this->em1$an$m$entite 'LIVRER'$taille 5);
  667.          
  668.                 $leComptePlanC $value['compte'];//$compte_cheque[$j];
  669.                 $leMontantPaye =$montant[$j];
  670.                // try {
  671.                                         
  672.                 if ($i == 1) {
  673.                     
  674.                     $stmt->bindParam(':caisse_id'$caisse_idPDO::PARAM_STR); //var_dump($caisse_id);
  675.                    // if($commande_id != null )
  676.                     $stmt->bindParam(':commande_id'$commande_idPDO::PARAM_STR);//var_dump($commande_id);
  677.                     $stmt->bindParam(':date_operation'$dateAutorPDO::PARAM_STR);//var_dump($dateAutor);
  678.                     
  679.                     $stmt->bindParam(':piece_operation'$piece_operationPDO::PARAM_INT);//var_dump($piece_operation);
  680.                     $stmt->bindParam(':sensoperation'$value['sens'], PDO::PARAM_STR);//var_dump($value['sens']);
  681.                     $stmt->bindParam(':date_valeur'$datevPDO::PARAM_STR);//var_dump($datev);
  682.                     $stmt->bindParam(':montant'$leMontantPayePDO::PARAM_STR);//var_dump($leMontantPaye);
  683.                     $stmt->bindParam(':comptabilise'$comptabilisePDO::PARAM_STR);//var_dump($comptabilise);
  684.                     $stmt->bindParam(':nom_deposant'$nom_deposantPDO::PARAM_STR);//var_dump($nom_deposant);
  685.                     $stmt->bindParam(':tel_deposant'$tel_deposantPDO::PARAM_STR);//var_dump($tel_deposant);
  686.                     $stmt->bindParam(':compte'$leComptePlanCPDO::PARAM_STR);//var_dump($leComptePlanC);
  687.                     $stmt->bindParam(':compte_client'$compte_clientPDO::PARAM_STR);//var_dump($compte_client);
  688.                     $stmt->bindParam(':cheque'$num_chequePDO::PARAM_STR);//var_dump($num_cheque);
  689.                     $stmt->bindParam(':idtypeoperation'$idTypeOpPDO::PARAM_STR);//var_dump($idTypeOp);
  690.                     $stmt->bindParam(':typeoperation'$idTypeOpPDO::PARAM_STR);//var_dump($idTypeOp);
  691.                     $stmt->bindParam(':ref_facture'$ref_facturePDO::PARAM_STR);//var_dump($ref_facture);
  692.                     $stmt->bindParam(':num_mvt'$numMvtPDO::PARAM_STR);//var_dump($numMvt);
  693.                     $stmt->bindParam(':lib_operation'$libPDO::PARAM_STR);//var_dump($lib);
  694.                     $stmt->bindParam(':type_traite_operation'$type_payePDO::PARAM_STR);//var_dump($lib);
  695.                     $stmt->bindParam(':produit_id'$idProduitPDO::PARAM_INT);//var_dump($lib);
  696.                     $stmt->bindParam(':compte_auxiliaire'$compte_auxiPDO::PARAM_INT);//var_dump($lib);
  697.                     $stmt->bindParam(':ville_id'$idVillePDO::PARAM_INT);//var_dump($lib);
  698.                     $stmt->bindParam(':abonne_id'$idAbonnePDO::PARAM_INT);//var_dump($lib);
  699.                     $stmt->bindParam(':client_id'$clientPDO::PARAM_INT);//var_dump($lib);
  700.                     
  701.                     if($infolivrer_id == 0){
  702.                         $infolivrer_id NULL;
  703.                     }
  704.                     
  705.                     $stmt->bindParam(':infolivrer_id',$infolivrer_idPDO::PARAM_INT);//var_dump($lib);
  706.                     
  707.                     //    var_dump($infolivrer_id);exit;
  708.                //  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;
  709.                 //  var_dump($i);exit;
  710.                 
  711.                 }
  712.                  
  713.               
  714.                     
  715.                   $stmt->execute();
  716.                  // var_dump(1);exit;  
  717.                   //var_dump(1);exit;
  718.                 //  var_dump($compte_cheque);exit;
  719.                 /*} catch (\Exception $e) {
  720.                     $res = 1;
  721.                     var_dump($e->getMessage());
  722.                     exit;
  723.                 }*/
  724.                // var_dump($numMvt);exit;
  725.                 $i++;
  726.                 $j++;
  727.             }
  728.         }
  729.         //exit;
  730.         // retourner le numero de piece pour l'impression de l'ecriture
  731.         if ($res == 0)
  732.             $resulat 1;//$numpiece;
  733.         else
  734.             $resulat null;
  735.         return $resulat;
  736.     }
  737.     
  738.     
  739.     
  740. public function soldeCaisseDate(\Doctrine\ORM\EntityManager $emc,$idCaisse,$datedeb$datefin$idprod=0,$idab=0,$compte='0'){                 
  741.     
  742.         // requete d'insertion de l'ecrirure comptable
  743.         $datedebarray $this->traiterDateFormat($datedeb);
  744.         
  745.         $datefinarray $this->traiterDateFormat($datefin);
  746.         //var_dump($datedeb, $datefin);exit;
  747.         $paramdeb implode("-"$datedebarray);
  748.         $paramfin implode("-"$datefinarray); 
  749.         $sql =  " select c.id, c.nom_caisse ,".
  750.                 "    sum(case ".
  751.                 "            when sensoperation = 'C' then montant ".
  752.                 "        end) as soldecredit, ".
  753.                 "    sum(case ".
  754.                 "            when sensoperation = 'D' then montant ".
  755.                 "        end) as soldedebit ".
  756.                 " from operation o inner join caisse c ".
  757.                 "    on c.id =o.caisse_id  ".
  758.                 "    ".
  759.                 " where 1=1 ";       
  760.         ( $idCaisse == )? $sql.= '' $sql.= ' and c.id =:idcaisse';
  761.         ( $compte == '0' )? $sql.= '' $sql.= ' and o.compte =:compte';
  762.         if($idab !=0){
  763.             $sql.= ' and o.id_abonne =:idab';
  764.         }else{
  765.             ( $idprod == )? $sql.= '' $sql.= ' and o.produit_id =:idprod';
  766.         }
  767.         
  768.         // ($date != null && $date != '')? $sql.=" AND  o.date_operation <= " . " '" . $date . "' " :  $sql.= '' ;
  769.         $datedeb != && $datedeb != "" ) ? $sql .= " AND  o.date_valeur >= " " '" $paramdeb "' " $sql .= '';
  770.         ( $datefin != && $datefin != "" ) ? $sql .= " AND  o.date_valeur <= " " '" $paramfin "' " $sql .= '';
  771.         
  772.         $sql .=' group by c.id ';
  773.         $liste null;
  774.         
  775.         //var_dump( $sql,$idprod );exit;
  776.         // on ne passe les ecritures que si l'entity manager et le numero de piece sont pas null
  777.         if ( $this->em != null ) {
  778.               // recuperation de la connection 
  779.               $stmt $this->em->getConnection()->prepare($sql);              
  780.               ( $idCaisse == )? $sql.= '' $stmt->bindValue(':idcaisse',$idCaissePDO::PARAM_INT); 
  781.               ( $compte == '0' )? $sql.= '' $stmt->bindValue(':compte',$comptePDO::PARAM_INT); 
  782.               if($idab !=0){
  783.                  $stmt->bindValue(':idab',$idabPDO::PARAM_INT); 
  784.                 }else{
  785.                    ( $idprod == )? $sql.= '' $stmt->bindValue(':idprod',$idprodPDO::PARAM_INT); 
  786.                 }             
  787.               try{
  788.                 $stmt->execute(); 
  789.                 $liste $stmt->fetchAll(PDO::FETCH_ASSOC);
  790.               }catch ( \Exception $e){
  791.                  //var_dump(substr($e->getMessage(),600,800));exit;  
  792.               }             
  793.         }  
  794.         
  795.         return $liste 
  796.     }
  797.     
  798.     
  799.     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){                 
  800.     
  801.         // requete d'insertion de l'ecrirure comptable
  802.         $datedebarray $this->traiterDateFormat($datedeb);
  803.         
  804.         $datefinarray $this->traiterDateFormat($datefin);
  805.         //var_dump($datedeb, $datefin);exit;
  806.         $paramdeb implode("-"$datedebarray);
  807.         $paramfin implode("-"$datefinarray); 
  808.         $sql =  " select ".
  809.                 "    sum(case ".
  810.                 "            when sensoperation = 'C' then montant ".
  811.                 "        end) as soldecredit, ".
  812.                 "    sum(case ".
  813.                 "            when sensoperation = 'D' then montant ".
  814.                 "        end) as soldedebit ".
  815.                 " FROM operation  o
  816.                 
  817.                   INNER JOIN plancomptable cpte on cpte.compte = o.compte  ".
  818.                 "    
  819.                      INNER JOIN producteur p on p.id = o.producteur_id  ".
  820.                 "    ".
  821.                 " where 1=1 ";       
  822.         ( $idCaisse == )? $sql.= '' $sql.= ' and c.id =:idcaisse';
  823.         ( $compte == '0' )? $sql.= '' $sql.= ' and o.compte =:compte';
  824.         ( $producteurId == '0' )? $sql.= '' $sql.= ' and p.id =:producteurId';
  825.         ( $sens == )? $sql.= '' $sql.= ' and o.sensoperation =:sens';
  826.         ( $typeCompe == )? $sql.= '' $sql.= ' and cpte.liea =:typeCompe';
  827.         ( $annee == )? $sql.= '' $sql.= ' and YEAR(o.date_valeur) =:annee';
  828.         
  829.         if($idab !=0){
  830.             $sql.= ' and o.id_abonne =:idab';
  831.         }else{
  832.             ( $idprod == )? $sql.= '' $sql.= ' and o.produit_id =:idprod';
  833.         }
  834.         
  835.         // ($date != null && $date != '')? $sql.=" AND  o.date_operation <= " . " '" . $date . "' " :  $sql.= '' ;
  836.         $datedeb != && $datedeb != "" ) ? $sql .= " AND  o.date_valeur >= " " '" $paramdeb "' " $sql .= '';
  837.         ( $datefin != && $datefin != "" ) ? $sql .= " AND  o.date_valeur <= " " '" $paramfin "' " $sql .= '';
  838.         
  839.         //$sql .=' group by c.id ';
  840.         $liste null;
  841.         
  842.         //var_dump( $sql,$idprod );exit;
  843.         // on ne passe les ecritures que si l'entity manager et le numero de piece sont pas null
  844.         if ( $this->em != null ) {
  845.               // recuperation de la connection 
  846.               $stmt $this->em->getConnection()->prepare($sql);              
  847.               ( $idCaisse == )? $sql.= '' $stmt->bindValue(':idcaisse',$idCaissePDO::PARAM_INT); 
  848.               ( $compte == '0' )? $sql.= '' $stmt->bindValue(':compte',$comptePDO::PARAM_STR); 
  849.               ( $producteurId == '0' )? $sql.= '' $stmt->bindValue(':producteurId',$producteurIdPDO::PARAM_INT); 
  850.               ( $sens == '0' )? $sql.= '' $stmt->bindValue(':sens',$sensPDO::PARAM_STR); 
  851.               ( $typeCompe == '0' )? $sql.= '' $stmt->bindValue(':typeCompe',$typeCompePDO::PARAM_INT);
  852.               ( $annee == '0' )? $sql.= '' $stmt->bindValue(':annee',$anneePDO::PARAM_INT); 
  853.             
  854.             
  855.               if($idab !=0){
  856.                  $stmt->bindValue(':idab',$idabPDO::PARAM_INT); 
  857.                 }else{
  858.                    ( $idprod == )? $sql.= '' $stmt->bindValue(':idprod',$idprodPDO::PARAM_INT); 
  859.                 }             
  860.               try{
  861.                 
  862.                 $liste =  $stmt->executeQuery()->fetchAll(); //$stmt->execute();  $stmt->fetchAll(PDO::FETCH_ASSOC);
  863.               }catch ( \Exception $e){
  864.                  //var_dump(substr($e->getMessage(),600,800));exit;  
  865.               }             
  866.         }  
  867.         
  868.         return $liste 
  869.     }
  870.     public function soldeCaisseFournisseurDate(\Doctrine\ORM\EntityManager $emc,$idCaisse,$datedeb$datefin$idprod=0,$idab=0,$compte='0',  $fournisseurId=0){                 
  871.     
  872.         // requete d'insertion de l'ecrirure comptable
  873.         $datedebarray $this->traiterDateFormat($datedeb);
  874.         
  875.         $datefinarray $this->traiterDateFormat($datefin);
  876.         //var_dump($datedeb, $datefin);exit;
  877.         $paramdeb implode("-"$datedebarray);
  878.         $paramfin implode("-"$datefinarray); 
  879.         $sql =  " select c.id, c.nom_caisse ,".
  880.                 "    sum(case ".
  881.                 "            when sensoperation = 'C' then montant ".
  882.                 "        end) as soldecredit, ".
  883.                 "    sum(case ".
  884.                 "            when sensoperation = 'D' then montant ".
  885.                 "        end) as soldedebit ".
  886.                 " from operation o inner join caisse c ".
  887.                 "    on c.id =o.caisse_id 
  888.                      INNER JOIN fournisseur p on p.id = o.fournisseur_id  ".
  889.                 "    ".
  890.                 " where 1=1 ";       
  891.         ( $idCaisse == )? $sql.= '' $sql.= ' and c.id =:idcaisse';
  892.         ( $compte == '0' )? $sql.= '' $sql.= ' and o.compte =:compte';
  893.         ( $fournisseurId == '0' )? $sql.= '' $sql.= ' and p.id =:fournisseurId';
  894.         
  895.         if($idab !=0){
  896.             $sql.= ' and o.id_abonne =:idab';
  897.         }else{
  898.             ( $idprod == )? $sql.= '' $sql.= ' and o.produit_id =:idprod';
  899.         }
  900.         
  901.         // ($date != null && $date != '')? $sql.=" AND  o.date_operation <= " . " '" . $date . "' " :  $sql.= '' ;
  902.         $datedeb != && $datedeb != "" ) ? $sql .= " AND  o.date_valeur >= " " '" $paramdeb "' " $sql .= '';
  903.         ( $datefin != && $datefin != "" ) ? $sql .= " AND  o.date_valeur <= " " '" $paramfin "' " $sql .= '';
  904.         
  905.         $sql .=' group by c.id ';
  906.         $liste null;
  907.         
  908.         //var_dump( $sql,$idprod );exit;
  909.         // on ne passe les ecritures que si l'entity manager et le numero de piece sont pas null
  910.         if ( $this->em != null ) {
  911.               // recuperation de la connection 
  912.               $stmt $this->em->getConnection()->prepare($sql);              
  913.               ( $idCaisse == )? $sql.= '' $stmt->bindValue(':idcaisse',$idCaissePDO::PARAM_INT); 
  914.               ( $compte == '0' )? $sql.= '' $stmt->bindValue(':compte',$comptePDO::PARAM_INT); 
  915.               ( $fournisseurId == '0' )? $sql.= '' $stmt->bindValue(':fournisseurId',$fournisseurIdPDO::PARAM_INT); 
  916.             
  917.               if($idab !=0){
  918.                  $stmt->bindValue(':idab',$idabPDO::PARAM_INT); 
  919.                 }else{
  920.                    ( $idprod == )? $sql.= '' $stmt->bindValue(':idprod',$idprodPDO::PARAM_INT); 
  921.                 }             
  922.               try{
  923.                 
  924.                 $liste =  $stmt->executeQuery()->fetchAll(); //$stmt->execute();  $stmt->fetchAll(PDO::FETCH_ASSOC);
  925.               }catch ( \Exception $e){
  926.                  //var_dump(substr($e->getMessage(),600,800));exit;  
  927.               }             
  928.         }  
  929.         
  930.         return $liste 
  931.     }
  932.     
  933.     
  934. public function soldeCaisseParSercice(\Doctrine\ORM\EntityManager $emc,$idCaisse,$date,$idprod=0,$idab=0,$compte='0'){                 
  935.          $date implode('-'array_reverseexplode('-',$date) ) ) ;
  936.         // requete d'insertion de l'ecrirure comptable
  937.         $sql =  " select p.nom_produit ,".
  938.                 "    sum(case ".
  939.                 "            when sensoperation = 'C' then montant ".
  940.                 "        end) as soldecredit, ".
  941.                 "    sum(case ".
  942.                 "            when sensoperation = 'D' then montant ".
  943.                 "        end) as soldedebit ".
  944.                 " from operation o inner join caisse c ".
  945.                 "    on c.id =o.caisse_id inner join produit p on p.id =o.produit_id  ".
  946.                 "    ".
  947.                 " where  p.etat_produit !=6 and 1=1";       
  948.         ( $idCaisse == )? $sql.= '' $sql.= ' and c.id =:idcaisse';
  949.         ( $compte == '0' )? $sql.= '' $sql.= ' and o.compte =:compte';
  950.         if($idab !=0){
  951.         $sql.= ' and o.id_abonne =:idab';
  952.         }else{
  953.             ( $idprod == )? $sql.= '' $sql.= ' and o.produit_id =:idprod';
  954.         }
  955.         
  956.         ( $date != '')? $sql.=" AND  o.date_operation <= " " '" $date "' " :  $sql.= '' ;
  957.         
  958.         $sql .=' group by p.nom_produit';
  959.         $liste null;
  960.         
  961.         // on ne passe les ecritures que si l'entity manager et le numero de piece sont pas null
  962.         if ( $this->em != null ) {
  963.               // recuperation de la connection 
  964.               $stmt $this->em->getConnection()->prepare($sql);              
  965.               ( $idCaisse == )? $sql.= '' $stmt->bindValue(':idcaisse',$idCaissePDO::PARAM_INT); 
  966.               ( $compte == '0' )? $sql.= '' $stmt->bindValue(':compte',$comptePDO::PARAM_INT); 
  967.               if($idab !=0){
  968.                  $stmt->bindValue(':idab',$idabPDO::PARAM_INT); 
  969.                 }else{
  970.                    ( $idprod == )? $sql.= '' $stmt->bindValue(':idprod',$idprodPDO::PARAM_INT); 
  971.                 }             
  972.               try{
  973.                 $stmt->execute(); 
  974.                 $liste $stmt->fetchAll(PDO::FETCH_ASSOC);
  975.               }catch ( \Exception $e){
  976.                  //var_dump(substr($e->getMessage(),600,800));exit;  
  977.               }             
  978.         }  
  979.         
  980.         return $liste 
  981.     }    
  982.     
  983.     
  984.     
  985. public function soldeCaisseDesSercice(\Doctrine\ORM\EntityManager $emc,$idCaisse,$date,$idprod=0,$idab=0,$compte='0'){                 
  986.          $date implode('-'array_reverseexplode('-',$date) ) ) ;
  987.         // requete d'insertion de l'ecrirure comptable
  988.         $sql =  " select p.nom_produit ,".
  989.                 "    sum(case ".
  990.                 "            when sensoperation = 'C' then montant ".
  991.                 "        end) as soldecredit, ".
  992.                 "    sum(case ".
  993.                 "            when sensoperation = 'D' then montant ".
  994.                 "        end) as soldedebit ".
  995.                 " from operation o inner join caisse c ".
  996.                 "    on c.id =o.caisse_id inner join produit p on p.id =o.produit_id  ".
  997.                 "    ".
  998.                 " where  p.etat_produit !=6 and 1=1 ";       
  999.         ( $idCaisse == )? $sql.= '' $sql.= ' and c.id =:idcaisse';
  1000.         ( $compte == '0' )? $sql.= '' $sql.= ' and o.compte =:compte';
  1001.         if($idab !=0){
  1002.         $sql.= ' and o.id_abonne =:idab';
  1003.         }else{
  1004.             ( $idprod == )? $sql.= '' $sql.= ' and o.produit_id =:idprod';
  1005.         }
  1006.         
  1007.         ( $date != '')? $sql.=" AND  o.date_operation = " " '" $date "' " :  $sql.= '' ;
  1008.         
  1009.         $sql .=' group by p.nom_produit';
  1010.         $liste null;
  1011.         
  1012.         // on ne passe les ecritures que si l'entity manager et le numero de piece sont pas null
  1013.         if ( $this->em != null ) {
  1014.               // recuperation de la connection 
  1015.               $stmt $this->em->getConnection()->prepare($sql);              
  1016.               ( $idCaisse == )? $sql.= '' $stmt->bindValue(':idcaisse',$idCaissePDO::PARAM_INT); 
  1017.               ( $compte == '0' )? $sql.= '' $stmt->bindValue(':compte',$comptePDO::PARAM_INT); 
  1018.               if($idab !=0){
  1019.                  $stmt->bindValue(':idab',$idabPDO::PARAM_INT); 
  1020.                 }else{
  1021.                    ( $idprod == )? $sql.= '' $stmt->bindValue(':idprod',$idprodPDO::PARAM_INT); 
  1022.                 }             
  1023.               try{
  1024.                 $stmt->execute(); 
  1025.                 $liste $stmt->fetchAll(PDO::FETCH_ASSOC);
  1026.               }catch ( \Exception $e){
  1027.                  //var_dump(substr($e->getMessage(),600,800));exit;  
  1028.               }             
  1029.         }  
  1030.         
  1031.         return $liste 
  1032.     }    
  1033. public function soldeCaisseDesSerciceAutres(\Doctrine\ORM\EntityManager $emc,$idCaisse,$date,$idprod=0,$idab=0,$compte='0'){                 
  1034.          $date implode('-'array_reverseexplode('-',$date) ) ) ;
  1035.         // requete d'insertion de l'ecrirure comptable
  1036.         $sql =  " select p.nom_produit , o.lib_operation as detail, ".
  1037.                 "  o.montant, o.sensoperation ".
  1038.                 " from operation o inner join caisse c ".
  1039.                 "    on c.id =o.caisse_id inner join produit p on p.id =o.produit_id  ".
  1040.                 "    ".
  1041.                 " where  p.etat_produit =6 and 1=1 ";       
  1042.         ( $idCaisse == )? $sql.= '' $sql.= ' and c.id =:idcaisse';
  1043.         ( $compte == '0' )? $sql.= '' $sql.= ' and o.compte =:compte';
  1044.         if($idab !=0){
  1045.         $sql.= ' and o.id_abonne =:idab';
  1046.         }else{
  1047.             ( $idprod == )? $sql.= '' $sql.= ' and o.produit_id =:idprod';
  1048.         }
  1049.         
  1050.         ( $date != '')? $sql.=" AND  o.date_operation = " " '" $date "' " :  $sql.= '' ;
  1051.         
  1052.         //$sql .=' group by p.nom_produit';
  1053.       
  1054.       
  1055.         $liste null;
  1056.         
  1057.         // on ne passe les ecritures que si l'entity manager et le numero de piece sont pas null
  1058.         if ( $this->em != null ) {
  1059.               // recuperation de la connection 
  1060.               $stmt $this->em->getConnection()->prepare($sql);              
  1061.               ( $idCaisse == )? $sql.= '' $stmt->bindValue(':idcaisse',$idCaissePDO::PARAM_INT); 
  1062.               ( $compte == '0' )? $sql.= '' $stmt->bindValue(':compte',$comptePDO::PARAM_INT); 
  1063.               if($idab !=0){
  1064.                  $stmt->bindValue(':idab',$idabPDO::PARAM_INT); 
  1065.                 }else{
  1066.                    ( $idprod == )? $sql.= '' $stmt->bindValue(':idprod',$idprodPDO::PARAM_INT); 
  1067.                 }             
  1068.               try{
  1069.                 $stmt->execute(); 
  1070.                 $liste $stmt->fetchAll(PDO::FETCH_ASSOC);
  1071.               }catch ( \Exception $e){
  1072.                  //var_dump(substr($e->getMessage(),600,800));exit;  
  1073.               }             
  1074.         }  
  1075.         
  1076.         return $liste 
  1077.     }    
  1078.     
  1079.  public function somEntreeSortieDate(\Doctrine\ORM\EntityManager $emc,$idCaisse,$date){                 
  1080.         $sql =  " select c.id, 
  1081.                     sum(case 
  1082.                             when operation = 'D' then montant
  1083.                             when operation = 'C' then 0
  1084.                         end) as sommedebit,
  1085.                     sum(case 
  1086.                             when operation = 'D' then 0
  1087.                             when operation = 'C' then montant
  1088.                         end) as sommecredit
  1089.                   from operation o inner join caisse c
  1090.                     on c.compte = o.compte
  1091.                     ";       
  1092.         ( $idCaisse == )? $sql.= '' $sql.= ' and c.idcaisse =:idcaisse';
  1093.        // ( trim($date)=='' || $date != null)? $sql.= '' : $sql.=" AND  o.dateOperation = " . " '" . $date . "' ";
  1094.         ($date != null && trim($date) != '')? $sql.=" AND  o.dateOperation = " " '" $date "' " :  $sql.= '' ;
  1095.         $sql .= " ";
  1096.         $sql .= " group by c.id";
  1097.         
  1098.         $liste null;
  1099.         // on ne passe les ecritures que si l'entity manager et le numero de piece sont pas null
  1100.         if ( $this->em != null ) {
  1101.               // recuperation de la connection 
  1102.               $stmt $this->em->getConnection()->prepare($sql);              
  1103.               ( $idCaisse == )? $sql.= '' $stmt->bindValue(':idcaisse',$idCaissePDO::PARAM_INT);  
  1104.              
  1105.               try{
  1106.                 $stmt->execute(); 
  1107.                 $liste $stmt->fetchAll(PDO::FETCH_ASSOC);
  1108.               }catch ( \Exception $e){
  1109.                  //var_dump($e->getMessage());exit;  
  1110.               }             
  1111.         }  
  1112.        // //var_dump($liste); exit ;
  1113.         return $liste 
  1114.     }
  1115.     
  1116.     
  1117.     public function totalOperationParMois(\Doctrine\ORM\EntityManager $emc,$idCaisse$type,$compte){                 
  1118.         
  1119.         // requete d'insertion de l'ecrirure comptable
  1120.          $sql =  " select c.id,c.compte,cpte.libelle as libellecompte, 
  1121.                 YEAR(o.date_valeur) as lyear, MONTH(o.date_valeur) as lmonth,
  1122.                 CAST(CONCAT_WS( '-', YEAR(o.date_valeur), MONTH(o.date_valeur),'01' ) AS DATE) as premierDate,
  1123.                 sum(case when o.sensoperation = 'C' then o.montant end) as solde 
  1124.                 FROM caisse c left join operation o on o.caisse_id = c.id 
  1125.                 
  1126.                 inner join plancomptable cpte on cpte.compte = c.compte  
  1127.                 
  1128.                 WHERE 1=1 and o.compte =:compte  ";       
  1129.            // ( $idCaisse == 0 )? $sql.= '' : $sql.= " and c.id =:idcaisse";
  1130.                
  1131.                 $type == )? $sql.= '' $sql.= " and o.id_abonne =:type";
  1132.                 
  1133.         
  1134.         $sql .=" GROUP BY lyear, lmonth
  1135.                         ";
  1136.         //var_dump($compte,$sql);exit;
  1137.         // on ne passe les ecritures que si l'entity manager et le numero de piece sont pas null
  1138.         if ( $this->em != null ) {        $liste null;
  1139.               // recuperation de la connection 
  1140.               $stmt $this->em->getConnection()->prepare($sql);              
  1141.                     // ( $idCaisse == 0 )? $sql.= '' : $stmt->bindValue(':idcaisse',$idCaisse, PDO::PARAM_INT);   
  1142.                     $type == )? $sql.= '' $stmt->bindValue(':type',$typePDO::PARAM_INT);   
  1143.                     $stmt->bindValue(':compte',$comptePDO::PARAM_INT);   
  1144.               try{
  1145.                 $liste $stmt->executeQuery(); 
  1146.                 //= $stmt->fetchAssociative(PDO::FETCH_ASSOC);
  1147.               }catch ( \Exception $e){
  1148.                  //var_dump(substr($e->getMessage(),600,800));exit;  
  1149.               }             
  1150.         }   
  1151.             
  1152.        // var_dump($liste);exit;
  1153.         return $liste 
  1154.     }        
  1155.      /*
  1156.      * Retourne un nom par defaut lors de la création d'un nouveau param
  1157.      * @return type
  1158.      */
  1159.     public function getRecuperationCompte(\Doctrine\ORM\EntityManager $emc,$idTypeOp,$montantEsp$typeOperationRepository) {
  1160.         
  1161.         $lesComptes = array();
  1162.         $lesMontants = array();
  1163.         $tabCompteMontant =array();
  1164.         $i 0;
  1165.         $unTypeop $typeOperationRepository->find($idTypeOp);
  1166.         foreach ($unTypeop->getSchemas() as $unGenreTypeOp) {
  1167.              $lesComptes[$i] = $unGenreTypeOp->getPlancomptable()->getCompte();
  1168.              $lesMontants[$i] = $montantEsp;
  1169.              $i++;
  1170.          }
  1171.          $tabCompteMontant['compte'] = $lesComptes;
  1172.          $tabCompteMontant['montant'] = $lesMontants;
  1173.          return $tabCompteMontant ;
  1174.         
  1175.     } 
  1176.     
  1177.     
  1178.     /*
  1179.      * Retourne un nom par defaut lors de la création d'un nouveau param
  1180.      * @return type
  1181.      */
  1182.     public function getCompteVille(\Doctrine\ORM\EntityManager $emc,$idVille$villeRepository$caisseRepository) {
  1183.         $tabCompteId = array();
  1184.         $objetVille $villeRepository->find($idVille);
  1185.         $criteria = array('ville' => $objetVille);
  1186.         $objetCaisse $caisseRepository->findOneBy($criteria);
  1187.         $tabCompteId['compte'] = $objetCaisse->getPlanComptable()->getCompte();
  1188.         $tabCompteId['id'] = $objetCaisse->getId();
  1189.         return $tabCompteId ;
  1190.         
  1191.     } 
  1192.      /*
  1193.      * Retourne un nom par defaut lors de la création d'un nouveau param
  1194.      * @return type
  1195.      */
  1196.     public function getCompteCaisse(\Doctrine\ORM\EntityManager $emc,$idcaisse $caisseRepository) {
  1197.         $tabCompteId = array();
  1198.         $objetCaisse $caisseRepository->find($idcaisse);
  1199.         $tabCompteId['compte'] = $objetCaisse->getPlanComptable()->getCompte();
  1200.         $tabCompteId['id'] = $objetCaisse->getId();
  1201.         return $tabCompteId ;
  1202.         
  1203.     } 
  1204.     /*
  1205.      * Retourne un nom par defaut lors de la création d'un nouveau param
  1206.      * @return type
  1207.      */
  1208.     public function getTabLibelle(\Doctrine\ORM\EntityManager $emc,$idOper$compte,$libelleCaisse$libelleOperation$typeOperationRepository$schemaRepository ) {
  1209.         $tabLibelle = array();
  1210.         $objetTypOperation $typeOperationRepository->find($idOper);
  1211.         $objetSchemaComptable $schemaRepository->findBy(array("typeoperation"=>$objetTypOperation));
  1212.         
  1213.         foreach ($objetSchemaComptable as $uneSchemaComptable) {
  1214.             
  1215.             if($uneSchemaComptable->getSens() == 'D' ){
  1216.                 $tabLibelle[$uneSchemaComptable->getSens()] = $libelleCaisse;
  1217.             }else{
  1218.                 $tabLibelle[$uneSchemaComptable->getSens()] = $libelleOperation;
  1219.             }
  1220.         }
  1221.         
  1222.         return $tabLibelle ;
  1223.         
  1224.     } 
  1225.     
  1226.     
  1227.     
  1228.     public function getName() {
  1229.         return 'OperationManager';
  1230.     }    
  1231.    
  1232. }