This implements #377

This commit is contained in:
James Cole 2016-11-20 12:51:33 +01:00
parent 9340ca09e6
commit 350e0b08b1
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
9 changed files with 242 additions and 6 deletions

View File

@ -276,6 +276,26 @@ class AccountController extends Controller
return view('accounts.show', compact('account', 'what', 'entries', 'subTitleIcon', 'journals', 'subTitle'));
}
/**
* @param Account $account
*
* @return View
*/
public function showAll(Account $account)
{
$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);
// replace with journal collector:
$collector = new JournalCollector(auth()->user());
$collector->setAccounts(new Collection([$account]))->setLimit($pageSize)->setPage($page);
$journals = $collector->getPaginatedJournals();
$journals->setPath('accounts/show/' . $account->id . '/all');
return view('accounts.show_with_date', compact('category', 'date', 'account', 'journals', 'subTitle', 'carbon'));
}
/**
* @param Account $account
* @param string $date

View File

@ -14,12 +14,14 @@ declare(strict_types = 1);
namespace FireflyIII\Http\Controllers;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\JournalCollector;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalTaskerInterface;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Log;
use Navigation;
use Preferences;
use Response;
use View;
@ -56,15 +58,22 @@ class TransactionController extends Controller
*
* @return View
*/
public function index(Request $request, string $what)
public function index(Request $request, JournalRepositoryInterface $repository, string $what)
{
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
$subTitleIcon = config('firefly.transactionIconsByWhat.' . $what);
$types = config('firefly.transactionTypesByWhat.' . $what);
$subTitle = trans('firefly.title_' . $what);
$range = Preferences::get('viewRange', '1M')->data;
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
$collector = new JournalCollector(auth()->user());
// to make sure we only grab a subset, based on the current date (in session):
$start = session('start', Navigation::startOfPeriod(new Carbon, $range));
$end = session('end', Navigation::endOfPeriod(new Carbon, $range));
$collector = app(JournalCollectorInterface::class, [auth()->user()]);
$collector->setTypes($types)->setLimit($pageSize)->setPage($page)->setAllAssetAccounts();
$collector->setRange($start, $end);
// do not filter transfers if $what = transfer.
if (!in_array($what, ['transfer', 'transfers'])) {
@ -75,7 +84,93 @@ class TransactionController extends Controller
$journals = $collector->getPaginatedJournals();
$journals->setPath('transactions/' . $what);
return view('transactions.index', compact('subTitle', 'what', 'subTitleIcon', 'journals'));
unset($start, $end);
// then also show a list of periods where the user can click on, based on the
// user's range and the oldest journal the user has:
$first = $repository->first();
$blockStart = is_null($first->id) ? new Carbon : $first->date;
$blockStart = Navigation::startOfPeriod($blockStart, $range);
$blockEnd = Navigation::endOfX(new Carbon, $range);
$entries = new Collection;
while ($blockEnd >= $blockStart) {
Log::debug(sprintf('Now at blockEnd: %s', $blockEnd->format('Y-m-d')));
$blockEnd = Navigation::startOfPeriod($blockEnd, $range);
$dateStr = $blockEnd->format('Y-m-d');
$dateName = Navigation::periodShow($blockEnd, $range);
$entries->push([$dateStr, $dateName]);
$blockEnd = Navigation::subtractPeriod($blockEnd, $range, 1);
}
return view('transactions.index', compact('subTitle', 'what', 'subTitleIcon', 'journals', 'entries'));
}
/**
* @param Request $request
* @param string $what
*
* @return View
*/
public function indexAll(Request $request, string $what)
{
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
$subTitleIcon = config('firefly.transactionIconsByWhat.' . $what);
$types = config('firefly.transactionTypesByWhat.' . $what);
$subTitle = sprintf('%s (%s)', trans('firefly.title_' . $what), strtolower(trans('firefly.everything')));
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
$collector = app(JournalCollectorInterface::class, [auth()->user()]);
$collector->setTypes($types)->setLimit($pageSize)->setPage($page)->setAllAssetAccounts();
// do not filter transfers if $what = transfer.
if (!in_array($what, ['transfer', 'transfers'])) {
Log::debug('Also get opposing account info.');
$collector->withOpposingAccount();
}
$journals = $collector->getPaginatedJournals();
$journals->setPath('transactions/' . $what . '/all');
return view('transactions.index-all', compact('subTitle', 'what', 'subTitleIcon', 'journals'));
}
/**
* @param Request $request
* @param string $what
*
* @return View
*/
public function indexDate(Request $request, string $what, string $date)
{
$carbon = new Carbon($date);
$range = Preferences::get('viewRange', '1M')->data;
$start = Navigation::startOfPeriod($carbon, $range);
$end = Navigation::endOfPeriod($carbon, $range);
$pageSize = intval(Preferences::get('transactionPageSize', 50)->data);
$subTitleIcon = config('firefly.transactionIconsByWhat.' . $what);
$types = config('firefly.transactionTypesByWhat.' . $what);
$subTitle = trans('firefly.title_' . $what) . ' (' . Navigation::periodShow($carbon, $range) . ')';
$page = intval($request->get('page')) === 0 ? 1 : intval($request->get('page'));
Log::debug(sprintf('Transaction index by date will show between %s and %s', $start->format('Y-m-d'), $end->format('Y-m-d')));
$collector = app(JournalCollectorInterface::class, [auth()->user()]);
$collector->setTypes($types)->setLimit($pageSize)->setPage($page)->setAllAssetAccounts();
$collector->setRange($start, $end);
// do not filter transfers if $what = transfer.
if (!in_array($what, ['transfer', 'transfers'])) {
Log::debug('Also get opposing account info.');
$collector->withOpposingAccount();
}
$journals = $collector->getPaginatedJournals();
$journals->setPath('transactions/' . $what . '/' . $date);
return view('transactions.index-date', compact('subTitle', 'what', 'subTitleIcon', 'journals', 'carbon'));
}

View File

@ -83,6 +83,17 @@ Breadcrumbs::register(
}
);
Breadcrumbs::register(
'accounts.show.all', function (BreadCrumbGenerator $breadcrumbs, Account $account) {
$breadcrumbs->parent('accounts.show', $account);
$title = sprintf('%s (%s)', $account->name, strtolower(trans('firefly.everything')));
$breadcrumbs->push($title, route('accounts.show.all', [$account->id]));
}
);
Breadcrumbs::register(
'accounts.delete', function (BreadCrumbGenerator $breadcrumbs, Account $account) {
$breadcrumbs->parent('accounts.show', $account);
@ -573,6 +584,28 @@ Breadcrumbs::register(
$breadcrumbs->push(trans('breadcrumbs.' . $what . '_list'), route('transactions.index', [$what]));
}
);
Breadcrumbs::register(
'transactions.index.all', function (BreadCrumbGenerator $breadcrumbs, string $what) {
$breadcrumbs->parent('transactions.index', $what);
$title = sprintf('%s (%s)', trans('breadcrumbs.' . $what . '_list'), strtolower(trans('firefly.everything')));
$breadcrumbs->push($title, route('transactions.index.all', [$what]));
}
);
Breadcrumbs::register(
'transactions.index.date', function (BreadCrumbGenerator $breadcrumbs, string $what, Carbon $date) {
$breadcrumbs->parent('transactions.index', $what);
$range = Preferences::get('viewRange', '1M')->data;
$title = trans('breadcrumbs.' . $what . '_list') . ' (' . Navigation::periodShow($date, $range) . ')';
$breadcrumbs->push($title, route('transactions.index.date', [$what, $date->format('Y-m-d')]));
}
);
Breadcrumbs::register(
'transactions.create', function (BreadCrumbGenerator $breadcrumbs, string $what) {
$breadcrumbs->parent('transactions.index', $what);

View File

@ -86,6 +86,7 @@ return [
'field_supports_markdown' => 'This field supports <a href="https://en.support.wordpress.com/markdown-quick-reference/">Markdown</a>.',
'need_more_help' => 'If you need more help using Firefly III, please <a href="https://github.com/JC5/firefly-iii/issues">open a ticker on Github</a>.',
'nothing_to_display' => 'There are no transactions to show you',
'show_all_no_filter' => 'Show all transactions without grouping them by date.',
// repeat frequencies:
'repeat_freq_yearly' => 'yearly',

View File

@ -38,6 +38,12 @@
</div>
<div class="box-body">
{% include 'list.journals-tasker' with {sorting:true} %}
<p>
<i class="fa fa-calendar" aria-hidden="true"></i>
<a href="{{ route('accounts.show.all', [account.id]) }}">
{{ 'show_all_no_filter'|_ }}
</a>
</p>
</div>
</div>
</div>

View File

@ -0,0 +1,23 @@
{% extends "./layout/default" %}
{% block breadcrumbs %}
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, what) }}
{% endblock %}
{% block content %}
<div class="row">
<div class="col-lg-12 col-sm-12 col-md-12">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ subTitle }}</h3>
</div>
<div class="box-body">
{% include 'list.journals-tasker' %}
</div>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script type="text/javascript" src="js/ff/transactions/list.js"></script>
{% endblock %}

