Example #1
0
 /**
  * @param AccountEntity $account
  * @return bool
  */
 public function synchronizeAccount(AccountEntity $account)
 {
     foreach ($this->getDrivers() as $driver) {
         if ($driver->getCode() == $account->getBank()->getCode()) {
             $payments = $driver->getPayments($account, $account->getSyncDate());
             $last = NULL;
             foreach ($payments as $payment) {
                 if ($this->paymentRepository->findOneBy(array('paymentId' => $payment->getPaymentId())) || $this->paymentRepository->findOneBy(array('instructionId' => $payment->getInstructionId()))) {
                     continue;
                 }
                 $payment->setAccount($account);
                 $this->paymentRepository->save($payment);
                 $last = $payment;
             }
             if ($last instanceof PaymentEntity) {
                 $account->setSyncDate($last->getDate());
                 $this->accountRepository->save($account);
             }
             return TRUE;
         }
     }
     return FALSE;
 }
Example #2
0
 /**
  * @param $number
  * @param CurrencyEntity $currency
  * @param $code
  * @param null $user
  * @param null $name
  * @return AccountEntity
  */
 private function getAccountByNumber($number, CurrencyEntity $currency, $code, $user = NULL, $name = NULL)
 {
     $entity = $this->accountRepository->createQueryBuilder('a')->leftJoin('a.bank', 'b')->andWhere('b.code = :code')->setParameter('code', $code)->andWhere('a.name = :name')->setParameter('name', $number)->getQuery()->getOneOrNullResult();
     if ($entity === NULL) {
         $entity = new AccountEntity();
         $entity->setBank($this->getBankByCode($code, $name));
         $entity->setName($number);
         $entity->setCurrency($currency);
         $this->accountRepository->save($entity);
     }
     if (!$entity->getPerson() && $user) {
         $entity->setPerson($this->getPersonByName($user));
         $this->accountRepository->save($entity);
     }
     return $entity;
 }