diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index c4401c21dd..42fabc7488 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -226,7 +226,7 @@ class AccountController extends Controller // grouped other months thing: // oldest transaction in account: - $start = $repository->firstUseDate($account); + $start = $repository->oldestJournalDate($account); $range = Preferences::get('viewRange', '1M')->data; $start = Navigation::startOfPeriod($start, $range); $end = Navigation::endOfX(new Carbon, $range); diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index bce6c9650b..9c39d9c373 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -85,30 +85,6 @@ class AccountRepository implements AccountRepositoryInterface return true; } - /** - * Returns the date of the first time the Account has been used, or today if it has never been used. - * - * @param Account $account - * - * @return Carbon - */ - public function firstUseDate(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; - } /** * Returns the transaction from a journal that is related to a given account. Since a journal generally only contains @@ -340,19 +316,20 @@ class AccountRepository implements AccountRepositoryInterface */ public function oldestJournalDate(Account $account): Carbon { - /** @var TransactionJournal $journal */ - $journal = TransactionJournal:: - leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') - ->where('transactions.account_id', $account->id) - ->orderBy('transaction_journals.date', 'ASC') - ->orderBy('transaction_journals.order', 'DESC') - ->orderBy('transaction_journals.id', 'ÅSC') - ->first(['transaction_journals.*']); - if (is_null($journal)) { - return new Carbon('1900-01-01'); + $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 $journal->date; + return $first; } /** diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.php index c02789239a..d4b6c55212 100644 --- a/app/Repositories/Account/AccountRepositoryInterface.php +++ b/app/Repositories/Account/AccountRepositoryInterface.php @@ -47,15 +47,6 @@ interface AccountRepositoryInterface */ public function destroy(Account $account, Account $moveTo): bool; - /** - * Returns the date of the first time the Account has been used, or today if it has never been used. - * - * @param Account $account - * - * @return Carbon - */ - public function firstUseDate(Account $account): Carbon; - /** * Returns the transaction from a journal that is related to a given account. Since a journal generally only contains * two transactions, this will return one of the two. This method fails horribly when the journal has more than two transactions,