View File

@ -0,0 +1,23 @@
{% extends "./layout/default" %}
{% block breadcrumbs %}
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, what, carbon) }}
{% endblock %}
{% block content %}
<div class="row">
<div class="col-lg-12 col-sm-12 col-md-12">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ subTitle }}</h3>
</div>
<div class="box-body">
{% include 'list.journals-tasker' %}
</div>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script type="text/javascript" src="js/ff/transactions/list.js"></script>
{% endblock %}

View File

@ -6,16 +6,38 @@
{% block content %}
<div class="row">
<div class="col-lg-12 col-sm-12 col-md-12">
<div class="col-lg-10 col-md-10 col-sm-12">
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">{{ subTitle }}</h3>
</div>
<div class="box-body">
{% include 'list.journals-tasker' %}
<p>
<i class="fa fa-calendar" aria-hidden="true"></i>
<a href="{{ route('transactions.index.all', [what]) }}">
{{ 'show_all_no_filter'|_ }}
</a>
</p>
</div>
</div>
</div>
<div class="col-lg-2 col-md-2 col-sm-12 col-xs-12">
{% for entry in entries %}
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">
<a href="{{ route('transactions.index.date',[what,entry[0]]) }}">{{ entry[1] }}</a>
</h3>
</div>
<div class="box-body">
&nbsp;
</div>
</div>
{% endfor %}
</div>
</div>
{% endblock %}
{% block scripts %}

