/** ************************************************************************
  * 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;
 }
 /** ************************************************************************
  * Create a new Operation 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)
 {
     $recurrentOperation = new Operation($account);
     $recurrentOperation->setIsMonthlyRecurrent(true);
     $recurrentOperation->setDate(new \DateTime());
     $recurrentOperation->setIsMarked(false);
     $form = $this->createForm(new RecurrentOperationType(), $recurrentOperation);
     // ------------- 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($recurrentOperation);
             $em->flush();
             return $this->redirect($this->generateUrl('finance_operation_operation_see', array('operation_id' => $recurrentOperation->getId())));
         }
     }
     return $this->render('FinanceOperationBundle:RecurrentOperation:add.html.twig', array('form' => $form->createView(), 'account' => $account));
 }
 /** ************************************************************************
  * Duplicate the Operation $operation.
  * 
  * @param Operation $oldOperation
  * @ParamConverter("oldOperation", options={"mapping": {"oldOperation_id": "id"}})
  * @Route("/duplicate/{oldOperation_id}", requirements={"oldOperation_id" = "\d+"})
  **************************************************************************/
 public function duplicateAction(Operation $oldOperation)
 {
     $newOperation = new Operation($oldOperation->getAccount());
     $this->get('financeoperation.operationhelper')->duplicate($oldOperation, $newOperation);
     $form = $this->createForm(new OperationType($newOperation), $newOperation);
     // ------------- 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($newOperation);
             $em->flush();
             return $this->redirect($this->generateUrl('finance_operation_operation_see', array('operation_id' => $newOperation->getId())));
         }
     }
     return $this->render('FinanceOperationBundle:Operation:add.html.twig', array('account' => $oldOperation->getAccount(), 'oldOperation' => $oldOperation, 'form' => $form->createView()));
 }