mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-24 22:48:18 +00:00
Fix native display.
This commit is contained in:
@@ -154,6 +154,7 @@ class IndexController extends Controller
|
|||||||
$startBalances = app('steam')->finalAccountsBalance($accounts, $start);
|
$startBalances = app('steam')->finalAccountsBalance($accounts, $start);
|
||||||
$endBalances = app('steam')->finalAccountsBalance($accounts, $end);
|
$endBalances = app('steam')->finalAccountsBalance($accounts, $end);
|
||||||
$activities = app('steam')->getLastActivities($ids);
|
$activities = app('steam')->getLastActivities($ids);
|
||||||
|
|
||||||
$accounts->each(
|
$accounts->each(
|
||||||
function (Account $account) use ($activities, $startBalances, $endBalances): void {
|
function (Account $account) use ($activities, $startBalances, $endBalances): void {
|
||||||
$interest = (string) $this->repository->getMetaValue($account, 'interest');
|
$interest = (string) $this->repository->getMetaValue($account, 'interest');
|
||||||
|
@@ -89,14 +89,13 @@ class AccountController extends Controller
|
|||||||
|
|
||||||
/** @var Carbon $end */
|
/** @var Carbon $end */
|
||||||
$end = clone session('end', today(config('app.timezone'))->endOfMonth());
|
$end = clone session('end', today(config('app.timezone'))->endOfMonth());
|
||||||
$convertToNative = app('preferences')->get('convert_to_native', false)->data;
|
|
||||||
$cache = new CacheProperties();
|
$cache = new CacheProperties();
|
||||||
$cache->addProperty($start);
|
$cache->addProperty($start);
|
||||||
$cache->addProperty($end);
|
$cache->addProperty($end);
|
||||||
$cache->addProperty($convertToNative);
|
$cache->addProperty($this->convertToNative);
|
||||||
$cache->addProperty('chart.account.expense-accounts');
|
$cache->addProperty('chart.account.expense-accounts');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
// return response()->json($cache->get());
|
return response()->json($cache->get());
|
||||||
}
|
}
|
||||||
$start->subDay();
|
$start->subDay();
|
||||||
|
|
||||||
@@ -127,16 +126,16 @@ class AccountController extends Controller
|
|||||||
* @var string $endBalance
|
* @var string $endBalance
|
||||||
*/
|
*/
|
||||||
foreach ($expenses as $key => $endBalance) {
|
foreach ($expenses as $key => $endBalance) {
|
||||||
if(!$convertToNative && 'native_balance' === $key) {
|
if(!$this->convertToNative && 'native_balance' === $key) {
|
||||||
Log::debug(sprintf('[a] Will skip expense array "%s"', $key));
|
Log::debug(sprintf('[a] Will skip expense array "%s"', $key));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if($convertToNative && 'native_balance' !== $key) {
|
if($this->convertToNative && 'native_balance' !== $key) {
|
||||||
Log::debug(sprintf('[b] Will skip expense array "%s"', $key));
|
Log::debug(sprintf('[b] Will skip expense array "%s"', $key));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Log::debug(sprintf('Will process expense array "%s" with amount %s', $key, $endBalance));
|
Log::debug(sprintf('Will process expense array "%s" with amount %s', $key, $endBalance));
|
||||||
$searchCode = $convertToNative ? $default->code: $key;
|
$searchCode = $this->convertToNative ? $default->code: $key;
|
||||||
Log::debug(sprintf('Search code is %s', $searchCode));
|
Log::debug(sprintf('Search code is %s', $searchCode));
|
||||||
// see if there is an accompanying start amount.
|
// see if there is an accompanying start amount.
|
||||||
// grab the difference and find the currency.
|
// grab the difference and find the currency.
|
||||||
@@ -518,13 +517,12 @@ class AccountController extends Controller
|
|||||||
/** @var Carbon $end */
|
/** @var Carbon $end */
|
||||||
$end = clone session('end', today(config('app.timezone'))->endOfMonth());
|
$end = clone session('end', today(config('app.timezone'))->endOfMonth());
|
||||||
$cache = new CacheProperties();
|
$cache = new CacheProperties();
|
||||||
$convertToNative = app('preferences')->get('convert_to_native', false)->data;
|
|
||||||
$cache->addProperty($start);
|
$cache->addProperty($start);
|
||||||
$cache->addProperty($end);
|
$cache->addProperty($end);
|
||||||
$cache->addProperty($convertToNative);
|
$cache->addProperty($this->convertToNative);
|
||||||
$cache->addProperty('chart.account.revenue-accounts');
|
$cache->addProperty('chart.account.revenue-accounts');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
// return response()->json($cache->get());
|
return response()->json($cache->get());
|
||||||
}
|
}
|
||||||
$start->subDay();
|
$start->subDay();
|
||||||
|
|
||||||
@@ -556,16 +554,16 @@ class AccountController extends Controller
|
|||||||
* @var string $endBalance
|
* @var string $endBalance
|
||||||
*/
|
*/
|
||||||
foreach ($expenses as $key => $endBalance) {
|
foreach ($expenses as $key => $endBalance) {
|
||||||
if(!$convertToNative && 'native_balance' === $key) {
|
if(!$this->convertToNative && 'native_balance' === $key) {
|
||||||
Log::debug(sprintf('[a] Will skip expense array "%s"', $key));
|
Log::debug(sprintf('[a] Will skip expense array "%s"', $key));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if($convertToNative && 'native_balance' !== $key) {
|
if($this->convertToNative && 'native_balance' !== $key) {
|
||||||
Log::debug(sprintf('[b] Will skip expense array "%s"', $key));
|
Log::debug(sprintf('[b] Will skip expense array "%s"', $key));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
Log::debug(sprintf('Will process expense array "%s" with amount %s', $key, $endBalance));
|
Log::debug(sprintf('Will process expense array "%s" with amount %s', $key, $endBalance));
|
||||||
$searchCode = $convertToNative ? $default->code: $key;
|
$searchCode = $this->convertToNative ? $default->code: $key;
|
||||||
Log::debug(sprintf('Search code is %s', $searchCode));
|
Log::debug(sprintf('Search code is %s', $searchCode));
|
||||||
// see if there is an accompanying start amount.
|
// see if there is an accompanying start amount.
|
||||||
// grab the difference and find the currency.
|
// grab the difference and find the currency.
|
||||||
|
@@ -378,12 +378,11 @@ class BudgetController extends Controller
|
|||||||
{
|
{
|
||||||
$start = session('start', today(config('app.timezone'))->startOfMonth());
|
$start = session('start', today(config('app.timezone'))->startOfMonth());
|
||||||
$end = session('end', today(config('app.timezone'))->endOfMonth());
|
$end = session('end', today(config('app.timezone'))->endOfMonth());
|
||||||
$convertToNative = app('preferences')->get('convert_to_native', false)->data;
|
|
||||||
// chart properties for cache:
|
// chart properties for cache:
|
||||||
$cache = new CacheProperties();
|
$cache = new CacheProperties();
|
||||||
$cache->addProperty($start);
|
$cache->addProperty($start);
|
||||||
$cache->addProperty($end);
|
$cache->addProperty($end);
|
||||||
$cache->addProperty($convertToNative);
|
$cache->addProperty($this->convertToNative);
|
||||||
$cache->addProperty('chart.budget.frontpage');
|
$cache->addProperty('chart.budget.frontpage');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
// return response()->json($cache->get());
|
// return response()->json($cache->get());
|
||||||
@@ -393,7 +392,7 @@ class BudgetController extends Controller
|
|||||||
$chartGenerator->setUser(auth()->user());
|
$chartGenerator->setUser(auth()->user());
|
||||||
$chartGenerator->setStart($start);
|
$chartGenerator->setStart($start);
|
||||||
$chartGenerator->setEnd($end);
|
$chartGenerator->setEnd($end);
|
||||||
$chartGenerator->convertToNative = $convertToNative;
|
$chartGenerator->convertToNative = $this->convertToNative;
|
||||||
$chartGenerator->default = Amount::getDefaultCurrency();
|
$chartGenerator->default = Amount::getDefaultCurrency();
|
||||||
|
|
||||||
$chartData = $chartGenerator->generate();
|
$chartData = $chartGenerator->generate();
|
||||||
|
@@ -106,12 +106,11 @@ class CategoryController extends Controller
|
|||||||
{
|
{
|
||||||
$start = session('start', today(config('app.timezone'))->startOfMonth());
|
$start = session('start', today(config('app.timezone'))->startOfMonth());
|
||||||
$end = session('end', today(config('app.timezone'))->endOfMonth());
|
$end = session('end', today(config('app.timezone'))->endOfMonth());
|
||||||
$convertToNative = app('preferences')->get('convert_to_native', false)->data;
|
|
||||||
// chart properties for cache:
|
// chart properties for cache:
|
||||||
$cache = new CacheProperties();
|
$cache = new CacheProperties();
|
||||||
$cache->addProperty($start);
|
$cache->addProperty($start);
|
||||||
$cache->addProperty($end);
|
$cache->addProperty($end);
|
||||||
$cache->addProperty($convertToNative);
|
$cache->addProperty($this->convertToNative);
|
||||||
$cache->addProperty('chart.category.frontpage');
|
$cache->addProperty('chart.category.frontpage');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
// return response()->json($cache->get());
|
// return response()->json($cache->get());
|
||||||
|
@@ -52,6 +52,7 @@ abstract class Controller extends BaseController
|
|||||||
|
|
||||||
protected string $dateTimeFormat;
|
protected string $dateTimeFormat;
|
||||||
protected string $monthAndDayFormat;
|
protected string $monthAndDayFormat;
|
||||||
|
protected bool $convertToNative = false;
|
||||||
protected string $monthFormat;
|
protected string $monthFormat;
|
||||||
protected string $redirectUrl = '/';
|
protected string $redirectUrl = '/';
|
||||||
|
|
||||||
@@ -116,12 +117,12 @@ abstract class Controller extends BaseController
|
|||||||
$language = Steam::getLanguage();
|
$language = Steam::getLanguage();
|
||||||
$locale = Steam::getLocale();
|
$locale = Steam::getLocale();
|
||||||
$darkMode = app('preferences')->get('darkMode', 'browser')->data;
|
$darkMode = app('preferences')->get('darkMode', 'browser')->data;
|
||||||
$convertToNative =app('preferences')->get('convert_to_native', false)->data;
|
$this->convertToNative =app('preferences')->get('convert_to_native', false)->data;
|
||||||
$page = $this->getPageName();
|
$page = $this->getPageName();
|
||||||
$shownDemo = $this->hasSeenDemo();
|
$shownDemo = $this->hasSeenDemo();
|
||||||
View::share('language', $language);
|
View::share('language', $language);
|
||||||
View::share('locale', $locale);
|
View::share('locale', $locale);
|
||||||
View::share('convertToNative', $convertToNative);
|
View::share('convertToNative', $this->convertToNative);
|
||||||
View::share('shownDemo', $shownDemo);
|
View::share('shownDemo', $shownDemo);
|
||||||
View::share('current_route_name', $page);
|
View::share('current_route_name', $page);
|
||||||
View::share('original_route_name', Route::currentRouteName());
|
View::share('original_route_name', Route::currentRouteName());
|
||||||
|
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||||||
namespace FireflyIII\Http\Controllers\Json;
|
namespace FireflyIII\Http\Controllers\Json;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Enums\TransactionTypeEnum;
|
||||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||||
use FireflyIII\Helpers\Report\NetWorthInterface;
|
use FireflyIII\Helpers\Report\NetWorthInterface;
|
||||||
use FireflyIII\Http\Controllers\Controller;
|
use FireflyIII\Http\Controllers\Controller;
|
||||||
@@ -65,14 +66,13 @@ class BoxController extends Controller
|
|||||||
|
|
||||||
/** @var Carbon $end */
|
/** @var Carbon $end */
|
||||||
$end = session('end', today(config('app.timezone'))->endOfMonth());
|
$end = session('end', today(config('app.timezone'))->endOfMonth());
|
||||||
$convertToNative = app('preferences')->get('convert_to_native', false)->data;
|
|
||||||
$cache = new CacheProperties();
|
$cache = new CacheProperties();
|
||||||
$cache->addProperty($start);
|
$cache->addProperty($start);
|
||||||
$cache->addProperty($end);
|
$cache->addProperty($end);
|
||||||
$cache->addProperty($convertToNative);
|
$cache->addProperty($this->convertToNative);
|
||||||
$cache->addProperty('box-balance');
|
$cache->addProperty('box-balance');
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
// return response()->json($cache->get());
|
return response()->json($cache->get());
|
||||||
}
|
}
|
||||||
// prep some arrays:
|
// prep some arrays:
|
||||||
$incomes = [];
|
$incomes = [];
|
||||||
@@ -90,7 +90,7 @@ class BoxController extends Controller
|
|||||||
|
|
||||||
/** @var array $journal */
|
/** @var array $journal */
|
||||||
foreach ($set as $journal) {
|
foreach ($set as $journal) {
|
||||||
$currencyId = $convertToNative ? $currency->id : (int) $journal['currency_id'];
|
$currencyId = $this->convertToNative ? $currency->id : (int) $journal['currency_id'];
|
||||||
$amount = Amount::getAmountFromJournal($journal);
|
$amount = Amount::getAmountFromJournal($journal);
|
||||||
$incomes[$currencyId] ??= '0';
|
$incomes[$currencyId] ??= '0';
|
||||||
$incomes[$currencyId] = bcadd($incomes[$currencyId], app('steam')->positive($amount));
|
$incomes[$currencyId] = bcadd($incomes[$currencyId], app('steam')->positive($amount));
|
||||||
@@ -102,12 +102,12 @@ class BoxController extends Controller
|
|||||||
/** @var GroupCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(GroupCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
$collector->setRange($start, $end)
|
$collector->setRange($start, $end)
|
||||||
->setTypes([TransactionType::WITHDRAWAL]);
|
->setTypes([TransactionTypeEnum::WITHDRAWAL->value]);
|
||||||
$set = $collector->getExtractedJournals();
|
$set = $collector->getExtractedJournals();
|
||||||
|
|
||||||
/** @var array $journal */
|
/** @var array $journal */
|
||||||
foreach ($set as $journal) {
|
foreach ($set as $journal) {
|
||||||
$currencyId = $convertToNative ? $currency->id : (int) $journal['currency_id'];
|
$currencyId = $this->convertToNative ? $currency->id : (int) $journal['currency_id'];
|
||||||
$amount = Amount::getAmountFromJournal($journal);
|
$amount = Amount::getAmountFromJournal($journal);
|
||||||
$expenses[$currencyId] ??= '0';
|
$expenses[$currencyId] ??= '0';
|
||||||
$expenses[$currencyId] = bcadd($expenses[$currencyId], $amount);
|
$expenses[$currencyId] = bcadd($expenses[$currencyId], $amount);
|
||||||
|
@@ -103,7 +103,7 @@ class PreferencesController extends Controller
|
|||||||
$darkMode = app('preferences')->get('darkMode', 'browser')->data;
|
$darkMode = app('preferences')->get('darkMode', 'browser')->data;
|
||||||
$customFiscalYear = app('preferences')->get('customFiscalYear', 0)->data;
|
$customFiscalYear = app('preferences')->get('customFiscalYear', 0)->data;
|
||||||
$fiscalYearStartStr = app('preferences')->get('fiscalYearStart', '01-01')->data;
|
$fiscalYearStartStr = app('preferences')->get('fiscalYearStart', '01-01')->data;
|
||||||
$convertToNative = app('preferences')->get('convert_to_native', false)->data;
|
$convertToNative = $this->convertToNative;
|
||||||
if (is_array($fiscalYearStartStr)) {
|
if (is_array($fiscalYearStartStr)) {
|
||||||
$fiscalYearStartStr = '01-01';
|
$fiscalYearStartStr = '01-01';
|
||||||
}
|
}
|
||||||
|
@@ -38,7 +38,8 @@ trait BasicDataSupport
|
|||||||
*/
|
*/
|
||||||
protected function isInArray(array $array, int $entryId)
|
protected function isInArray(array $array, int $entryId)
|
||||||
{
|
{
|
||||||
return $array[$entryId]['balance'] ?? '0';
|
$key = $this->convertToNative ? 'native_balance' : 'balance';
|
||||||
|
return $array[$entryId][$key] ?? '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -282,12 +282,6 @@ class Steam
|
|||||||
$accountCurrency = $this->getAccountCurrency($account);
|
$accountCurrency = $this->getAccountCurrency($account);
|
||||||
$hasCurrency = null !== $accountCurrency;
|
$hasCurrency = null !== $accountCurrency;
|
||||||
$currency = $hasCurrency ? $accountCurrency : $native;
|
$currency = $hasCurrency ? $accountCurrency : $native;
|
||||||
if (!$hasCurrency) {
|
|
||||||
//Log::debug('Pretend native currency is fake, because account has no currency.');
|
|
||||||
// fake currency
|
|
||||||
//$native = new TransactionCurrency();
|
|
||||||
}
|
|
||||||
//unset($accountCurrency);
|
|
||||||
$return = [];
|
$return = [];
|
||||||
|
|
||||||
// first, the "balance", as described earlier.
|
// first, the "balance", as described earlier.
|
||||||
@@ -336,10 +330,16 @@ class Steam
|
|||||||
Log::debug('All balances are (joined)', $others);
|
Log::debug('All balances are (joined)', $others);
|
||||||
// if the account has no own currency preference, drop balance in favor of native balance
|
// if the account has no own currency preference, drop balance in favor of native balance
|
||||||
if ($hasCurrency && !$convertToNative) {
|
if ($hasCurrency && !$convertToNative) {
|
||||||
$return['balance'] = $others[$currency->code] ?? null;
|
$return['balance'] = $others[$currency->code] ?? '0';
|
||||||
$return['native_balance'] = $others[$currency->code] ?? null;
|
$return['native_balance'] = $others[$currency->code] ?? '0';
|
||||||
Log::debug(sprintf('Set balance + native_balance to %s', $return['balance']));
|
Log::debug(sprintf('Set balance + native_balance to %s', $return['balance']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if the currency is the same as the native currency, set the native_balance to the balance for consistency.
|
||||||
|
if($currency->id === $native->id) {
|
||||||
|
$return['native_balance'] = $return['balance'];
|
||||||
|
}
|
||||||
|
|
||||||
if (!$hasCurrency) {
|
if (!$hasCurrency) {
|
||||||
Log::debug('Account has no currency preference, dropping balance in favor of native balance.');
|
Log::debug('Account has no currency preference, dropping balance in favor of native balance.');
|
||||||
$sum = bcadd($return['balance'], $return['native_balance']);
|
$sum = bcadd($return['balance'], $return['native_balance']);
|
||||||
|
Reference in New Issue
Block a user