user = $user; } /** * Moved here from account CRUD * * @param array $types * * @return int */ public function count(array $types):int { $count = $this->user->accounts()->accountTypeIn($types)->count(); return $count; } /** * Moved here from account CRUD. * * @param Account $account * @param Account $moveTo * * @return bool */ public function destroy(Account $account, Account $moveTo): bool { if (!is_null($moveTo->id)) { DB::table('transactions')->where('account_id', $account->id)->update(['account_id' => $moveTo->id]); } if (!is_null($account)) { $account->delete(); } return true; } /** * @param $accountId * * @return Account */ public function find(int $accountId): Account { $account = $this->user->accounts()->find($accountId); if (is_null($account)) { return new Account; } return $account; } /** * Returns the date of the very first transaction in this account. * * @param Account $account * * @return Carbon */ public function oldestJournalDate(Account $account): Carbon { $first = new Carbon; /** @var Transaction $first */ $date = $account->transactions() ->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') ->orderBy('transaction_journals.date', 'ASC') ->orderBy('transaction_journals.order', 'DESC') ->orderBy('transaction_journals.id', 'ASC') ->first(['transaction_journals.date']); if (!is_null($date)) { $first = new Carbon($date->date); } return $first; } }