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