incomes = new Collection; } /** * @param TransactionJournal $entry */ public function addOrCreateIncome(TransactionJournal $entry) { $accountId = $entry->account_id; if (!$this->incomes->has($accountId)) { $newObject = new stdClass; $newObject->amount = floatval($entry->amount); $newObject->name = $entry->name; $newObject->count = 1; $newObject->id = $accountId; $this->incomes->put($accountId, $newObject); } else { $existing = $this->incomes->get($accountId); $existing->amount += floatval($entry->amount); $existing->count++; $this->incomes->put($accountId, $existing); } } /** * @param $add */ public function addToTotal($add) { $this->total += floatval($add); } /** * @return Collection */ public function getIncomes() { $this->incomes->sortByDesc( function (stdClass $object) { return $object->amount; } ); return $this->incomes; } /** * @return float */ public function getTotal() { return $this->total; } }