protected function onSuccess(PermanenceReport $report) { //Remove numbers of card $sellcard = $report->getSellCard(); $nbCard = $this->em->getRepository('ESNAdministrationBundle:Card')->getNumberOfCards(); $availableCard = $nbCard - $sellcard; $report->setAmountSell($report->getSellCard() * 5); $report->setOwner($this->user); $Card = new Card(); $Card->setNumber($availableCard); $this->em->persist($Card); $operation = new Operation(); $operation->setMontant($report->getAmountSell()); $operation->setDate(new \DateTime()); $operation->setLibelle("Vente carte ESN pendant la perm"); $operation->setDescription("Vente de " . $report->getSellCard() . " cartes ESN"); $this->em->persist($operation); // CAISSE $montant = $this->em->getRepository('ESNTreasuryBundle:Caisse')->getLastCaisse(); $caisse = new Caisse(); $caisse->setMontant($montant + $operation->getMontant()); $this->em->persist($caisse); if (!$report->getId()) { $this->em->persist($report); } $this->em->flush(); }