Пример #1
0
 /**
  * Get a Link entry's nominal id using its name
  *
  * @param StringType $name
  * @return Nominal|null
  */
 public function getLinkId(StringType $name)
 {
     return Match::create(Option::create($this->getLink($name)))->Monad_Option_Some(function ($val) {
         return $val->value()->getId();
     })->Monad_Option_None(function () {
         return null;
     })->value();
 }
 /**
  * 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();
 }