/** ************************************************************************
  * Create a new TransferBetweenAccount according to the information given in the form.
  * @param \Finance\AccountBundle\Entity\Account $account
  * @ParamConverter("account", options={"mapping": {"account_id": "id"}})
  * @Route("/add/{account_id}", requirements={"account_id" = "\d+"})
  **************************************************************************/
 public function addAction(\Finance\AccountBundle\Entity\Account $account)
 {
     $transferBetweenAccount = new TransferBetweenAccount();
     $transferBetweenAccount->setSourceAccount($account);
     $transferBetweenAccount->setDestinationAccount($account);
     $form = $this->createForm(new TransferBetweenAccountType(), $transferBetweenAccount);
     // ------------- Request Management ------------------------------------
     $request = $this->get('request');
     if ($request->getMethod() == 'POST') {
         $form->bind($request);
         // Link Request and Form
         if ($form->isValid()) {
             $em = $this->getDoctrine()->getManager();
             $em->persist($transferBetweenAccount);
             $em->flush();
             return $this->redirect($this->generateUrl('finance_operation_transferbetweenaccount_see', array('transferBetweenAccount_id' => $transferBetweenAccount->getId())));
         }
     }
     return $this->render('FinanceOperationBundle:TransferBetweenAccount:add.html.twig', array('form' => $form->createView(), 'account' => $account));
 }
 /** ************************************************************************
  * Convert the HTML string containing the copy-paste from Boursorama CCP page
  * into an Operation and TransferBetweenAccount array.
  * @param \Finance\AccountBundle\Entity\Account $account
  * @param string $htmlString
  * @return Operation[]
  **************************************************************************/
 public function processHtmlString(\Finance\AccountBundle\Entity\Account $account, $htmlString)
 {
     $abstractOperations = array('transferBetweenAccounts' => array(), 'operations' => array());
     foreach ($this->htmlStringToArray($htmlString) as $lineIndex => $line) {
         if ($this->isTransferBetweenAccount($line['label operation'])) {
             $transferBetweenAccount = new TransferBetweenAccount();
             $transferBetweenAccount->setIsMarked(true);
             $transferBetweenAccount->setDate($this->convertDate($line['dateValeur']));
             $transferBetweenAccount->setAmount($this->convertAmount($line['amount']));
             $transferBetweenAccount->setSourceAccount($this->convertSourceAccount($line['label operation']));
             $transferBetweenAccount->setDestinationAccount($this->convertDestinationAccount($line['label operation']));
             $abstractOperations['transferBetweenAccounts'][$lineIndex] = $transferBetweenAccount;
             $abstractOperations['originalHtml']['transferBetweenAccounts'][$lineIndex] = $line['originalHtml'];
         } else {
             $operation = new Operation($account);
             $operation->setIsMarked(true);
             $operation->setDate($this->convertDate($line['dateValeur']));
             $operation->setAmount($this->convertAmount($line['amount']));
             $operation->setPaymentMethod($this->convertPaymentMethod($line['label operation']));
             $operation->setStakeholder($this->convertStakeholder($line['label operation']));
             $operation->setCategory($this->convertCategory($line['label operation']));
             $abstractOperations['operations'][$lineIndex] = $operation;
             $abstractOperations['originalHtml']['operations'][$lineIndex] = $line['originalHtml'];
         }
     }
     return $abstractOperations;
 }