/**
  * Displays a form to create a new Payment entity.
  *
  * @Route("/new_simple_expense", name="finance_payment_simple_expense_create")
  * @Method("POST")
  * @Template("FlowerFinancesBundle:Payment:newSimpleExpense.html.twig")
  */
 public function createSimpleExpenseAction(Request $request)
 {
     $payment = new Payment();
     $payment->setType(Payment::TYPE_EXPENSE);
     $em = $this->getDoctrine()->getManager();
     $expenseAccount = $em->getRepository('FlowerFinancesBundle:Account')->find($request->get('expense_account_id'));
     $assetAccount = $em->getRepository('FlowerFinancesBundle:Account')->find($request->get('asset_account_id'));
     $form = $this->createForm(new SimpleExpensePaymentType(), $payment);
     if ($form->handleRequest($request)->isValid()) {
         /* has receipt */
         if ($request->get('receipt_number')) {
             $receipt = new Document();
             $type = $this->getDoctrine()->getManager()->getRepository('FlowerFinancesBundle:DocumentType')->findOneBy(array('name' => \Flower\FinancesBundle\Entity\DocumentType::TYPE_RECEIPT));
             $receipt->setCode($request->get('receipt_number'));
             $receipt->setType($type);
             $receipt->setTotal($payment->getAmount());
             $em->persist($receipt);
             $payment->addDocument($receipt);
         }
         $transaction = $this->get('finances.service.transaction')->createSimpleExpenseTransaction($expenseAccount, $assetAccount, $payment->getAmount(), $payment->getDate());
         $payment->setTransaction($transaction);
         $em->persist($payment);
         $em->flush();
         return $this->redirect($this->generateUrl('finance_payment_show', array('id' => $payment->getId())));
     }
     $assetAccounts = $em->getRepository('FlowerFinancesBundle:Account')->findBy(array('type' => Account::TYPE_ASSET));
     $expenseAccounts = $em->getRepository('FlowerFinancesBundle:Account')->findBy(array('type' => Account::TYPE_EXPENSE));
     return array('form' => $form->createView(), 'assetAccounts' => $assetAccounts, 'expenseAccounts' => $expenseAccounts);
 }