%PDF- %PDF-
Direktori : /home/emtnaeewxm/www/src/EEM/FonctionnaliteBundle/Service/ |
Current File : /home/emtnaeewxm/www/src/EEM/FonctionnaliteBundle/Service/TresorieService.php |
<?php namespace EEM\FonctionnaliteBundle\Service; use EEM\VenteBundle\Entity\Tresorie; use Doctrine\ORM\EntityManagerInterface; class TresorieService { private $em; public function __construct(EntityManagerInterface $entityManager) { $this->em = $entityManager; } public function controleExisteTresorie() { $date = new \DateTime(); $tresorie = $this->em->getRepository('EEMVenteBundle:Tresorie')->findBy(['date' => $date]); if (!$tresorie) { $tresories = $this->em->getRepository('EEMVenteBundle:Tresorie')->findBy([], ['id' => 'desc']); $last_tresorie = $tresories[0]->getMontant(); $tresorie = new Tresorie(); $tresorie->setDate($date); $tresorie->setMontant($last_tresorie); $this->em->persist($tresorie); $this->em->flush(); } } public function mettreAJourTresorie($montant) { $date = new \DateTime(); $tresorie = $this->em->getRepository('EEMVenteBundle:Tresorie')->findOneBy(['date' => $date],['id'=>'desc']); if ($tresorie) { $tresorie->setMontant($tresorie->getMontant()+ $montant); $this->em->flush(); } } }