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(); }
/** * Crée le formulaire de rapport et sauvegarde un nouveau rapport en base. * * @param Request $request * * @return mixed */ public function createAction(Request $request) { /** @var EntityManager $em */ $em = $this->getDoctrine()->getManager(); /** @var integer $caisse */ $caisse = $em->getRepository('ESNTreasuryBundle:Caisse')->getLastCaisse(); /** @var integer $nbCard */ $nbCard = $em->getRepository('ESNAdministrationBundle:Card')->getNumberOfCards(); $report = new PermanenceReport(); $report->setAmountBefore($caisse); $report->setAmountAfter($caisse); $report->setAvailableCard($nbCard); /** @var PermanenceReport $previousReport */ $previousReport = $em->getRepository('ESNPermanenceBundle:PermanenceReport')->getLast(); /** @var Form $form */ $form = $this->get('form.factory')->create(new ReportType($this->getTranslator()), $report); $formHandler = new ReportHandler($em, $form, $request, $this->getUser()); $form->handleRequest($request); if ($formHandler->process()) { $this->get('activity.manager')->create($report); $request->getSession()->getFlashBag()->add('notice', 'Rapport bien enregistrée.'); return $this->redirect($this->generateUrl('esn_permanence_reports')); } return $this->render('ESNPermanenceBundle:Reports:create.html.twig', array('form' => $form->createView(), 'cards' => $nbCard, 'money' => $caisse, 'previous' => $previousReport[0])); }