mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fix overview, skip chart for now.
This commit is contained in:
@@ -29,10 +29,12 @@ use FireflyIII\Http\Controllers\Controller;
|
|||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
|
use FireflyIII\Support\Facades\Steam;
|
||||||
use FireflyIII\Support\Http\Controllers\BasicDataSupport;
|
use FireflyIII\Support\Http\Controllers\BasicDataSupport;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,8 +101,8 @@ class IndexController extends Controller
|
|||||||
function (Account $account) use ($activities, $startBalances, $endBalances): void {
|
function (Account $account) use ($activities, $startBalances, $endBalances): void {
|
||||||
$currency = $this->repository->getAccountCurrency($account);
|
$currency = $this->repository->getAccountCurrency($account);
|
||||||
$account->lastActivityDate = $this->isInArrayDate($activities, $account->id);
|
$account->lastActivityDate = $this->isInArrayDate($activities, $account->id);
|
||||||
$account->startBalances = $this->getBalance($account, $currency, $startBalances);
|
$account->startBalances = Steam::filterAccountBalance($startBalances[$account->id] ?? [], $account, $this->convertToNative, $currency);
|
||||||
$account->endBalances = $this->getBalance($account, $currency, $endBalances);
|
$account->endBalances = Steam::filterAccountBalance($endBalances[$account->id] ?? [], $account, $this->convertToNative, $currency);
|
||||||
$account->differences = $this->subtract($account->startBalances, $account->endBalances);
|
$account->differences = $this->subtract($account->startBalances, $account->endBalances);
|
||||||
$account->interest = app('steam')->bcround($this->repository->getMetaValue($account, 'interest'), 4);
|
$account->interest = app('steam')->bcround($this->repository->getMetaValue($account, 'interest'), 4);
|
||||||
$account->interestPeriod = (string) trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period')));
|
$account->interestPeriod = (string) trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period')));
|
||||||
@@ -163,8 +165,8 @@ class IndexController extends Controller
|
|||||||
$interest = '' === $interest ? '0' : $interest;
|
$interest = '' === $interest ? '0' : $interest;
|
||||||
$currency = $this->repository->getAccountCurrency($account);
|
$currency = $this->repository->getAccountCurrency($account);
|
||||||
|
|
||||||
$account->startBalances = $this->getBalance($account, $currency, $startBalances);
|
$account->startBalances = Steam::filterAccountBalance($startBalances[$account->id] ?? [], $account, $this->convertToNative, $currency);
|
||||||
$account->endBalances = $this->getBalance($account, $currency, $endBalances);
|
$account->endBalances = Steam::filterAccountBalance($endBalances[$account->id] ?? [], $account, $this->convertToNative, $currency);
|
||||||
$account->differences = $this->subtract($account->startBalances, $account->endBalances);
|
$account->differences = $this->subtract($account->startBalances, $account->endBalances);
|
||||||
$account->lastActivityDate = $this->isInArrayDate($activities, $account->id);
|
$account->lastActivityDate = $this->isInArrayDate($activities, $account->id);
|
||||||
$account->interest = app('steam')->bcround($interest, 4);
|
$account->interest = app('steam')->bcround($interest, 4);
|
||||||
@@ -175,7 +177,7 @@ class IndexController extends Controller
|
|||||||
$account->location = $this->repository->getLocation($account);
|
$account->location = $this->repository->getLocation($account);
|
||||||
$account->liability_direction = $this->repository->getMetaValue($account, 'liability_direction');
|
$account->liability_direction = $this->repository->getMetaValue($account, 'liability_direction');
|
||||||
$account->current_debt = $this->repository->getMetaValue($account, 'current_debt') ?? '-';
|
$account->current_debt = $this->repository->getMetaValue($account, 'current_debt') ?? '-';
|
||||||
$account->currency = $currency;
|
$account->currency = $currency ?? $this->defaultCurrency;
|
||||||
$account->iban = implode(' ', str_split((string) $account->iban, 4));
|
$account->iban = implode(' ', str_split((string) $account->iban, 4));
|
||||||
|
|
||||||
|
|
||||||
@@ -194,22 +196,6 @@ class IndexController extends Controller
|
|||||||
return view('accounts.index', compact('objectType', 'inactiveCount', 'subTitleIcon', 'subTitle', 'page', 'accounts'));
|
return view('accounts.index', compact('objectType', 'inactiveCount', 'subTitleIcon', 'subTitle', 'page', 'accounts'));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getBalance(Account $account, ?TransactionCurrency $currency, array $balances): array
|
|
||||||
{
|
|
||||||
if (!array_key_exists($account->id, $balances)) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
$set = $balances[$account->id];
|
|
||||||
|
|
||||||
if ($this->convertToNative && $this->defaultCurrency->id === $currency?->id) {
|
|
||||||
unset($set['native_balance'], $set[$this->defaultCurrency->code]);
|
|
||||||
}
|
|
||||||
if ($this->convertToNative && null !== $currency && $this->defaultCurrency->id !== $currency->id) {
|
|
||||||
unset($set['balance']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $set;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function subtract(array $startBalances, array $endBalances)
|
private function subtract(array $startBalances, array $endBalances)
|
||||||
{
|
{
|
||||||
|
@@ -30,6 +30,7 @@ use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
|||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
|
use FireflyIII\Support\Facades\Amount;
|
||||||
use FireflyIII\Support\Facades\Steam;
|
use FireflyIII\Support\Facades\Steam;
|
||||||
use FireflyIII\Support\Http\Controllers\PeriodOverview;
|
use FireflyIII\Support\Http\Controllers\PeriodOverview;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
@@ -90,7 +91,7 @@ class ShowController extends Controller
|
|||||||
// @var Carbon $end
|
// @var Carbon $end
|
||||||
$end ??= session('end');
|
$end ??= session('end');
|
||||||
|
|
||||||
if ($end < $start) {
|
if ($end->lt($start)) {
|
||||||
[$start, $end] = [$end, $start];
|
[$start, $end] = [$end, $start];
|
||||||
}
|
}
|
||||||
$location = $this->repository->getLocation($account);
|
$location = $this->repository->getLocation($account);
|
||||||
@@ -99,7 +100,8 @@ class ShowController extends Controller
|
|||||||
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type));
|
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type));
|
||||||
$page = (int) $request->get('page');
|
$page = (int) $request->get('page');
|
||||||
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
|
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
|
||||||
$currency = $this->repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
|
$accountCurrency = $this->repository->getAccountCurrency($account);
|
||||||
|
$currency = $accountCurrency ?? Amount::getDefaultCurrency();
|
||||||
$fStart = $start->isoFormat($this->monthAndDayFormat);
|
$fStart = $start->isoFormat($this->monthAndDayFormat);
|
||||||
$fEnd = $end->isoFormat($this->monthAndDayFormat);
|
$fEnd = $end->isoFormat($this->monthAndDayFormat);
|
||||||
$subTitle = (string) trans('firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $fStart, 'end' => $fEnd]);
|
$subTitle = (string) trans('firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $fStart, 'end' => $fEnd]);
|
||||||
@@ -129,7 +131,7 @@ class ShowController extends Controller
|
|||||||
|
|
||||||
$groups->setPath(route('accounts.show', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]));
|
$groups->setPath(route('accounts.show', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]));
|
||||||
$showAll = false;
|
$showAll = false;
|
||||||
$balance = Steam::finalAccountBalance($account, $end)['balance'] ?? '0'; // TODO fix me
|
$balances = Steam::filterAccountBalance(Steam::finalAccountBalance($account, $end), $account, $this->convertToNative, $accountCurrency);
|
||||||
|
|
||||||
return view(
|
return view(
|
||||||
'accounts.show',
|
'accounts.show',
|
||||||
@@ -148,7 +150,7 @@ class ShowController extends Controller
|
|||||||
'end',
|
'end',
|
||||||
'chartUrl',
|
'chartUrl',
|
||||||
'location',
|
'location',
|
||||||
'balance'
|
'balances'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -175,7 +177,7 @@ class ShowController extends Controller
|
|||||||
$subTitleIcon = config('firefly.subIconsByIdentifier.'.$account->accountType->type);
|
$subTitleIcon = config('firefly.subIconsByIdentifier.'.$account->accountType->type);
|
||||||
$page = (int) $request->get('page');
|
$page = (int) $request->get('page');
|
||||||
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
|
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
|
||||||
$currency = $this->repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
|
$currency = $this->repository->getAccountCurrency($account) ?? Amount::getDefaultCurrency();
|
||||||
$subTitle = (string) trans('firefly.all_journals_for_account', ['name' => $account->name]);
|
$subTitle = (string) trans('firefly.all_journals_for_account', ['name' => $account->name]);
|
||||||
$periods = new Collection();
|
$periods = new Collection();
|
||||||
|
|
||||||
|
@@ -431,11 +431,10 @@ class AccountRepository implements AccountRepositoryInterface
|
|||||||
|
|
||||||
public function getUsedCurrencies(Account $account): Collection
|
public function getUsedCurrencies(Account $account): Collection
|
||||||
{
|
{
|
||||||
$info = $account->transactions()->get(['transaction_currency_id', 'foreign_currency_id'])->toArray();
|
$info = $account->transactions()->distinct()->groupBy('transaction_currency_id')->get(['transaction_currency_id'])->toArray();
|
||||||
$currencyIds = [];
|
$currencyIds = [];
|
||||||
foreach ($info as $entry) {
|
foreach ($info as $entry) {
|
||||||
$currencyIds[] = (int) $entry['transaction_currency_id'];
|
$currencyIds[] = (int) $entry['transaction_currency_id'];
|
||||||
$currencyIds[] = (int) $entry['foreign_currency_id'];
|
|
||||||
}
|
}
|
||||||
$currencyIds = array_unique($currencyIds);
|
$currencyIds = array_unique($currencyIds);
|
||||||
|
|
||||||
|
@@ -355,6 +355,62 @@ class Steam
|
|||||||
return array_merge($return, $others);
|
return array_merge($return, $others);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function filterAccountBalances(array $total, Account $account, bool $convertToNative, ?TransactionCurrency $currency = null): array {
|
||||||
|
$return = [];
|
||||||
|
foreach($total as $key => $value) {
|
||||||
|
$return[$key] = $this->filterAccountBalance($value, $account, $convertToNative, $currency);
|
||||||
|
}
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function filterAccountBalance(array $set, Account $account, bool $convertToNative, ?TransactionCurrency $currency = null): array {
|
||||||
|
if(0 === count($set)) {
|
||||||
|
Log::debug(sprintf('Return empty array for account #%d', $account->id));
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
$defaultCurrency = app('amount')->getDefaultCurrency();
|
||||||
|
if($convertToNative) {
|
||||||
|
if ($defaultCurrency->id === $currency?->id) {
|
||||||
|
Log::debug(sprintf('Unset "native_balance" and "%s" for account #%d', $defaultCurrency->code, $account->id));
|
||||||
|
unset($set['native_balance'], $set[$defaultCurrency->code]);
|
||||||
|
}
|
||||||
|
if (null !== $currency && $defaultCurrency->id !== $currency->id) {
|
||||||
|
Log::debug(sprintf('Unset balance for account #%d', $account->id));
|
||||||
|
unset($set['balance']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null === $currency) {
|
||||||
|
Log::debug(sprintf('TEMP DO NOT Drop defaultCurrency balance for account #%d', $account->id));
|
||||||
|
//unset($set[$this->defaultCurrency->code]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!$convertToNative) {
|
||||||
|
if (null === $currency) {
|
||||||
|
Log::debug(sprintf('Unset native_balance and make defaultCurrency balance the balance for account #%d', $account->id));
|
||||||
|
$set['balance'] = $set[$this->defaultCurrency->code] ?? '0';
|
||||||
|
unset($set['native_balance'], $set[$defaultCurrency->code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null !== $currency) {
|
||||||
|
Log::debug(sprintf('Unset native_balance + defaultCurrency + currencyCode balance for account #%d', $account->id));
|
||||||
|
unset($set['native_balance'], $set[$defaultCurrency->code], $set[$currency->code]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// put specific value first in array.
|
||||||
|
if (array_key_exists('native_balance', $set)) {
|
||||||
|
$set = ['native_balance' => $set['native_balance']] + $set;
|
||||||
|
}
|
||||||
|
if (array_key_exists('balance', $set)) {
|
||||||
|
$set = ['balance' => $set['balance']] + $set;
|
||||||
|
}
|
||||||
|
Log::debug(sprintf('Return #%d', $account->id), $set);
|
||||||
|
|
||||||
|
return $set;
|
||||||
|
}
|
||||||
|
|
||||||
private function groupAndSumTransactions(array $array, string $group, string $field): array
|
private function groupAndSumTransactions(array $array, string $group, string $field): array
|
||||||
{
|
{
|
||||||
$return = [];
|
$return = [];
|
||||||
|
@@ -11,9 +11,15 @@
|
|||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">
|
<h3 class="box-title">
|
||||||
|
{% if balances.balance %}
|
||||||
{{ trans('firefly.chart_account_in_period', {
|
{{ trans('firefly.chart_account_in_period', {
|
||||||
balance: formatAmountBySymbol(balance, currency.symbol, currency.decimal_places, true),
|
balance: formatAmountBySymbol(balances.balance, currency.symbol, currency.decimal_places, true),
|
||||||
name: account.name|escape, start: start.isoFormat(monthAndDayFormat), end: end.isoFormat(monthAndDayFormat) })|raw }}
|
name: account.name|escape, start: start.isoFormat(monthAndDayFormat), end: end.isoFormat(monthAndDayFormat) })|raw }}
|
||||||
|
{% elseif balances.native_balance %}
|
||||||
|
{{ trans('firefly.chart_account_in_period', {
|
||||||
|
balance: formatAmountBySymbol(balances.native_balance, defaultCurrency.symbol, defaultCurrency.decimal_places, true),
|
||||||
|
name: account.name|escape, start: start.isoFormat(monthAndDayFormat), end: end.isoFormat(monthAndDayFormat) })|raw }}
|
||||||
|
{% endif %}
|
||||||
</h3>
|
</h3>
|
||||||
<div class="box-tools pull-right">
|
<div class="box-tools pull-right">
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
@@ -140,7 +146,12 @@
|
|||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="box-header with-border">
|
<div class="box-header with-border">
|
||||||
<h3 class="box-title">{{ 'transactions'|_ }}
|
<h3 class="box-title">{{ 'transactions'|_ }}
|
||||||
({{ formatAmountBySymbol(balance, currency.symbol, currency.decimal_places, true)|raw }})</h3>
|
{% if balances.balance %}
|
||||||
|
({{ formatAmountBySymbol(balances.balance, currency.symbol, currency.decimal_places, true)|raw }})
|
||||||
|
{% elseif balances.native_balance %}
|
||||||
|
({{ formatAmountBySymbol(balances.native_balance, defaultCurrency.symbol, defaultCurrency.decimal_places, true)|raw }})
|
||||||
|
{% endif %}
|
||||||
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
{% if account.accountType.type == 'Asset account' %}
|
{% if account.accountType.type == 'Asset account' %}
|
||||||
|
@@ -68,8 +68,10 @@
|
|||||||
<span style="margin-right:5px;">
|
<span style="margin-right:5px;">
|
||||||
{% for key, balance in account.endBalances %}
|
{% for key, balance in account.endBalances %}
|
||||||
<span title="{{ key }}">
|
<span title="{{ key }}">
|
||||||
{% if 'balance' == key or 'native_balance' == key %}
|
{% if 'balance' == key %}
|
||||||
{{ formatAmountBySymbol(balance, defaultCurrency.symbol, defaultCurrency.currency.decimal_places) }}
|
{{ formatAmountBySymbol(balance, account.currency.symbol, account.currency.decimal_places) }}
|
||||||
|
{% elseif 'native_balance' == key %}
|
||||||
|
{{ formatAmountBySymbol(balance, defaultCurrency.symbol, defaultCurrency.decimal_places) }}
|
||||||
{% else %}
|
{% else %}
|
||||||
({{ formatAmountByCode(balance, key) }})
|
({{ formatAmountByCode(balance, key) }})
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -110,11 +112,14 @@
|
|||||||
<td class="hidden-sm hidden-xs hidden-md" style="text-align: right;">
|
<td class="hidden-sm hidden-xs hidden-md" style="text-align: right;">
|
||||||
<span style="margin-right:5px;">
|
<span style="margin-right:5px;">
|
||||||
{% for key, balance in account.differences %}
|
{% for key, balance in account.differences %}
|
||||||
|
<span title="{{ key }}">
|
||||||
{% if 'balance' == key or 'native_balance' == key %}
|
{% if 'balance' == key or 'native_balance' == key %}
|
||||||
{{ formatAmountBySymbol(balance, defaultCurrency.symbol, defaultCurrency.currency.decimal_places) }}
|
{{ formatAmountBySymbol(balance, account.currency.symbol, account.currency.currency.decimal_places) }}
|
||||||
|
|
||||||
{% else %}
|
{% else %}
|
||||||
({{ formatAmountByCode(balance, key) }})
|
({{ formatAmountByCode(balance, key) }})
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
|
Reference in New Issue
Block a user