/**
  * Creates a StatementOfAccount model from array.
  *
  * @param array $array
  * @return StatementOfAccount|null
  */
 public static function createModelFromArray(array $array)
 {
     if (empty($array)) {
         return null;
     }
     $soa = new StatementOfAccount();
     foreach ($array as $date => $statement) {
         $statementModel = new Statement();
         $statementModel->setDate(new \DateTime($date));
         $statementModel->setStartBalance((double) $statement['start_balance']['amount']);
         $statementModel->setCreditDebit($statement['start_balance']['credit_debit']);
         if (isset($statement['transactions'])) {
             foreach ($statement['transactions'] as $trx) {
                 $transaction = new Transaction();
                 $transaction->setBookingDate(new \DateTime($trx['booking_date']));
                 $transaction->setValutaDate(new \DateTime($trx['valuta_date']));
                 $transaction->setCreditDebit($trx['credit_debit']);
                 $transaction->setAmount($trx['amount']);
                 $transaction->setBookingText($trx['description']['booking_text']);
                 $transaction->setDescription1($trx['description']['description_1']);
                 $transaction->setDescription2($trx['description']['description_2']);
                 $transaction->setBankCode($trx['description']['bank_code']);
                 $transaction->setAccountNumber($trx['description']['account_number']);
                 $transaction->setName($trx['description']['name']);
                 $statementModel->addTransaction($transaction);
             }
         }
         $soa->addStatement($statementModel);
     }
     return $soa;
 }
Пример #2
0
 public function test_getter_and_setter()
 {
     $obj = new Statement();
     $this->assertInternalType('array', $obj->getTransactions());
     $this->assertEmpty($obj->getTransactions());
     $this->assertSame(0.0, $obj->getStartBalance());
     $this->assertNull($obj->getCreditDebit());
     $this->assertNull($obj->getDate());
     $trx1 = new Transaction();
     $trx2 = new Transaction();
     $obj->addTransaction($trx1);
     $this->assertCount(1, $obj->getTransactions());
     $obj->addTransaction($trx2);
     $this->assertCount(2, $obj->getTransactions());
     $obj->setTransactions(null);
     $this->assertNull($obj->getTransactions());
     $obj->setTransactions(array());
     $this->assertInternalType('array', $obj->getTransactions());
     $this->assertCount(0, $obj->getTransactions());
     $trxArray = array($trx1, $trx2);
     $obj->setTransactions($trxArray);
     $this->assertInternalType('array', $obj->getTransactions());
     $this->assertCount(2, $obj->getTransactions());
     $obj->setStartBalance(20.0);
     $this->assertInternalType('float', $obj->getStartBalance());
     $this->assertSame(20.0, $obj->getStartBalance());
     $obj->setStartBalance('string');
     $this->assertSame(0.0, $obj->getStartBalance());
     $obj->setCreditDebit(Statement::CD_CREDIT);
     $this->assertSame(Statement::CD_CREDIT, $obj->getCreditDebit());
     $obj->setCreditDebit(Statement::CD_DEBIT);
     $this->assertSame(Statement::CD_DEBIT, $obj->getCreditDebit());
     $date = new \DateTime();
     $obj->setDate($date);
     $this->assertSame($date, $obj->getDate());
 }