Rename "native" to "primary".

This commit is contained in:
James Cole
2025-08-01 06:12:36 +02:00
parent ea6addafe6
commit 084ce02c21
51 changed files with 296 additions and 296 deletions

View File

@@ -68,7 +68,7 @@ class BoxController extends Controller
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($this->convertToNative);
$cache->addProperty($this->convertToPrimary);
$cache->addProperty('box-balance');
if ($cache->has()) {
return response()->json($cache->get());
@@ -77,7 +77,7 @@ class BoxController extends Controller
$incomes = [];
$expenses = [];
$sums = [];
$currency = $this->defaultCurrency;
$currency = $this->primaryCurrency;
// collect income of user:
/** @var GroupCollectorInterface $collector */
@@ -89,7 +89,7 @@ class BoxController extends Controller
/** @var array $journal */
foreach ($set as $journal) {
$currencyId = $this->convertToNative && $this->defaultCurrency->id !== (int) $journal['currency_id'] ? $this->defaultCurrency->id : (int) $journal['currency_id'];
$currencyId = $this->convertToPrimary && $this->primaryCurrency->id !== (int) $journal['currency_id'] ? $this->primaryCurrency->id : (int) $journal['currency_id'];
$amount = Amount::getAmountFromJournal($journal);
$incomes[$currencyId] ??= '0';
$incomes[$currencyId] = bcadd($incomes[$currencyId], (string) app('steam')->positive($amount));
@@ -107,7 +107,7 @@ class BoxController extends Controller
/** @var array $journal */
foreach ($set as $journal) {
$currencyId = $this->convertToNative ? $this->defaultCurrency->id : (int) $journal['currency_id'];
$currencyId = $this->convertToPrimary ? $this->primaryCurrency->id : (int) $journal['currency_id'];
$amount = Amount::getAmountFromJournal($journal);
$expenses[$currencyId] ??= '0';
$expenses[$currencyId] = bcadd($expenses[$currencyId], $amount);
@@ -124,10 +124,10 @@ class BoxController extends Controller
$expenses[$currencyId] = app('amount')->formatAnything($currency, $expenses[$currencyId] ?? '0', false);
}
if (0 === count($sums)) {
$currency = $this->defaultCurrency;
$sums[$this->defaultCurrency->id] = app('amount')->formatAnything($this->defaultCurrency, '0', false);
$incomes[$this->defaultCurrency->id] = app('amount')->formatAnything($this->defaultCurrency, '0', false);
$expenses[$this->defaultCurrency->id] = app('amount')->formatAnything($this->defaultCurrency, '0', false);
$currency = $this->primaryCurrency;
$sums[$this->primaryCurrency->id] = app('amount')->formatAnything($this->primaryCurrency, '0', false);
$incomes[$this->primaryCurrency->id] = app('amount')->formatAnything($this->primaryCurrency, '0', false);
$expenses[$this->primaryCurrency->id] = app('amount')->formatAnything($this->primaryCurrency, '0', false);
}
$response = [
@@ -182,7 +182,7 @@ class BoxController extends Controller
$netWorthSet = $netWorthHelper->byAccounts($filtered, $date);
$return = [];
foreach ($netWorthSet as $key => $data) {
if ('native' === $key) {
if ('primary' === $key) {
continue;
}
$return[$data['currency_id']] = app('amount')->formatFlat($data['currency_symbol'], $data['currency_decimal_places'], $data['balance'], false);

View File

@@ -45,14 +45,12 @@ class FrontpageController extends Controller
{
$set = $repository->getPiggyBanks();
$info = [];
$native = Amount::getPrimaryCurrency();
$convertToNative = Amount::convertToPrimary();
/** @var PiggyBank $piggyBank */
foreach ($set as $piggyBank) {
$amount = $repository->getCurrentAmount($piggyBank);
$nativeAmount = $repository->getCurrentNativeAmount($piggyBank);
$pcAmount = $repository->getCurrentPrimaryCurrencyAmount($piggyBank);
if (1 === bccomp($amount, '0')) {
// percentage!
$pct = 0;
@@ -64,15 +62,15 @@ class FrontpageController extends Controller
'id' => $piggyBank->id,
'name' => $piggyBank->name,
'amount' => $amount,
'native_amount' => $nativeAmount,
'pc_amount' => $pcAmount,
'target' => $piggyBank->target_amount,
'native_target' => $piggyBank->native_target_amount,
'pc_target' => $piggyBank->native_target_amount,
'percentage' => $pct,
// currency:
'currency_symbol' => $piggyBank->transactionCurrency->symbol,
'currency_decimal_places' => $piggyBank->transactionCurrency->decimal_places,
'native_currency_symbol' => $native->symbol,
'native_currency_decimal_places' => $native->decimal_places,
'primary_currency_symbol' => $this->primaryCurrency->symbol,
'primary_currency_decimal_places' => $this->primaryCurrency->decimal_places,
];
@@ -89,7 +87,9 @@ class FrontpageController extends Controller
$html = '';
if (0 !== count($info)) {
try {
$html = view('json.piggy-banks', compact('info', 'convertToNative', 'native'))->render();
$convertToPrimary = $this->convertToPrimary;
$primary = $this->primaryCurrency;
$html = view('json.piggy-banks', compact('info', 'convertToPrimary', 'primary'))->render();
} catch (Throwable $e) {
app('log')->error(sprintf('Cannot render json.piggy-banks: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString());

View File

@@ -74,7 +74,7 @@ class ReconcileController extends Controller
{
$startBalance = $request->get('startBalance');
$endBalance = $request->get('endBalance');
$accountCurrency = $this->accountRepos->getAccountCurrency($account) ?? $this->defaultCurrency;
$accountCurrency = $this->accountRepos->getAccountCurrency($account) ?? $this->primaryCurrency;
$amount = '0';
$clearedAmount = '0';
@@ -195,7 +195,7 @@ class ReconcileController extends Controller
$startDate = clone $start;
$startDate->subDay();
$currency = $this->accountRepos->getAccountCurrency($account) ?? $this->defaultCurrency;
$currency = $this->accountRepos->getAccountCurrency($account) ?? $this->primaryCurrency;
// correct
Log::debug(sprintf('transactions: Call finalAccountBalance with date/time "%s"', $startDate->toIso8601String()));
Log::debug(sprintf('transactions2: Call finalAccountBalance with date/time "%s"', $end->toIso8601String()));