예제 #1
0
 public function createAction(Request $request)
 {
     if ($request->getMethod() == 'POST') {
         if ($request->get('montant') > 0) {
             $operation = new Operation();
             $compte = new Compte();
             $compte->setId($request->get('compteId'));
             $operation->setCompte($compte)->setMontant($request->get('montant'))->setType($request->get('type'));
             $this->getDoctrine()->getRepository("MITFinanceBundle:Operation")->save($operation);
             return $this->redirect($this->generateUrl("versAddOperation"));
         }
     }
     return $this->redirect($this->generateUrl("versAddOperation"));
 }
예제 #2
0
 public function save(Operation $operation)
 {
     $operation->setCompte($this->_em->getRepository("MITFinanceBundle:Compte")->find($operation->getCompte()->getId()));
     $compte = $operation->getCompte();
     if ($operation->getType() == "debit") {
         if ($compte->getSolde() - $operation->getMontant() >= 0) {
             $compte->setSolde($compte->getSolde() - $operation->getMontant());
             $operation->setCompte($compte);
             $this->_em->persist($operation);
             $this->_em->getRepository("MITFinanceBundle:Compte")->_em->merge($compte);
             $this->_em->flush();
             return 1;
         }
         return -1;
     } else {
         $compte = $operation->getCompte();
         $compte->setSolde($compte->getSolde() + $operation->getMontant());
         $operation->setCompte($compte);
         $this->_em->persist($operation);
         $this->_em->getRepository("MITFinanceBundle:Compte")->_em->merge($compte);
         $this->_em->flush();
         return 2;
     }
 }