/**
  * Get amount if the account is balanced
  *
  * @return Currency
  * @throw AccountsException
  */
 public function getAmount()
 {
     return Match::create(Option::create($this->entries->checkBalance(), false))->Monad_Option_Some(function () {
         $tot = 0;
         foreach ($this->entries as $entry) {
             $tot += $entry->getAmount()->get();
         }
         //use last entry to grab currency code from
         /** @noinspection PhpUndefinedVariableInspection */
         return CFactory::create($entry->getAmount()->getCode()->get())->set($tot / 2);
     })->Monad_Option_None(function () {
         throw new AccountsException('No amount for unbalanced transaction');
     })->value();
 }
示例#2
0
 public function testCheckBalanceWillReturnFalseIfEntriesAreNotBalanced()
 {
     $sut1 = new Entries(array($this->getEntry('7789', 12.34, 'dr'), $this->getEntry('3456', 6.17, 'cr')));
     $this->assertFalse($sut1->checkBalance());
 }