Skip to content

Firefly III: a personal finances manager

Fix chart for account/all overview.

James Cole4a99399952ff
diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php
index c1c89ef897..7ad7b4a0d1 100644
--- a/app/Http/Controllers/AccountController.php
+++ b/app/Http/Controllers/AccountController.php
@@ -22,6 +22,7 @@ use FireflyIII\Http\Requests\AccountFormRequest;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction;
+use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Account\AccountRepositoryInterface as ARI;
use FireflyIII\Repositories\Account\AccountTaskerInterface;
use FireflyIII\Support\CacheProperties;
@@ -240,7 +241,7 @@ class AccountController extends Controller
*
* @return View
*/
- public function showAll(Account $account)
+ public function showAll(AccountRepositoryInterface $repository, Account $account)
{
$subTitle = sprintf('%s (%s)', $account->name, strtolower(trans('firefly.everything')));
$page = intval(Input::get('page')) === 0 ? 1 : intval(Input::get('page'));
@@ -252,7 +253,11 @@ class AccountController extends Controller
$journals = $collector->getPaginatedJournals();
$journals->setPath('accounts/show/' . $account->id . '/all');
- return view('accounts.show_with_date', compact('category', 'date', 'account', 'journals', 'subTitle', 'carbon'));
+ // get oldest and newest journal for account:
+ $start = $repository->oldestJournalDate($account);
+ $end = $repository->newestJournalDate($account);
+
+ return view('accounts.show_with_date', compact('account', 'journals', 'subTitle', 'start', 'end'));
}
/**
diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php
index b7421c1e6b..e9c21082e2 100644
--- a/app/Repositories/Account/AccountRepository.php
+++ b/app/Repositories/Account/AccountRepository.php
@@ -261,23 +261,44 @@ class AccountRepository implements AccountRepositoryInterface
}
/**
- * Returns the date of the very first transaction in this account.
+ * Returns the date of the very last transaction in this account.
*
* @param Account $account
*
* @return Carbon
*/
- public function oldestJournalDate(Account $account): Carbon
+ public function newestJournalDate(Account $account): Carbon
{
- $first = new Carbon;
-
- /** @var Transaction $first */
+ $last = new Carbon;
$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')
+ ->orderBy('transaction_journals.date', 'DESC')
+ ->orderBy('transaction_journals.order', 'ASC')
+ ->orderBy('transaction_journals.id', 'DESC')
->first(['transaction_journals.date']);
+ if (!is_null($date)) {
+ $last = new Carbon($date->date);
+ }
+
+ return $last;
+ }
+
+ /**
+ * 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;
+ $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);
}
@@ -602,5 +623,4 @@ class AccountRepository implements AccountRepositoryInterface
return false;
}
-
}
diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.php
index ab7b1f5dc9..d306e433de 100644
--- a/app/Repositories/Account/AccountRepositoryInterface.php
+++ b/app/Repositories/Account/AccountRepositoryInterface.php
@@ -96,6 +96,15 @@ interface AccountRepositoryInterface
*/
public function getActiveAccountsByType(array $types): Collection;
+ /**
+ * Returns the date of the very last transaction in this account.
+ *
+ * @param Account $account
+ *
+ * @return Carbon
+ */
+ public function newestJournalDate(Account $account): Carbon;
+
/**
* Returns the date of the very first transaction in this account.
*