Fixed missing chart.

This commit is contained in:
James Cole 2016-12-11 11:15:19 +01:00
parent 5c02eaa66c
commit 43f59a1135
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
6 changed files with 106 additions and 67 deletions

View File

@ -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'));
}
/**

View File

@ -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

View File

@ -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')]) }}';

View File

@ -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')]) }}';

View File

@ -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']);

View File

@ -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()
{
}
}