コード例 #1
0
 /**
  * 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());
     }
 }