/**
  * Save date in database
  * @param type $nAccountId
  * @param type $aData
  * @return boolean
  */
 private function saveData($nAccountId, $aData)
 {
     try {
         $oRepoAccount = $this->getRepoEntity('Account');
         $oAccount = $oRepoAccount->findOneById($nAccountId);
         $em = $this->getDoctrine()->getManager();
         foreach ($aData as $key => $data) {
             // date
             $sDate = Help::convertFrenchDate(trim($data['date']));
             $sValeurEuro = trim(str_replace(',', '.', $data['value']));
             $aCateg = LclExcelFile::findCategoryByTransaction($data);
             // check if the some transaction exist in database
             $oRepoTrans = $this->getRepoEntity('Transaction');
             $oTransaction = $oRepoTrans->findOneBy(array('date' => new \DateTime($sDate), 'wording' => $aCateg['label'], 'amount' => $sValeurEuro));
             if (!empty($aCateg['name'])) {
                 if (!$oTransaction instanceof Transaction) {
                     $oTransaction = new Transaction();
                 }
                 $oCateg = $this->getCategorieObject($aCateg['name']);
                 // save
                 $oTransaction->setDate(new \DateTime($sDate));
                 $oTransaction->setCategory($oCateg);
                 $oTransaction->setWording($aCateg['label']);
                 $oTransaction->setAmount($sValeurEuro);
                 $oTransaction->setAccount($oAccount);
                 $oTransaction->setModifiedAt(new \DateTime());
                 $em->persist($oTransaction);
             }
         }
         $em->flush();
         return true;
     } catch (Exception $ex) {
         $this->get('logger')->error($ex->getMessage());
     }
 }
 /**
  * Index
  * @Route("/home", name="home")
  */
 public function indexAction(Request $oRequest)
 {
     $oRepo = $this->getRepoEntity('Account');
     $aAccount = $oRepo->getAccountsListForm($this->container);
     $nAccount = count($aAccount);
     $aLastSearch = $this->findInSession('lastSearch');
     // si aucun compte dans la base de donnnée
     if (0 == $nAccount) {
         return $this->redirect($this->generateUrl('account'));
     }
     $sDateBegin = Help::getCustomDate('Y-m-d', 'first day of last month');
     $sDateEnd = Help::getCustomDate('Y-m-d', 'last day of last month');
     if (!empty($aLastSearch)) {
         $sDateBegin = $aLastSearch['date_begin'];
         $sDateEnd = $aLastSearch['date_end'];
     }
     $oForm = $this->createForm(new BasicForm($aAccount, $sDateBegin, $sDateEnd));
     $oRep = $this->getRepoEntity('Transaction');
     $oObj = $oRep->getLastTransaction();
     $oLastDate = !is_null($oObj) ? $oObj->getCreatedAt() : null;
     return $this->render('AnalyzerBundle:Index:index.html.twig', array('oLastDate' => $oLastDate, 'form' => $oForm->createView(), 'formAction' => $this->generateUrl('basicStatistics'), 'nAccount' => $nAccount));
 }
 /**
  * @Route("/transaction/find", name="findTransactions")
  */
 public function findTransactionsAction(Request $oRequest)
 {
     // $aCategories = $this->container->getParameter('categories');
     $nPages = $nFirstResult = 0;
     $aRequest = $oRequest->request->all();
     $nPage = isset($aRequest['page']) ? $aRequest['page'] : 1;
     $nPerPage = $this->container->getParameter('per_page');
     $sWording = !empty($aRequest['wording']) ? $aRequest['wording'] : null;
     if ($nPage > 1) {
         $nFirstResult = $nPerPage * ($nPage - 1);
     }
     if (!empty($aRequest['date_begin']) && !empty($aRequest['date_end'])) {
         $oAccount = $this->getRepoEntity('Account')->find($aRequest['account']);
         $sDateBegin = $aRequest['date_begin'];
         $sDateEnd = $aRequest['date_end'];
         $nCategId = $aRequest['category'];
         $oRepTransaction = $this->getRepoEntity('Transaction');
         $oCategory = null;
         if ($nCategId != 0) {
             $oCategory = $this->getRepoEntity('Category')->findOneById($nCategId);
         }
         $aoTransactions = $oRepTransaction->findByAccount($oAccount, $sDateBegin, $sDateEnd, $oCategory, $sWording, null, $nFirstResult, $nPerPage);
         $nPages = Help::getNumberPages($aoTransactions['TotalRecordCount'], $nPerPage);
     }
     return $this->render('AnalyzerBundle:Transaction:list.html.twig', array('aoTransactions' => $aoTransactions, 'nPages' => $nPages, 'currentPage' => $nPage));
 }