Ejemplo n.º 1
0
 /**
  * Sum the amounts of the entries matching the given account,
  * or null if no match is found.
  *
  * The given account must be comparable.
  *
  * @param ComparableInterface $account
  * @return MoneyInterface|null
  */
 public function sumByAccount(ComparableInterface $account)
 {
     /* @var $money MoneyInterface */
     $money = null;
     /* @var $entry EntryInterface */
     foreach ($this as $entry) {
         if ($account->equalTo($entry->getAccount()) && $entry->getAmount()) {
             $money = $money === null ? clone $entry->getAmount() : $money->add($entry->getAmount());
         }
     }
     return $money;
 }
Ejemplo n.º 2
0
 /**
  * Extract from current collection the first entry matching the given account,
  * or null if no match is found.
  *
  * The given account must be comparable.
  *
  * @param ComparableInterface $account
  * @return EntryInterface
  */
 public function getByAccount(ComparableInterface $account)
 {
     /* @var $entry EntryInterface */
     foreach ($this as $entry) {
         if ($account->equalTo($entry->getAccount())) {
             return $entry;
         }
     }
     return null;
 }