mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-23 09:26:29 -06:00
Simplify frontpage.
This commit is contained in:
parent
dfa60ec703
commit
8df6356abf
@ -63,8 +63,8 @@ class HomeController extends Controller
|
||||
*
|
||||
* @param Request $request
|
||||
*
|
||||
* @throws Exception
|
||||
* @return JsonResponse
|
||||
* @throws Exception
|
||||
*/
|
||||
public function dateRange(Request $request): JsonResponse
|
||||
{
|
||||
@ -105,8 +105,8 @@ class HomeController extends Controller
|
||||
*
|
||||
* @param AccountRepositoryInterface $repository
|
||||
*
|
||||
* @throws Exception
|
||||
* @return Factory|RedirectResponse|Redirector|View
|
||||
* @throws Exception
|
||||
*/
|
||||
public function index(AccountRepositoryInterface $repository)
|
||||
{
|
||||
@ -119,10 +119,7 @@ class HomeController extends Controller
|
||||
}
|
||||
$subTitle = (string) trans('firefly.welcome_back');
|
||||
$transactions = [];
|
||||
$frontPage = app('preferences')->get(
|
||||
'frontPageAccounts',
|
||||
$repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray()
|
||||
);
|
||||
$frontPage = app('preferences')->get('frontPageAccounts', $repository->getAccountsByType([AccountType::ASSET])->pluck('id')->toArray());
|
||||
/** @var Carbon $start */
|
||||
$start = session('start', Carbon::now()->startOfMonth());
|
||||
/** @var Carbon $end */
|
||||
@ -134,14 +131,15 @@ class HomeController extends Controller
|
||||
/** @var BillRepositoryInterface $billRepository */
|
||||
$billRepository = app(BillRepositoryInterface::class);
|
||||
$billCount = $billRepository->getBills()->count();
|
||||
|
||||
|
||||
// collect groups for each transaction.
|
||||
foreach ($accounts as $account) {
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts(new Collection([$account]))
|
||||
->withAccountInformation()
|
||||
->setRange($start, $end)->setLimit(10)->setPage(1);
|
||||
$set = $collector->getGroups();
|
||||
$transactions[] = [$set, $account];
|
||||
$collector->setAccounts(new Collection([$account]))->withAccountInformation()->setRange($start, $end)->setLimit(10)->setPage(1);
|
||||
$set = $collector->getExtractedJournals();
|
||||
$transactions[] = ['transactions' => $set, 'account' => $account];
|
||||
}
|
||||
|
||||
/** @var User $user */
|
||||
|
@ -55,43 +55,6 @@ class TransactionGroupTwig extends AbstractExtension
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TwigFunction
|
||||
*/
|
||||
public function groupAmount(): TwigFunction
|
||||
{
|
||||
return new TwigFunction(
|
||||
'groupAmount',
|
||||
function (array $array): string {
|
||||
$sums = $array['sums'];
|
||||
$return = [];
|
||||
$first = reset($array['transactions']);
|
||||
$type = $first['transaction_type_type'] ?? TransactionType::WITHDRAWAL;
|
||||
$colored = true;
|
||||
if ($type === TransactionType::TRANSFER) {
|
||||
$colored = false;
|
||||
}
|
||||
|
||||
|
||||
/** @var array $sum */
|
||||
foreach ($sums as $sum) {
|
||||
$amount = $sum['amount'];
|
||||
|
||||
$sourceType = $first['source_account_type'] ?? 'invalid';
|
||||
$amount = $this->signAmount($amount, $type, $sourceType);
|
||||
|
||||
$return[] = app('amount')->formatFlat($sum['currency_symbol'], (int)$sum['currency_decimal_places'], $amount, $colored);
|
||||
}
|
||||
$result = implode(', ', $return);
|
||||
if ($type === TransactionType::TRANSFER) {
|
||||
$result = sprintf('<span class="text-info">%s</span>', $result);
|
||||
}
|
||||
return $result;
|
||||
},
|
||||
['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TwigFunction
|
||||
*/
|
||||
@ -222,12 +185,12 @@ class TransactionGroupTwig extends AbstractExtension
|
||||
$colored = true;
|
||||
|
||||
$sourceType = $array['source_account_type'] ?? 'invalid';
|
||||
$amount = $this->signAmount($amount, $type, $sourceType);
|
||||
$amount = $this->signAmount($amount, $type, $sourceType);
|
||||
|
||||
if ($type === TransactionType::TRANSFER) {
|
||||
$colored = false;
|
||||
}
|
||||
$result = app('amount')->formatFlat($array['foreign_currency_symbol'], (int)$array['foreign_currency_decimal_places'], $amount, $colored);
|
||||
$result = app('amount')->formatFlat($array['foreign_currency_symbol'], (int) $array['foreign_currency_decimal_places'], $amount, $colored);
|
||||
if ($type === TransactionType::TRANSFER) {
|
||||
$result = sprintf('<span class="text-info">%s</span>', $result);
|
||||
}
|
||||
@ -246,10 +209,10 @@ class TransactionGroupTwig extends AbstractExtension
|
||||
{
|
||||
$type = $journal->transactionType->type;
|
||||
/** @var Transaction $first */
|
||||
$first = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
$currency = $first->foreignCurrency;
|
||||
$amount = $first->foreign_amount ?? '0';
|
||||
$colored = true;
|
||||
$first = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
$currency = $first->foreignCurrency;
|
||||
$amount = $first->foreign_amount ?? '0';
|
||||
$colored = true;
|
||||
$sourceType = $first->account()->first()->accountType()->first()->type;
|
||||
|
||||
$amount = $this->signAmount($amount, $type, $sourceType);
|
||||
@ -257,7 +220,7 @@ class TransactionGroupTwig extends AbstractExtension
|
||||
if ($type === TransactionType::TRANSFER) {
|
||||
$colored = false;
|
||||
}
|
||||
$result = app('amount')->formatFlat($currency->symbol, (int)$currency->decimal_places, $amount, $colored);
|
||||
$result = app('amount')->formatFlat($currency->symbol, (int) $currency->decimal_places, $amount, $colored);
|
||||
if ($type === TransactionType::TRANSFER) {
|
||||
$result = sprintf('<span class="text-info">%s</span>', $result);
|
||||
}
|
||||
@ -274,17 +237,17 @@ class TransactionGroupTwig extends AbstractExtension
|
||||
*/
|
||||
private function normalJournalArrayAmount(array $array): string
|
||||
{
|
||||
$type = $array['transaction_type_type'] ?? TransactionType::WITHDRAWAL;
|
||||
$amount = $array['amount'] ?? '0';
|
||||
$colored = true;
|
||||
$type = $array['transaction_type_type'] ?? TransactionType::WITHDRAWAL;
|
||||
$amount = $array['amount'] ?? '0';
|
||||
$colored = true;
|
||||
$sourceType = $array['source_account_type'] ?? 'invalid';
|
||||
$amount = $this->signAmount($amount, $type, $sourceType);
|
||||
$amount = $this->signAmount($amount, $type, $sourceType);
|
||||
|
||||
if ($type === TransactionType::TRANSFER) {
|
||||
$colored = false;
|
||||
}
|
||||
|
||||
$result = app('amount')->formatFlat($array['currency_symbol'], (int)$array['currency_decimal_places'], $amount, $colored);
|
||||
$result = app('amount')->formatFlat($array['currency_symbol'], (int) $array['currency_decimal_places'], $amount, $colored);
|
||||
if ($type === TransactionType::TRANSFER) {
|
||||
$result = sprintf('<span class="text-info">%s</span>', $result);
|
||||
}
|
||||
@ -301,11 +264,11 @@ class TransactionGroupTwig extends AbstractExtension
|
||||
*/
|
||||
private function normalJournalObjectAmount(TransactionJournal $journal): string
|
||||
{
|
||||
$type = $journal->transactionType->type;
|
||||
$first = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
$currency = $journal->transactionCurrency;
|
||||
$amount = $first->amount ?? '0';
|
||||
$colored = true;
|
||||
$type = $journal->transactionType->type;
|
||||
$first = $journal->transactions()->where('amount', '<', 0)->first();
|
||||
$currency = $journal->transactionCurrency;
|
||||
$amount = $first->amount ?? '0';
|
||||
$colored = true;
|
||||
$sourceType = $first->account()->first()->accountType()->first()->type;
|
||||
|
||||
$amount = $this->signAmount($amount, $type, $sourceType);
|
||||
@ -313,7 +276,7 @@ class TransactionGroupTwig extends AbstractExtension
|
||||
if ($type === TransactionType::TRANSFER) {
|
||||
$colored = false;
|
||||
}
|
||||
$result = app('amount')->formatFlat($currency->symbol, (int)$currency->decimal_places, $amount, $colored);
|
||||
$result = app('amount')->formatFlat($currency->symbol, (int) $currency->decimal_places, $amount, $colored);
|
||||
if ($type === TransactionType::TRANSFER) {
|
||||
$result = sprintf('<span class="text-info">%s</span>', $result);
|
||||
}
|
||||
@ -333,7 +296,14 @@ class TransactionGroupTwig extends AbstractExtension
|
||||
return null !== $first->foreign_amount;
|
||||
}
|
||||
|
||||
private function signAmount( string $amount, string $transactionType, string $sourceType ): string {
|
||||
/**
|
||||
* @param string $amount
|
||||
* @param string $transactionType
|
||||
* @param string $sourceType
|
||||
* @return string
|
||||
*/
|
||||
private function signAmount(string $amount, string $transactionType, string $sourceType): string
|
||||
{
|
||||
|
||||
// withdrawals stay negative
|
||||
if ($transactionType !== TransactionType::WITHDRAWAL) {
|
||||
|
@ -54,23 +54,24 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4 col-md-6 col-sm-12">
|
||||
|
||||
{# TRANSACTIONS #}
|
||||
<div id="all_transactions">
|
||||
{% for data in transactions %}
|
||||
<div class="box">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title"><a href="{{ route('accounts.show', data[1].id) }}">{{ data[1].name }}</a></h3>
|
||||
<h3 class="box-title"><a href="{{ route('accounts.show', data.account.id) }}">{{ data.account.name }}</a></h3>
|
||||
</div>
|
||||
|
||||
{% if data[0].count > 0 %}
|
||||
{% if data.transactions|length > 0 %}
|
||||
<div class="box-body no-padding">
|
||||
{% include 'list.groups-tiny' with {'groups': data[0],'account': data[1]} %}
|
||||
{% include 'list.groups-tiny' with {'transactions': data.transactions,'account': data.account} %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="box-body">
|
||||
<p>
|
||||
<em>
|
||||
{{ trans('firefly.no_transactions_account', {name: data[1].name}) }}
|
||||
{{ trans('firefly.no_transactions_account', {name: data.account.name}) }}
|
||||
</em>
|
||||
</p>
|
||||
|
||||
@ -84,23 +85,22 @@
|
||||
{{ 'sidebar_frontpage_create'|_ }} <span class="caret"></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="{{ route('transactions.create', ['withdrawal']) }}?source={{ data[1].id }}">{{ 'create_new_withdrawal'|_ }}</a></li>
|
||||
<li><a href="{{ route('transactions.create', ['deposit']) }}?destination={{ data[1].id }}">{{ 'create_new_deposit'|_ }}</a></li>
|
||||
<li><a href="{{ route('transactions.create', ['transfer']) }}?source={{ data[1].id }}">{{ 'create_new_transfer'|_ }}</a></li>
|
||||
<li><a href="{{ route('transactions.create', ['withdrawal']) }}?source={{ data.account.id }}">{{ 'create_new_withdrawal'|_ }}</a></li>
|
||||
<li><a href="{{ route('transactions.create', ['deposit']) }}?destination={{ data.account.id }}">{{ 'create_new_deposit'|_ }}</a></li>
|
||||
<li><a href="{{ route('transactions.create', ['transfer']) }}?source={{ data.account.id }}">{{ 'create_new_transfer'|_ }}</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="btn-group">
|
||||
<a type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"
|
||||
href="{{ route('accounts.show', [data[1].id]) }}">{{ formatAmountByAccount(data[1], data[1]|balance, false) }}
|
||||
href="{{ route('accounts.show', [data.account.id]) }}">{{ formatAmountByAccount(data.account, data.account|balance, false) }}
|
||||
<span class="caret"></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="{{ route('accounts.show', [data[1].id]) }}">{{ 'show'|_ }}</a></li>
|
||||
<li><a href="{{ route('accounts.reconcile', [data[1].id]) }}">{{ 'reconcile'|_ }}</a></li>
|
||||
<li><a href="{{ route('accounts.edit', [data[1].id]) }}">{{ 'edit'|_ }}</a></li>
|
||||
<li><a href="{{ route('accounts.delete', [data[1].id]) }}">{{ 'delete'|_ }}</a></li>
|
||||
<li><a href="{{ route('accounts.show', [data.account.id]) }}">{{ 'show'|_ }}</a></li>
|
||||
<li><a href="{{ route('accounts.reconcile', [data.account.id]) }}">{{ 'reconcile'|_ }}</a></li>
|
||||
<li><a href="{{ route('accounts.edit', [data.account.id]) }}">{{ 'edit'|_ }}</a></li>
|
||||
<li><a href="{{ route('accounts.delete', [data.account.id]) }}">{{ 'delete'|_ }}</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,19 +1,55 @@
|
||||
<div class="list-group">
|
||||
{% for group in groups %}
|
||||
<a class="list-group-item" href="{{ route('transactions.show', [group.id]) }}">
|
||||
{% for transaction in group.transactions %}
|
||||
{{ transaction.description }}
|
||||
<span class="pull-right small">
|
||||
{{ journalArrayAmount(transaction) }}
|
||||
</span>
|
||||
<br/>
|
||||
{% endfor %}
|
||||
{% if group.count > 1 %}
|
||||
|
||||
<span class="pull-right small">
|
||||
{{ groupAmount(group) }}
|
||||
</span>
|
||||
{% for transaction in transactions %}
|
||||
<a class="list-group-item" href="{{ route('transactions.show', [transaction.transaction_group_id]) }}">
|
||||
{% if transaction.transaction_group_title %}
|
||||
{{ transaction.transaction_group_title }}:
|
||||
{% endif %}
|
||||
{{ transaction.description }}
|
||||
|
||||
<span class="pull-right small">
|
||||
{% if transaction.transaction_type_type == 'Deposit' %}
|
||||
{{ formatAmountBySymbol(transaction.amount*-1, transaction.currency_symbol, transaction.currency_decimal_places) }}
|
||||
{% if null != transaction.foreign_amount %}
|
||||
({{ formatAmountBySymbol(transaction.foreign_amount*-1, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
|
||||
{% endif %}
|
||||
{% elseif transaction.transaction_type_type == 'Transfer' %}
|
||||
<span class="text-info">
|
||||
{{ formatAmountBySymbol(transaction.amount*-1, transaction.currency_symbol, transaction.currency_decimal_places, false) }}
|
||||
{% if null != transaction.foreign_amount %}
|
||||
({{ formatAmountBySymbol(transaction.foreign_amount*-1, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places, false) }})
|
||||
{% endif %}
|
||||
</span>
|
||||
{% elseif transaction.transaction_type_type == 'Opening balance' %}
|
||||
{% if transaction.source_account_type == 'Initial balance account' %}
|
||||
{{ formatAmountBySymbol(transaction.amount*-1, transaction.currency_symbol, transaction.currency_decimal_places) }}
|
||||
{% if null != transaction.foreign_amount %}
|
||||
({{ formatAmountBySymbol(transaction.foreign_amount*-1, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{{ formatAmountBySymbol(transaction.amount, transaction.currency_symbol, transaction.currency_decimal_places) }}
|
||||
{% if null != transaction.foreign_amount %}
|
||||
({{ formatAmountBySymbol(transaction.foreign_amount, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% elseif transaction.transaction_type_type == 'Reconciliation' %}
|
||||
{% if transaction.source_account_type == 'Reconciliation account' %}
|
||||
{{ formatAmountBySymbol(transaction.amount*-1, transaction.currency_symbol, transaction.currency_decimal_places) }}
|
||||
{% if null != transaction.foreign_amount %}
|
||||
({{ formatAmountBySymbol(transaction.foreign_amount*-1, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{{ formatAmountBySymbol(transaction.amount, transaction.currency_symbol, transaction.currency_decimal_places) }}
|
||||
{% if null != transaction.foreign_amount %}
|
||||
({{ formatAmountBySymbol(transaction.foreign_amount, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{{ formatAmountBySymbol(transaction.amount, transaction.currency_symbol, transaction.currency_decimal_places) }}
|
||||
{% if null != transaction.foreign_amount %}
|
||||
({{ formatAmountBySymbol(transaction.foreign_amount, transaction.foreign_currency_symbol, transaction.foreign_currency_decimal_places) }})
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</span>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user