Exemplo n.º 1
0
 public function getSaldo(BankAccount $bankAccount)
 {
     $repo = $this->entityManager->getRepository('HomefinanceBundle:Transaction');
     $transactions = $repo->findBy(array('administration' => $bankAccount->getAdministration(), 'bank_account' => $bankAccount));
     $total = (double) $bankAccount->getStartingBalance();
     foreach ($transactions as $t) {
         $total = $total + $t->getAmount();
     }
     return $total;
 }
 /**
  * @Route("/bankaccounts/add", name="add_bank_account")
  *
  * @param Request $request
  * @return Response
  */
 public function addBankAccountAction(Request $request)
 {
     $administration = $this->checkCurrentAdministration(Permission::FULL_ACCESS);
     $account = new BankAccount();
     $account->setAdministration($administration);
     $form = $this->createForm('bank_account', $account);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($account);
         $em->flush();
         $this->addFlash('success', 'bank_account.added');
         return $this->redirect($this->generateUrl('bank_accounts'));
     }
     return $this->render('HomefinanceBundle:Administration:add_bank_account.html.twig', array('form' => $form->createView()));
 }