/** * Ajouter une operation * @param Request $request * @return type */ public function addAction(Request $request) { // crée une tâche et lui donne quelques données par défaut pour cet exemple $operation = new Operation(); $form = $this->createFormBuilder($operation)->add('libelle', 'text')->add('description', 'textarea')->add('montant', 'money')->getForm(); $form->handleRequest($request); if ($form->isValid()) { $this->get('activity.manager')->create($operation); // fait quelque chose comme sauvegarder la tâche dans la bdd $em = $this->getDoctrine()->getManager(); $em->persist($operation); $em->flush(); // On récupère le montant de la caisse $query = $em->createQuery('SELECT c FROM ESNTreasuryBundle:Caisse c ORDER BY c.date DESC ')->setMaxResults(1); try { $montantQuery = $query->getSingleResult(); $montant = $montantQuery->getMontant(); } catch (NoResultException $e) { $montant = 0; } $em = $this->getDoctrine()->getManager(); $caisse = new Caisse(); $caisse->setMontant($montant + $operation->getMontant()); $em->persist($caisse); $em->flush(); $this->get('activity.manager')->create($caisse); $request->getSession()->getFlashBag()->add('notice', 'Opération bien enregistrée.'); return $this->redirect($this->generateUrl('esn_treasury_list')); } return $this->render('ESNTreasuryBundle:Operations:add.html.twig', array('title' => "Treasury", 'form' => $form->createView())); }
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(); }
protected function onSuccess(ParticipateTrip $participateTrip) { $participateTrip->setDateInscription(new \DateTime()); $operation = new Operation(); $operation->setDate(new \DateTime()); $operation->setDescription("New payment for the trip : " . $participateTrip->getTrip()->getName()); $operation->setLibelle("Payment for a trip"); $operation->setMontant($participateTrip->getTrip()->getPrice()); $montant = $this->em->getRepository('ESNTreasuryBundle:Caisse')->getLastCaisse(); $caisse = new Caisse(); $caisse->setMontant($montant + $operation->getMontant()); $this->em->persist($caisse); $this->em->persist($operation); $this->em->persist($participateTrip); $this->em->flush(); }