<?php
namespace App\Repository\stock;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use App\Entity\stock\Operation;
use Doctrine\ORM\RepositoryRepository;
use App\Types\user\TypeEtat;
use DateInterval;
use App\ControllerModel\user\paramUtilTrait;
/**
* OperationRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class OperationRepository extends ServiceEntityRepository
{
use paramUtilTrait;
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Operation::class);
}
public function getListeOperationCommande($id) {
$query = $this->_em->createQuery(
'SELECT o,c
FROM App\Entity\stock\Operation o INNER JOIN o.commande c
WHERE c.id = :id'
)->setParameter('id', $id);
return $query->getResult();
}
/**
* Retourne tous les fournisseurs.
*
* @return type
*/
public function getAllOperation() {
$qb = $this->createQueryBuilder('r')
->where('r.etatOperation != ' . TypeEtat::SUPPRIME)
->orderBy('r.id', 'ASC');
return $qb->getQuery()->getResult();
}
public function getOperationsCaisseBrouillardOld($caisse, $typedate, $datedeb, $datefin, $typeop, $idprod, $idab = '0', $compte = '0', $details = '0') {
$param = array();
$paramdeb = $datedeb; //implode('/', array_reverse( explode('-',$datedeb) ) ) ;
$paramfin = $datefin; //implode('/', array_reverse( explode('-',$datefin) ) ) ;
// o.soldeLigne,o.chrgjr,
$sql = "SELECT DISTINCT o.id, o.sensOperation AS sens , o.dateOperation, o.montant , o.numMvt, o.libOperation, o.planAnalytique, o.refFacture , p.compte
FROM App\Entity\stock\Operation o ";
if ($idab == '0') {
/* $sql .= " INNER JOIN o.produit c
INNER JOIN c.categorie ca "; */
} else {
$compte = 'CPTE001';
}
$sql .= " INNER JOIN o.typeoperation t
INNER JOIN o.plancomptable p
LEFT JOIN o.commande co
WHERE 1=1 ";
if ($idab == '0') {
/** debut critère recherche * */
// ( ($deb == null) || ($deb == 0) )? $sql.="' : $sql.=' AND o.dateValeur >= :deb and o.dateValeur <= :fin ';
if ($typedate == 0) {
( $datedeb != 0 && $datedeb != "" ) ? $sql .= " AND o.dateOperation >= " . " '" . $paramdeb . "' " : $sql .= '';
( $datefin != 0 && $datefin != "" ) ? $sql .= " AND o.dateOperation <= " . " '" . $paramfin . "' " : $sql .= '';
} else {
( $datedeb != 0 && $datedeb != "" ) ? $sql .= " AND o.dateValeur >= " . " '" . $paramdeb . "' " : $sql .= '';
( $datefin != 0 && $datefin != "" ) ? $sql .= " AND o.dateValeur <= " . " '" . $paramfin . "' " : $sql .= '';
}
}
($caisse == 0) ? $sql .= '' : $sql .= 'AND c.id = :caisse ';
($details == '0' ) ? $sql .= '' : $sql .= 'AND o.libOperation like :details ';
($compte == '0') ? $sql .= '' : $sql .= 'and p.compte = :compte';
( trim($typeop) == 0) ? $sql .= '' : $sql .= ' AND o.refFacture = :typeop ';
( trim($idprod) == 0) ? $sql .= '' : $sql .= ' AND co.id = :idprod ';
( trim($idab) == '0') ? $sql .= '' : $sql .= ' AND o.idAbonne = :idab ';
/** Fin critère recherche * */
$sql .= ' ORDER BY o.id DESC';
/** debut parametres * */
if (trim($typeop) != 0) {
$param['typeop'] = $typeop;
}
if (trim($idprod) != 0) {
$param['idprod'] = $idprod;
}
if (trim($idab) != '0') {
$param['idab'] = $idab;
}
if (trim($details) != '0') {
$param['details'] = '%' . $details . '%';
}
if (trim($caisse) != 0) {
$param['caisse'] = $caisse;
}
if (trim($compte) != '0') {
$param['compte'] = $compte;
}
//var_dump( $sql);exit;
/** Fin parametres et valeur * */
$query = $this->_em->createQuery($sql);
$query->setParameters($param);
return $query->getResult();
}
public function getTotalOperationsBrouillard($caisse, $datedeb, $datefin, $typeop, $typedate) {
$param = array();
$paramdeb = implode('-', array_reverse(explode('-', $datedeb)));
$paramfin = implode('-', array_reverse(explode('-', $datefin)));
/* $sql = 'SELECT count(o.id)
FROM App\Entity\stock\Operation o
INNER JOIN o.caisse c
INNER JOIN o.typeoperation t
WHERE 1 = 1 '; */
$sql = "SELECT count(o.id)
FROM App\Entity\stock\Operation o
INNER JOIN o.caisse c
INNER JOIN o.typeoperation t
INNER JOIN o.plancomptable p
WHERE p.compte = c.plancomptable ";
/** debut critère recherche * */
// ( ($deb == null) || ($deb == 0) )? $sql.='' : $sql.=' AND o.dateValeur >= :deb and o.dateValeur <= :fin ';
if ($typedate == 0) {
( $datedeb != 0 ) ? $sql .= " AND o.dateOperation >= " . " '" . $paramdeb . "' " : $sql .= '';
( $datefin != 0 ) ? $sql .= " AND o.dateOperation <= " . " '" . $paramfin . "' " : $sql .= '';
} else {
( $datedeb != 0 ) ? $sql .= " AND o.dateValeur >= " . " '" . $paramdeb . "' " : $sql .= '';
( $datefin != 0 ) ? $sql .= " AND o.dateValeur <= " . " '" . $paramfin . "' " : $sql .= '';
}
($caisse == 0) ? $sql .= '' : $sql .= 'AND c.id = :caisse ';
( trim($typeop) == 0) ? $sql .= '' : $sql .= ' AND t.id = :typeop ';
/** Fin critère recherche * */
/** debut parametres * */
if (trim($typeop) != 0) {
$param['typeop'] = $typeop;
}
if (trim($caisse) != 0) {
$param['caisse'] = $caisse;
}
/** Fin parametres et valeur * */
$query = $this->_em->createQuery($sql);
$query->setParameters($param);
try {
//$lavaleur = $query->getResult();
$lavaleur = $query->getSingleScalarResult();
} catch (\Doctrine\ORM\NoResultException $e) {
$lavaleur = 0;
}
return $lavaleur;
}
public function getOperationsCaisseBrouillard($caisse, $typedate, $datedeb, $datefin, $typeop=0, $total, $page, $articles_per_page, $idprod, $idfour, $compte = '0', $details = '0', $ville = '0', $silivre = '0', $abonneId = '0', $clientId = '0', $producteurId = '0', $partenaireId = '0', $fournisseurId = '0') {
$param = array();
$datedebarray = array();
$datefinarray = array();
if ($datedeb == 0 && $datefin == 0 && $producteurId == 0) {
$dateJour = new \DateTime();
$premierDate = $this->dateDuPremierDuMois($dateJour);
$datedeb = $premierDate->format("d/m/Y 00:00:00");
$dateMoi = $premierDate->add(new DateInterval('P1M'));
$datefin = $dateMoi->format("d/m/Y 00:00:00");
}
$heureDebut = explode(' ', $datedeb);
$heureFin = explode(' ', $datefin);
$datedebarray = $this->traiterDateFormat($datedeb);
$datefinarray = $this->traiterDateFormat($datefin);
$paramdeb = implode("-", $datedebarray);
$paramfin = implode("-", $datefinarray);
$sql = "SELECT o.id, o.sensOperation AS sens , o.dateOperation, o.montant , o.numMvt, o.libOperation, v.nomVille ,o.refFacture, o.planAnalytique , p.compte, p.infoCompte
FROM App\Entity\stock\Operation o ";
if ($idfour != '0') {
$sql .= " LEFT JOIN o.commande c
LEFT JOIN c.fournisseur f ";
}
$sql .= " LEFT JOIN o.produit pr
INNER JOIN o.typeoperation t
INNER JOIN o.plancomptable p
";
//if($ville !='0'){
$sql .= " LEFT JOIN o.ville v ";
if (trim($abonneId) != '0') {
$sql .= " INNER JOIN o.abonne a ";
}
if ($partenaireId != '0') {
$sql .= " INNER JOIN o.partenaire pa ";
}
if ($producteurId != '0' && $producteurId != '' ) {
$sql .= " INNER JOIN o.producteur pd ";
}
if ($fournisseurId != '0') {
$sql .= " INNER JOIN o.fournisseur four ";
}
if (trim($caisse) != '0') {
$sql .= " INNER JOIN o.caisse c ";
}
if (trim($clientId) != '0') {
$sql .= " INNER JOIN o.client cl ";
}
//}
$sql .= " WHERE 1=1 ";
/** debut critère recherche * */
// ( ($deb == null) || ($deb == 0) )? $sql.="' : $sql.=' AND o.dateValeur >= :deb and o.dateValeur <= :fin ';
if (($datedeb == 0 && $datefin == 0 && $producteurId == 0) or ($datedeb != 0 or $datefin != 0 ) ) {
$sql .= " AND o.dateOperation >= " . " '" . $paramdeb." ".$heureDebut[1] . "' ";
$sql .= " AND o.dateOperation <= " . " '" . $paramfin." ".$heureFin[1] . "' ";
}
($caisse == 0) ? $sql .= '' : $sql .= 'AND c.id = :caisse ';
($ville == '0') ? $sql .= '' : $sql .= 'AND v.id = :ville ';
//($silivre == '0') ? $sql .= '' : $sql .= 'AND o.idAbonne = :silivre ';
($details == '0' or $details == '' ) ? $sql .= '' : $sql .= 'AND o.libOperation like :details ';
// ($typeop == '0' ) ? $sql .= '' : $sql .= 'AND t.id =:idtypeop ';
($compte == '0') ? $sql .= '' : $sql .= ' AND p.compte = :compte';
($idfour == '0') ? $sql .= '' : $sql .= ' AND f.id = :idfour';
($idprod == '0') ? $sql .= '' : $sql .= ' AND pr.id = :idprod';
($abonneId == '0') ? $sql .= '' : $sql .= ' AND a.id = :abonneId';
($clientId == '0') ? $sql .= '' : $sql .= ' AND cl.id = :clientId';
($idfour == '0') ? $sql .= '' : $sql .= ' AND f.id = :idfour';
($typeop != 0 && $typeop != "") ? $sql .= ' AND t.id = :typeop ' : $sql .= '';
($partenaireId == '0') ? $sql .= '' : $sql .= ' AND pa.id = :partenaireId';
($producteurId != '0' && $producteurId != '') ? $sql .= ' AND pd.id = :producteurId' : $sql .= ' ';
($fournisseurId == '0') ? $sql .= '' : $sql .= ' AND four.id = :fournisseurId';
//var_dump($silivre, $sql,$compte);exit;
/** Fin critère recherche * */
$sql .= ' ORDER BY o.dateOperation DESC';
/** debut parametres * */
//var_dump($sql,$caisse, $typedate,$datedeb, $datefin, $typeop, $total, $page, $articles_per_page, $idprod, $idfour,$compte, $details, $ville,$silivre); exit;
if ($typeop != 0 && $typeop != "") {
$param['typeop'] = $typeop;
}
if (trim($idprod) != '0') {
$param['idprod'] = $idprod;
}
if ($partenaireId != '0') {
$param['partenaireId'] = $partenaireId;
}
if ($producteurId != '0' && $producteurId != '') {
$param['producteurId'] = $producteurId;
}
if ($fournisseurId != 0) {
$param['fournisseurId'] = $fournisseurId;
}
if ($details != '0' && $details != '') {
$param['details'] = '%' . $details . '%';
}
if (trim($caisse) != 0) {
$param['caisse'] = $caisse;
}
if (trim($ville) != 0) {
$param['ville'] = $ville;
}
if (trim($clientId) != '0') {
$param['clientId'] = $clientId;
}
/* if (trim($silivre) != 0) {
$param['silivre'] = $silivre;
}*/
if (trim($compte) != '0') {
$param['compte'] = $compte;
}
if (trim($idfour) != '0') {
$param['idfour'] = $idfour;
}
if (trim($abonneId) != '0') {
$param['abonneId'] = $abonneId;
}
// var_dump($sql, $typeop);exit;
// exit;
/** Fin parametres et valeur * */
$query = $this->_em->createQuery($sql);
$query->setParameters($param);
//var_dump($query->getSQL(), $compte, $caisse, $abonneId );exit;
return $query->getResult();
}
public function getOperationsSuivieLivraison($datedeb, $datefin, $typeop, $ville = '0') {
$param = array();
$datedebarray = array();
$datefinarray = array();
//var_dump($datedeb, $datefin);exit;
if ($datedeb == 0 && $datefin == 0) {
$dateJour = new \DateTime();
$premierDate = $this->dateDuPremierDuMois($dateJour);
$datedeb = $premierDate->format("d/m/Y");
$dateMoi = $premierDate->add(new DateInterval('P1M'));
$datefin = $dateMoi->format("d/m/Y");
}
//traitement des tableaux
//heure debut
$datedebarray = $this->traiterDateFormat($datedeb);
$datefinarray = $this->traiterDateFormat($datefin);
//var_dump($silivre);exit;
$paramdeb = implode("-", $datedebarray);
$paramfin = implode("-", $datefinarray);
$sql = "SELECT s
FROM App\Entity\stock\SuivieLivraison s ";
if (trim($ville) != 0) {
$sql .= " INNER JOIN s.ville v ";
}
$sql .= " WHERE 1=1 ";
$sql .= " AND s.dateSuivie >= " . " '" . $paramdeb . "' ";
$sql .= " AND s.dateSuivie <= " . " '" . $paramfin . "' ";
($ville == '0') ? $sql .= '' : $sql .= 'AND v.id = :ville ';
( trim($typeop) == 0) ? $sql .= '' : $sql .= ' AND t.id = :typeop ';
/** Fin critère recherche * */
$sql .= ' ORDER BY s.dateSuivie DESC';
// var_dump($sql);exit;
if (trim($typeop) != 0) {
$param['typeop'] = $typeop;
}
if (trim($ville) != 0) {
$param['ville'] = $ville;
}
$query = $this->_em->createQuery($sql);
$query->setParameters($param);
//var_dump($query->getSQL());exit;
return $query->getResult();
}
}