View File

@ -92,6 +92,7 @@ Route::group(
Route::get('/accounts/edit/{account}', ['uses' => 'AccountController@edit', 'as' => 'accounts.edit']);
Route::get('/accounts/delete/{account}', ['uses' => 'AccountController@delete', 'as' => 'accounts.delete']);
Route::get('/accounts/show/{account}', ['uses' => 'AccountController@show', 'as' => 'accounts.show']);
Route::get('/accounts/show/{account}/all', ['uses' => 'AccountController@showAll', 'as' => 'accounts.show.all']);
Route::get('/accounts/show/{account}/{date}', ['uses' => 'AccountController@showWithDate', 'as' => 'accounts.show.date']);
@ -455,10 +456,22 @@ Route::group(
* Transaction Controller
*/
// normal controller
// normal controller: index for session range
Route::get('/transactions/{what}', ['uses' => 'TransactionController@index', 'as' => 'transactions.index'])->where(
['what' => 'expenses|revenue|withdrawal|deposit|transfer|transfers']
);
// normal controller: index showing ALL:
Route::get('/transactions/{what}/all', ['uses' => 'TransactionController@indexAll', 'as' => 'transactions.index.all'])->where(
['what' => 'expenses|revenue|withdrawal|deposit|transfer|transfers']
);
// normal controller: index for specific date range:
Route::get('/transactions/{what}/{date}', ['uses' => 'TransactionController@indexDate', 'as' => 'transactions.index.date'])->where(
['what' => 'expenses|revenue|withdrawal|deposit|transfer|transfers']
);
Route::get('/transaction/show/{tj}', ['uses' => 'TransactionController@show', 'as' => 'transactions.show']);
Route::post('/transaction/reorder', ['uses' => 'TransactionController@reorder', 'as' => 'transactions.reorder']);