Skip to content

Firefly III: a personal finances manager

Fixed missing chart.

James Cole43f59a1135aa
diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php
index 8add2bdce6..9fc18dc35d 100644
--- a/app/Http/Controllers/AccountController.php
+++ b/app/Http/Controllers/AccountController.php
@@ -239,7 +239,7 @@ class AccountController extends Controller
$end = session('end', Navigation::endOfPeriod(new Carbon, $range));
$page = intval(Input::get('page')) === 0 ? 1 : intval(Input::get('page'));
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
-
+ $chartUri = route('chart.account.single', [$account->id]);
// grab those journals:
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->setLimit($pageSize)->setPage($page);
$journals = $collector->getPaginatedJournals();
@@ -248,7 +248,7 @@ class AccountController extends Controller
// generate entries for each period (and cache those)
$entries = $this->periodEntries($account);
- return view('accounts.show', compact('account', 'what', 'entries', 'subTitleIcon', 'journals', 'subTitle', 'start', 'end'));
+ return view('accounts.show', compact('account', 'what', 'entries', 'subTitleIcon', 'journals', 'subTitle', 'start', 'end', 'chartUri'));
}
/**
@@ -262,6 +262,7 @@ class AccountController extends Controller
$subTitle = sprintf('%s (%s)', $account->name, strtolower(trans('firefly.everything')));
$page = intval(Input::get('page')) === 0 ? 1 : intval(Input::get('page'));
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
+ $chartUri = route('chart.account.all', [$account->id]);
// replace with journal collector:
$collector = new JournalCollector(auth()->user());
@@ -273,7 +274,7 @@ class AccountController extends Controller
$start = $repository->oldestJournalDate($account);
$end = $repository->newestJournalDate($account);
- return view('accounts.show-by-date', compact('account', 'journals', 'subTitle', 'start', 'end'));
+ return view('accounts.show-by-date', compact('account', 'journals', 'subTitle', 'start', 'end','chartUri'));
}
/**
@@ -291,6 +292,7 @@ class AccountController extends Controller
$subTitle = $account->name . ' (' . Navigation::periodShow($start, $range) . ')';
$page = intval(Input::get('page')) === 0 ? 1 : intval(Input::get('page'));
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
+ $chartUri = route('chart.account.period', [$account->id, $carbon->format('Y-m-d')]);
// replace with journal collector:
$collector = new JournalCollector(auth()->user());
@@ -298,7 +300,7 @@ class AccountController extends Controller
$journals = $collector->getPaginatedJournals();
$journals->setPath('accounts/show/' . $account->id . '/' . $date);
- return view('accounts.show-by-date', compact('category', 'date', 'account', 'journals', 'subTitle', 'carbon', 'start', 'end'));
+ return view('accounts.show-by-date', compact('category', 'date', 'account', 'journals', 'subTitle', 'carbon', 'start', 'end','chartUri'));
}
/**
diff --git a/app/Http/Controllers/Chart/AccountController.php b/app/Http/Controllers/Chart/AccountController.php
index df4557a824..b8f1ad5a7d 100644
--- a/app/Http/Controllers/Chart/AccountController.php
+++ b/app/Http/Controllers/Chart/AccountController.php
@@ -55,6 +55,51 @@ class AccountController extends Controller
$this->generator = app(AccountChartGeneratorInterface::class);
}
+ /**
+ * @param Account $account
+ * @param string $date
+ *
+ * @return \Illuminate\Http\JsonResponse
+ * @throws FireflyException
+ */
+ public function all(Account $account)
+ {
+ $cache = new CacheProperties();
+ $cache->addProperty('account-all-chart');
+ $cache->addProperty($account->id);
+ if ($cache->has()) {
+ return Response::json($cache->get());
+ }
+
+ /** @var AccountRepositoryInterface $repository */
+ $repository = app(AccountRepositoryInterface::class);
+ $start = $repository->oldestJournalDate($account);
+ $end = new Carbon;
+
+ $format = (string)trans('config.month_and_day');
+ $range = Steam::balanceInRange($account, $start, $end);
+ $current = clone $start;
+ $previous = array_values($range)[0];
+ $labels = [];
+ $chartData = [];
+
+ while ($end >= $current) {
+ $theDate = $current->format('Y-m-d');
+ $balance = $range[$theDate] ?? $previous;
+
+ $labels[] = $current->formatLocalized($format);
+ $chartData[] = $balance;
+ $previous = $balance;
+ $current->addDay();
+ }
+
+
+ $data = $this->generator->single($account, $labels, $chartData);
+ $cache->store($data);
+
+ return Response::json($data);
+ }
+
/**
* Shows the balances for all the user's expense accounts.
*
@@ -242,6 +287,58 @@ class AccountController extends Controller
}
+ /**
+ * @param Account $account
+ * @param string $date
+ *
+ * @return \Illuminate\Http\JsonResponse
+ * @throws FireflyException
+ */
+ public function period(Account $account, string $date)
+ {
+ try {
+ $start = new Carbon($date);
+ } catch (Exception $e) {
+ Log::error($e->getMessage());
+ throw new FireflyException('"' . e($date) . '" does not seem to be a valid date. Should be in the format YYYY-MM-DD');
+ }
+ $range = Preferences::get('viewRange', '1M')->data;
+ $end = Navigation::endOfPeriod($start, $range);
+ // chart properties for cache:
+ $cache = new CacheProperties();
+ $cache->addProperty($start);
+ $cache->addProperty($end);
+ $cache->addProperty('frontpage');
+ $cache->addProperty('specificPeriod');
+ $cache->addProperty($account->id);
+ if ($cache->has()) {
+ return Response::json($cache->get());
+ }
+
+ $format = (string)trans('config.month_and_day');
+ $range = Steam::balanceInRange($account, $start, $end);
+ $current = clone $start;
+ $previous = array_values($range)[0];
+ $labels = [];
+ $chartData = [];
+
+ while ($end >= $current) {
+ $theDate = $current->format('Y-m-d');
+ $balance = $range[$theDate] ?? $previous;
+
+ $labels[] = $current->formatLocalized($format);
+ $chartData[] = $balance;
+ $previous = $balance;
+ $current->addDay();
+ }
+
+
+ $data = $this->generator->single($account, $labels, $chartData);
+ $cache->store($data);
+
+ return Response::json($data);
+ }
+
/**
* Shows the balances for a given set of dates and accounts.
*
@@ -353,58 +450,6 @@ class AccountController extends Controller
return Response::json($data);
}
- /**
- * @param Account $account
- * @param string $date
- *
- * @return \Illuminate\Http\JsonResponse
- * @throws FireflyException
- */
- public function period(Account $account, string $date)
- {
- try {
- $start = new Carbon($date);
- } catch (Exception $e) {
- Log::error($e->getMessage());
- throw new FireflyException('"' . e($date) . '" does not seem to be a valid date. Should be in the format YYYY-MM-DD');
- }
- $range = Preferences::get('viewRange', '1M')->data;
- $end = Navigation::endOfPeriod($start, $range);
- // chart properties for cache:
- $cache = new CacheProperties();
- $cache->addProperty($start);
- $cache->addProperty($end);
- $cache->addProperty('frontpage');
- $cache->addProperty('specificPeriod');
- $cache->addProperty($account->id);
- if ($cache->has()) {
- return Response::json($cache->get());
- }
-
- $format = (string)trans('config.month_and_day');
- $range = Steam::balanceInRange($account, $start, $end);
- $current = clone $start;
- $previous = array_values($range)[0];
- $labels = [];
- $chartData = [];
-
- while ($end >= $current) {
- $theDate = $current->format('Y-m-d');
- $balance = $range[$theDate] ?? $previous;
-
- $labels[] = $current->formatLocalized($format);
- $chartData[] = $balance;
- $previous = $balance;
- $current->addDay();
- }
-
-
- $data = $this->generator->single($account, $labels, $chartData);
- $cache->store($data);
-
- return Response::json($data);
- }
-
/**
* @param Collection $accounts
* @param Carbon $start
diff --git a/resources/views/accounts/show-by-date.twig b/resources/views/accounts/show-by-date.twig
index e342b62344..bc298b3be1 100644
--- a/resources/views/accounts/show-by-date.twig
+++ b/resources/views/accounts/show-by-date.twig
@@ -94,7 +94,7 @@
var dateString = "{{ date|escape }}";
// uri's for charts:
- var chartUri = '{{ route('chart.account.period', [account.id, date]) }}';
+ var chartUri = '{{ chartUri }}';
var incomeCategoryUri = '{{ route('chart.account.income-category', [account.id, start.format('Ymd'), end.format('Ymd')]) }}';
var expenseCategoryUri = '{{ route('chart.account.expense-category', [account.id, start.format('Ymd'), end.format('Ymd')]) }}';
var expenseBudgetUri = '{{ route('chart.account.expense-budget', [account.id, start.format('Ymd'), end.format('Ymd')]) }}';
diff --git a/resources/views/accounts/show.twig b/resources/views/accounts/show.twig
index ddc6034b04..6b37740fe5 100644
--- a/resources/views/accounts/show.twig
+++ b/resources/views/accounts/show.twig
@@ -123,7 +123,7 @@
<script type="text/javascript">
var accountID = {{ account.id }};
// uri's for charts:
- var chartUri = '{{ route('chart.account.single', [account.id]) }}';
+ var chartUri = '{{ chartUri }}';
var incomeCategoryUri = '{{ route('chart.account.income-category', [account.id, start.format('Ymd'), end.format('Ymd')]) }}';
var expenseCategoryUri = '{{ route('chart.account.expense-category', [account.id, start.format('Ymd'), end.format('Ymd')]) }}';
var expenseBudgetUri = '{{ route('chart.account.expense-budget', [account.id, start.format('Ymd'), end.format('Ymd')]) }}';
diff --git a/routes/web.php b/routes/web.php
index f6dbed2f93..69fe929318 100755
--- a/routes/web.php
+++ b/routes/web.php
@@ -228,7 +228,7 @@ Route::group(
Route::get('expense', ['uses' => 'AccountController@expenseAccounts', 'as' => 'expense']);
Route::get('revenue', ['uses' => 'AccountController@revenueAccounts', 'as' => 'revenue']);
Route::get('report/{accountList}/{start_date}/{end_date}', ['uses' => 'AccountController@report', 'as' => 'report']);
- Route::get('all/{account}', ['uses' => 'AccountController@period', 'as' => 'all']); // TODO
+ Route::get('all/{account}', ['uses' => 'AccountController@all', 'as' => 'all']);
Route::get('single/{account}', ['uses' => 'AccountController@single', 'as' => 'single']);
Route::get('period/{account}/{date}', ['uses' => 'AccountController@period', 'as' => 'period']);
diff --git a/tests/acceptance/Controllers/AccountControllerTest.php b/tests/acceptance/Controllers/AccountControllerTest.php
index f2ec4ffa53..3893001d40 100644
--- a/tests/acceptance/Controllers/AccountControllerTest.php
+++ b/tests/acceptance/Controllers/AccountControllerTest.php
@@ -147,12 +147,4 @@ class AccountControllerTest extends TestCase
'This test has not been implemented yet.'
);
}
-
- /**
- * Tears down the fixture, for example, closes a network connection.
- * This method is called after a test is executed.
- */
- protected function tearDown()
- {
- }
}