mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
First code for #595. Charts are still broken.
This commit is contained in:
parent
4f50689d0e
commit
de9ef20014
@ -227,103 +227,171 @@ class AccountController extends Controller
|
||||
return view('accounts.index', compact('what', 'subTitleIcon', 'subTitle', 'accounts'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param JournalCollectorInterface $collector
|
||||
* @param Account $account
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
|
||||
*/
|
||||
public function show(Request $request, JournalCollectorInterface $collector, Account $account)
|
||||
{
|
||||
if ($account->accountType->type === AccountType::INITIAL_BALANCE) {
|
||||
return $this->redirectToOriginalAccount($account);
|
||||
}
|
||||
// show journals from current period only:
|
||||
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $account->accountType->type);
|
||||
$subTitle = $account->name;
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$start = session('start', Navigation::startOfPeriod(new Carbon, $range));
|
||||
$end = session('end', Navigation::endOfPeriod(new Carbon, $range));
|
||||
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
|
||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||
$chartUri = route('chart.account.single', [$account->id]);
|
||||
$accountType = $account->accountType->type;
|
||||
|
||||
// grab those journals:
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->setLimit($pageSize)->setPage($page);
|
||||
$journals = $collector->getPaginatedJournals();
|
||||
$journals->setPath('accounts/show/' . $account->id);
|
||||
|
||||
// generate entries for each period (and cache those)
|
||||
$entries = $this->periodEntries($account);
|
||||
|
||||
return view('accounts.show', compact('account', 'accountType', 'entries', 'subTitleIcon', 'journals', 'subTitle', 'start', 'end', 'chartUri'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param Account $account
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function showAll(Request $request, AccountRepositoryInterface $repository, Account $account)
|
||||
{
|
||||
$subTitle = sprintf('%s (%s)', $account->name, strtolower(trans('firefly.everything')));
|
||||
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
|
||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||
$chartUri = route('chart.account.all', [$account->id]);
|
||||
|
||||
// replace with journal collector:
|
||||
/** @var JournalCollectorInterface $collector */
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setUser(auth()->user());
|
||||
$collector->setAccounts(new Collection([$account]))->setLimit($pageSize)->setPage($page);
|
||||
$journals = $collector->getPaginatedJournals();
|
||||
$journals->setPath('accounts/show/' . $account->id . '/all');
|
||||
|
||||
// get oldest and newest journal for account:
|
||||
$start = $repository->oldestJournalDate($account);
|
||||
$end = $repository->newestJournalDate($account);
|
||||
|
||||
// same call, except "entries".
|
||||
return view('accounts.show', compact('account', 'subTitleIcon', 'journals', 'subTitle', 'start', 'end', 'chartUri'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param Account $account
|
||||
* @param string $date
|
||||
*
|
||||
* @return View
|
||||
* @param string $moment
|
||||
*/
|
||||
public function showByDate(Request $request, Account $account, string $date)
|
||||
public function show(Request $request, Account $account, string $moment = '')
|
||||
{
|
||||
$carbon = new Carbon($date);
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$start = Navigation::startOfPeriod($carbon, $range);
|
||||
$end = Navigation::endOfPeriod($carbon, $range);
|
||||
$subTitle = $account->name . ' (' . Navigation::periodShow($start, $range) . ')';
|
||||
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
|
||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||
$chartUri = route('chart.account.period', [$account->id, $carbon->format('Y-m-d')]);
|
||||
if ($account->accountType->type === AccountType::INITIAL_BALANCE) {
|
||||
return $this->redirectToOriginalAccount($account);
|
||||
}
|
||||
$subTitle = $account->name;
|
||||
$range = Preferences::get('viewRange', '1M')->data;
|
||||
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $account->accountType->type);
|
||||
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
|
||||
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||
$chartUri = route('chart.account.single', [$account->id]);
|
||||
$start = null;
|
||||
$end = null;
|
||||
$periods = new Collection;
|
||||
|
||||
// prep for "all" view.
|
||||
if ($moment === 'all') {
|
||||
$subTitle = $account->name . ' (' . strtolower(strval(trans('firefly.everything'))) . ')';
|
||||
$chartUri = route('chart.account.all', [$account->id]);
|
||||
}
|
||||
|
||||
// prep for "specific date" view.
|
||||
if (strlen($moment) > 0 && $moment !== 'all') {
|
||||
$start = new Carbon($moment);
|
||||
$end = Navigation::endOfPeriod($start, $range);
|
||||
$subTitle = $account->name . ' (' . strval(trans('firefly.from_to_breadcrumb', ['start' => 'x', 'end' => 'x'])) . ')';
|
||||
$chartUri = route('chart.account.period', [$account->id, $start->format('Y-m-d')]);
|
||||
$periods = $this->periodEntries($account);
|
||||
}
|
||||
|
||||
// prep for current period
|
||||
if (strlen($moment) === 0) {
|
||||
$start = session('start', Navigation::startOfPeriod(new Carbon, $range));
|
||||
$end = session('end', Navigation::endOfPeriod(new Carbon, $range));
|
||||
$periods = $this->periodEntries($account);
|
||||
}
|
||||
|
||||
$accountType = $account->accountType->type;
|
||||
$count = 0;
|
||||
// grab journals, but be prepared to jump a period back to get the right ones:
|
||||
while ($count === 0) {
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
Log::debug('Count is zero, search for journals.');
|
||||
$collector->setAccounts(new Collection([$account]))->setLimit($pageSize)->setPage($page);
|
||||
if (!is_null($start)) {
|
||||
$collector->setRange($start, $end);
|
||||
}
|
||||
$journals = $collector->getPaginatedJournals();
|
||||
$journals->setPath('accounts/show/' . $account->id);
|
||||
$count = $journals->getCollection()->count();
|
||||
if ($count === 0) {
|
||||
$start->subDay();
|
||||
$start = Navigation::startOfPeriod($start, $range);
|
||||
$end = Navigation::endOfPeriod($start, $range);
|
||||
Log::debug(sprintf('Count is still zero, go back in time to "%s" and "%s"!', $start->format('Y-m-d'), $end->format('Y-m-d')));
|
||||
}
|
||||
}
|
||||
|
||||
// replace with journal collector:
|
||||
/** @var JournalCollectorInterface $collector */
|
||||
$collector = app(JournalCollectorInterface::class);
|
||||
$collector->setAccounts(new Collection([$account]))->setRange($start, $end)->setLimit($pageSize)->setPage($page);
|
||||
$journals = $collector->getPaginatedJournals();
|
||||
$journals->setPath('accounts/show/' . $account->id . '/' . $date);
|
||||
|
||||
// generate entries for each period (and cache those)
|
||||
$entries = $this->periodEntries($account);
|
||||
|
||||
// same call, except "entries".
|
||||
return view('accounts.show', compact('account', 'accountType', 'entries', 'subTitleIcon', 'journals', 'subTitle', 'start', 'end', 'chartUri'));
|
||||
return view('accounts.show', compact('account', 'accountType', 'periods', 'subTitleIcon', 'journals', 'subTitle', 'start', 'end', 'chartUri'));
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @param Request $request
|
||||
// * @param JournalCollectorInterface $collector
|
||||
// * @param Account $account
|
||||
// *
|
||||
// * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View
|
||||
// */
|
||||
// public function show(Request $request, JournalCollectorInterface $collector, Account $account)
|
||||
// {
|
||||
// if ($account->accountType->type === AccountType::INITIAL_BALANCE) {
|
||||
// return $this->redirectToOriginalAccount($account);
|
||||
// }
|
||||
// // show journals from current period only:
|
||||
// $subTitleIcon = config('firefly.subIconsByIdentifier.' . $account->accountType->type);
|
||||
// $subTitle = $account->name;
|
||||
// $range = Preferences::get('viewRange', '1M')->data;
|
||||
// $start = session('start', Navigation::startOfPeriod(new Carbon, $range));
|
||||
// $end = session('end', Navigation::endOfPeriod(new Carbon, $range));
|
||||
// $page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
|
||||
// $pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||
// $chartUri = route('chart.account.single', [$account->id]);
|
||||
// $accountType = $account->accountType->type;
|
||||
//
|
||||
// // grab those journals:
|
||||
// $collector->setAccounts(new Collection([$account]))->setRange($start, $end)->setLimit($pageSize)->setPage($page);
|
||||
// $journals = $collector->getPaginatedJournals();
|
||||
// $journals->setPath('accounts/show/' . $account->id);
|
||||
//
|
||||
// // generate entries for each period (and cache those)
|
||||
// $entries = $this->periodEntries($account);
|
||||
//
|
||||
// return view('accounts.show', compact('account', 'accountType', 'entries', 'subTitleIcon', 'journals', 'subTitle', 'start', 'end', 'chartUri'));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @param Request $request
|
||||
// * @param AccountRepositoryInterface $repository
|
||||
// * @param Account $account
|
||||
// *
|
||||
// * @return View
|
||||
// */
|
||||
// public function showAll(Request $request, AccountRepositoryInterface $repository, Account $account)
|
||||
// {
|
||||
// $subTitle = sprintf('%s (%s)', $account->name, strtolower(trans('firefly.everything')));
|
||||
// $page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
|
||||
// $pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||
// $chartUri = route('chart.account.all', [$account->id]);
|
||||
//
|
||||
// // replace with journal collector:
|
||||
// /** @var JournalCollectorInterface $collector */
|
||||
// $collector = app(JournalCollectorInterface::class);
|
||||
// $collector->setUser(auth()->user());
|
||||
// $collector->setAccounts(new Collection([$account]))->setLimit($pageSize)->setPage($page);
|
||||
// $journals = $collector->getPaginatedJournals();
|
||||
// $journals->setPath('accounts/show/' . $account->id . '/all');
|
||||
//
|
||||
// // get oldest and newest journal for account:
|
||||
// $start = $repository->oldestJournalDate($account);
|
||||
// $end = $repository->newestJournalDate($account);
|
||||
//
|
||||
// // same call, except "entries".
|
||||
// return view('accounts.show', compact('account', 'subTitleIcon', 'journals', 'subTitle', 'start', 'end', 'chartUri'));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @param Request $request
|
||||
// * @param Account $account
|
||||
// * @param string $date
|
||||
// *
|
||||
// * @return View
|
||||
// */
|
||||
// public function showByDate(Request $request, Account $account, string $date)
|
||||
// {
|
||||
// $carbon = new Carbon($date);
|
||||
// $range = Preferences::get('viewRange', '1M')->data;
|
||||
// $start = Navigation::startOfPeriod($carbon, $range);
|
||||
// $end = Navigation::endOfPeriod($carbon, $range);
|
||||
// $subTitle = $account->name . ' (' . Navigation::periodShow($start, $range) . ')';
|
||||
// $page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
|
||||
// $pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
|
||||
// $chartUri = route('chart.account.period', [$account->id, $carbon->format('Y-m-d')]);
|
||||
// $accountType = $account->accountType->type;
|
||||
//
|
||||
// // replace with journal collector:
|
||||
// /** @var JournalCollectorInterface $collector */
|
||||
// $collector = app(JournalCollectorInterface::class);
|
||||
// $collector->setAccounts(new Collection([$account]))->setRange($start, $end)->setLimit($pageSize)->setPage($page);
|
||||
// $journals = $collector->getPaginatedJournals();
|
||||
// $journals->setPath('accounts/show/' . $account->id . '/' . $date);
|
||||
//
|
||||
// // generate entries for each period (and cache those)
|
||||
// $entries = $this->periodEntries($account);
|
||||
//
|
||||
// // same call, except "entries".
|
||||
// return view('accounts.show', compact('account', 'accountType', 'entries', 'subTitleIcon', 'journals', 'subTitle', 'start', 'end', 'chartUri'));
|
||||
// }
|
||||
|
||||
/**
|
||||
* @param AccountFormRequest $request
|
||||
* @param AccountRepositoryInterface $repository
|
||||
|
@ -76,30 +76,26 @@ Breadcrumbs::register(
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'accounts.show.date', function (BreadCrumbGenerator $breadcrumbs, Account $account, Carbon $start, Carbon $end) {
|
||||
'accounts.show.date', function (BreadCrumbGenerator $breadcrumbs, Account $account, Carbon $start = null, Carbon $end = null) {
|
||||
|
||||
$startString = $start->formatLocalized(strval(trans('config.month_and_day')));
|
||||
$endString = $end->formatLocalized(strval(trans('config.month_and_day')));
|
||||
$title = sprintf('%s (%s)', $account->name, trans('firefly.from_to', ['start' => $startString, 'end' => $endString]));
|
||||
$title = '';
|
||||
$route = '';
|
||||
if (!is_null($start) && !is_null($end)) {
|
||||
$startString = $start->formatLocalized(strval(trans('config.month_and_day')));
|
||||
$endString = $end->formatLocalized(strval(trans('config.month_and_day')));
|
||||
$title = sprintf('%s (%s)', $account->name, trans('firefly.from_to_breadcrumb', ['start' => $startString, 'end' => $endString]));
|
||||
$route = route('accounts.show.date', [$account->id, $start->format('Y-m-d')]);
|
||||
}
|
||||
if (is_null($start) && is_null($end)) {
|
||||
$title = $title = $account->name . ' (' . strtolower(strval(trans('firefly.everything'))) . ')';
|
||||
$route = route('accounts.show.date', [$account->id, 'all']);
|
||||
}
|
||||
|
||||
$breadcrumbs->parent('accounts.show', $account);
|
||||
$breadcrumbs->push($title, route('accounts.show.date', [$account->id, $start->format('Y-m-d')]));
|
||||
$breadcrumbs->push($title, $route);
|
||||
}
|
||||
);
|
||||
|
||||
Breadcrumbs::register(
|
||||
'accounts.show.all', function (BreadCrumbGenerator $breadcrumbs, Account $account, Carbon $start, Carbon $end) {
|
||||
|
||||
$startString = $start->formatLocalized(strval(trans('config.month_and_day')));
|
||||
$endString = $end->formatLocalized(strval(trans('config.month_and_day')));
|
||||
$title = sprintf('%s (%s)', $account->name, trans('firefly.from_to', ['start' => $startString, 'end' => $endString]));
|
||||
|
||||
$breadcrumbs->parent('accounts.show', $account);
|
||||
$breadcrumbs->push($title, route('accounts.show.all', [$account->id, $start->format('Y-m-d')]));
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Breadcrumbs::register(
|
||||
'accounts.delete', function (BreadCrumbGenerator $breadcrumbs, Account $account) {
|
||||
$breadcrumbs->parent('accounts.show', $account);
|
||||
|
@ -558,6 +558,7 @@ return [
|
||||
'select_more_than_one_budget' => 'Please select more than one budget',
|
||||
'select_more_than_one_tag' => 'Please select more than one tag',
|
||||
'from_to' => 'From :start to :end',
|
||||
'from_to_breadcrumb' => 'from :start to :end',
|
||||
|
||||
// categories:
|
||||
'new_category' => 'New category',
|
||||
|
@ -10,8 +10,12 @@
|
||||
<div class="box">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">{{ account.name }}
|
||||
({{ trans('firefly.from_to', {start: start.formatLocalized(monthAndDayFormat), end: end.formatLocalized(monthAndDayFormat)}) }})</h3>
|
||||
|
||||
{% if start and end %}
|
||||
({{ trans('firefly.from_to_breadcrumb', {start: start.formatLocalized(monthAndDayFormat), end: end.formatLocalized(monthAndDayFormat)}) }})
|
||||
{% else %}
|
||||
({{ trans('firefly.everything')|lower }})
|
||||
{% endif %}
|
||||
</h3>
|
||||
<!-- ACTIONS MENU -->
|
||||
<div class="box-tools pull-right">
|
||||
<div class="btn-group">
|
||||
@ -67,26 +71,26 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% if entries %}
|
||||
<div class="row">
|
||||
<div class="col-lg-offset-10 col-lg-2 col-md-offset-10 col-md-2 col-sm-12 col-xs-12">
|
||||
<p class="small text-center"><a href="{{ route('accounts.show.all',[account.id]) }}">{{ 'showEverything'|_ }}</a></p>
|
||||
{% if periods.count > 0 %}
|
||||
<div class="row">
|
||||
<div class="col-lg-offset-10 col-lg-2 col-md-offset-10 col-md-2 col-sm-12 col-xs-12">
|
||||
<p class="small text-center"><a href="{{ route('accounts.show.date',[account.id, 'all']) }}">{{ 'showEverything'|_ }}</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
<div class="row">
|
||||
<div class="{% if entries %}col-lg-10 col-md-10 col-sm-12{% else %}col-lg-12 col-md-12 col-sm-12{% endif %}">
|
||||
<div class="{% if periods.count > 0 %}col-lg-10 col-md-10 col-sm-12{% else %}col-lg-12 col-md-12 col-sm-12{% endif %}">
|
||||
<div class="box">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">{{ 'transactions'|_ }}</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
{% include 'list.journals-tasker' with {sorting:true, hideBills:true, hideBudgets: true, hideCategories: true} %}
|
||||
{% if entries %}
|
||||
{% if periods.count > 0 %}
|
||||
<p>
|
||||
<i class="fa fa-calendar" aria-hidden="true"></i>
|
||||
<a href="{{ route('accounts.show.all', [account.id]) }}">
|
||||
<a href="{{ route('accounts.show.date', [account.id, 'all']) }}">
|
||||
{{ 'show_all_no_filter'|_ }}
|
||||
</a>
|
||||
</p>
|
||||
@ -101,10 +105,9 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% if entries %}
|
||||
{% if periods.count > 0 %}
|
||||
<div class="col-lg-2 col-md-2 col-sm-12 col-xs-12">
|
||||
|
||||
{% for entry in entries %}
|
||||
{% for entry in periods %}
|
||||
{% if (entry[2] != 0 or entry[3] != 0) or (accountType == 'Asset account') %}
|
||||
<div class="box {% if entry[4] == start %}box-solid box-primary{% endif %}">
|
||||
<div class="box-header with-border">
|
||||
@ -130,7 +133,7 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<p class="small text-center"><a href="{{ route('accounts.show.all',[account.id]) }}">{{ 'showEverything'|_ }}</a></p>
|
||||
<p class="small text-center"><a href="{{ route('accounts.show.date',[account.id, 'all']) }}">{{ 'showEverything'|_ }}</a></p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
@ -144,9 +147,15 @@
|
||||
var accountID = {{ account.id }};
|
||||
// uri's for charts:
|
||||
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')]) }}';
|
||||
{% if start and end %}
|
||||
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')]) }}';
|
||||
{% else %}
|
||||
var incomeCategoryUri = '{{ route('chart.account.income-category', [account.id, 'all', 'all']) }}';
|
||||
var expenseCategoryUri = '{{ route('chart.account.expense-category', [account.id, 'all', 'all']) }}';
|
||||
var expenseBudgetUri = '{{ route('chart.account.expense-budget', [account.id, 'all', 'all']) }}';
|
||||
{% endif %}
|
||||
|
||||
</script>
|
||||
|
||||
|
@ -88,8 +88,7 @@ Route::group(
|
||||
Route::get('delete/{account}', ['uses' => 'AccountController@delete', 'as' => 'delete']);
|
||||
|
||||
Route::get('show/{account}', ['uses' => 'AccountController@show', 'as' => 'show']);
|
||||
Route::get('show/{account}/all', ['uses' => 'AccountController@showAll', 'as' => 'show.all']);
|
||||
Route::get('show/{account}/{date}', ['uses' => 'AccountController@showByDate', 'as' => 'show.date']);
|
||||
Route::get('show/{account}/{date}', ['uses' => 'AccountController@show', 'as' => 'show.date']);
|
||||
|
||||
Route::post('store', ['uses' => 'AccountController@store', 'as' => 'store']);
|
||||
Route::post('update/{account}', ['uses' => 'AccountController@update', 'as' => 'update']);
|
||||
|
Loading…
Reference in New Issue
Block a user