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

@@ -96,7 +96,7 @@ class AccountController extends Controller
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($this->convertToNative);
$cache->addProperty($this->convertToPrimary);
$cache->addProperty('chart.account.expense-accounts');
if ($cache->has()) {
return response()->json($cache->get());
@@ -132,19 +132,19 @@ class AccountController extends Controller
* @var string $endBalance
*/
foreach ($expenses as $key => $endBalance) {
if (!$this->convertToNative && 'native_balance' === $key) {
if (!$this->convertToPrimary && 'pc_balance' === $key) {
// Log::debug(sprintf('[a] Will skip expense array "%s"', $key));
continue;
}
if ($this->convertToNative && 'native_balance' !== $key) {
if ($this->convertToPrimary && 'pc_balance' !== $key) {
// Log::debug(sprintf('[b] Will skip expense array "%s"', $key));
continue;
}
// Log::debug(sprintf('Will process expense array "%s" with amount %s', $key, $endBalance));
$searchCode = $this->convertToNative ? $this->defaultCurrency->code : $key;
$searchCode = 'balance' === $searchCode || 'native_balance' === $searchCode ? $this->defaultCurrency->code : $searchCode;
$searchCode = $this->convertToPrimary ? $this->primaryCurrency->code : $key;
$searchCode = 'balance' === $searchCode || 'pc_balance' === $searchCode ? $this->primaryCurrency->code : $searchCode;
// Log::debug(sprintf('Search code is %s', $searchCode));
// see if there is an accompanying start amount.
// grab the difference and find the currency.
@@ -433,7 +433,7 @@ class AccountController extends Controller
$cache->addProperty('chart.account.period');
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($this->convertToNative);
$cache->addProperty($this->convertToPrimary);
$cache->addProperty($account->id);
if ($cache->has()) {
return response()->json($cache->get());
@@ -453,8 +453,8 @@ class AccountController extends Controller
$format = (string) trans('config.month_and_day_js', [], $locale);
$accountCurrency = $this->accountRepository->getAccountCurrency($account);
$range = Steam::finalAccountBalanceInRange($account, $start, $end, $this->convertToNative);
$range = Steam::filterAccountBalances($range, $account, $this->convertToNative, $accountCurrency);
$range = Steam::finalAccountBalanceInRange($account, $start, $end, $this->convertToPrimary);
$range = Steam::filterAccountBalances($range, $account, $this->convertToPrimary, $accountCurrency);
// temp, get end balance.
Log::debug(sprintf('period: Call finalAccountBalance with date/time "%s"', $end->toIso8601String()));
@@ -462,7 +462,7 @@ class AccountController extends Controller
Log::debug('END temp get end balance done');
$previous = array_values($range)[0];
$accountCurrency ??= $this->defaultCurrency; // do this AFTER getting the balances.
$accountCurrency ??= $this->primaryCurrency; // do this AFTER getting the balances.
Log::debug('Start chart loop.');
$newRange = [];
@@ -510,7 +510,7 @@ class AccountController extends Controller
$chartData = [];
foreach ($return as $key => $info) {
if ('balance' !== $key && 'native_balance' !== $key) {
if ('balance' !== $key && 'pc_balance' !== $key) {
// assume it's a currency:
$setCurrency = $this->currencyRepository->findByCode((string) $key);
$info['currency_symbol'] = $setCurrency->symbol;
@@ -522,10 +522,10 @@ class AccountController extends Controller
$info['currency_code'] = $accountCurrency->code;
$info['label'] = sprintf('%s (%s)', $account->name, $accountCurrency->symbol);
}
if ('native_balance' === $key) {
$info['currency_symbol'] = $this->defaultCurrency->symbol;
$info['currency_code'] = $this->defaultCurrency->code;
$info['label'] = sprintf('%s (%s) (%s)', $account->name, (string) trans('firefly.sum'), $this->defaultCurrency->symbol);
if ('pc_balance' === $key) {
$info['currency_symbol'] = $this->primaryCurrency->symbol;
$info['currency_code'] = $this->primaryCurrency->code;
$info['label'] = sprintf('%s (%s) (%s)', $account->name, (string) trans('firefly.sum'), $this->primaryCurrency->symbol);
}
$chartData[] = $info;
}
@@ -578,7 +578,7 @@ class AccountController extends Controller
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($this->convertToNative);
$cache->addProperty($this->convertToPrimary);
$cache->addProperty('chart.account.revenue-accounts');
if ($cache->has()) {
return response()->json($cache->get());
@@ -615,19 +615,19 @@ class AccountController extends Controller
* @var string $endBalance
*/
foreach ($expenses as $key => $endBalance) {
if (!$this->convertToNative && 'native_balance' === $key) {
if (!$this->convertToPrimary && 'pc_balance' === $key) {
// Log::debug(sprintf('[a] Will skip expense array "%s"', $key));
continue;
}
if ($this->convertToNative && 'native_balance' !== $key) {
if ($this->convertToPrimary && 'pc_balance' !== $key) {
// Log::debug(sprintf('[b] Will skip expense array "%s"', $key));
continue;
}
// Log::debug(sprintf('Will process expense array "%s" with amount %s', $key, $endBalance));
$searchCode = $this->convertToNative ? $this->defaultCurrency->code : $key;
$searchCode = 'balance' === $searchCode || 'native_balance' === $searchCode ? $this->defaultCurrency->code : $searchCode;
$searchCode = $this->convertToPrimary ? $this->primaryCurrency->code : $key;
$searchCode = 'balance' === $searchCode || 'pc_balance' === $searchCode ? $this->primaryCurrency->code : $searchCode;
// Log::debug(sprintf('Search code is %s', $searchCode));
// see if there is an accompanying start amount.
// grab the difference and find the currency.

View File

@@ -109,7 +109,7 @@ class BillController extends Controller
$cache = new CacheProperties();
$cache->addProperty('chart.bill.single');
$cache->addProperty($bill->id);
$cache->addProperty($this->convertToNative);
$cache->addProperty($this->convertToPrimary);
if ($cache->has()) {
return response()->json($cache->get());
}
@@ -134,8 +134,8 @@ class BillController extends Controller
}
);
$currency = $bill->transactionCurrency;
if ($this->convertToNative) {
$currency = $this->defaultCurrency;
if ($this->convertToPrimary) {
$currency = $this->primaryCurrency;
}
$chartData = [
@@ -164,7 +164,7 @@ class BillController extends Controller
$currencyId = $bill->transaction_currency_id;
$amountMin = $bill->amount_min;
$amountMax = $bill->amount_max;
if ($this->convertToNative && $currencyId !== $this->defaultCurrency->id) {
if ($this->convertToPrimary && $currencyId !== $this->primaryCurrency->id) {
$amountMin = $bill->native_amount_min;
$amountMax = $bill->native_amount_max;
}
@@ -178,11 +178,11 @@ class BillController extends Controller
$chartData[2]['entries'][$date] = '0';
}
$amount = bcmul((string) $journal['amount'], '-1');
if ($this->convertToNative && $currencyId !== $journal['currency_id']) {
$amount = bcmul($journal['native_amount'] ?? '0', '-1');
if ($this->convertToPrimary && $currencyId !== $journal['currency_id']) {
$amount = bcmul($journal['pc_amount'] ?? '0', '-1');
}
if ($this->convertToNative && $currencyId === $journal['foreign_currency_id']) {
$amount = bcmul((string) $journal['foreign_amount'], '-1');
if ($this->convertToPrimary && $currencyId === $journal['foreign_currency_id']) {
$amount = bcmul((string) $journal['pc_amount'], '-1');
}
$chartData[2]['entries'][$date] = bcadd($chartData[2]['entries'][$date], $amount); // amount of journal

View File

@@ -91,7 +91,7 @@ class BudgetController extends Controller
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($this->convertToNative);
$cache->addProperty($this->convertToPrimary);
$cache->addProperty('chart.budget.budget');
$cache->addProperty($budget->id);
@@ -108,7 +108,7 @@ class BudgetController extends Controller
while ($end >= $loopStart) {
/** @var Carbon $loopEnd */
$loopEnd = app('navigation')->endOfPeriod($loopStart, $step);
$spent = $this->opsRepository->sumExpenses($loopStart, $loopEnd, null, $collection); // this method already converts to native.
$spent = $this->opsRepository->sumExpenses($loopStart, $loopEnd, null, $collection); // this method already converts to primary currency.
$label = trim((string) app('navigation')->periodShow($loopStart, $step));
foreach ($spent as $row) {
@@ -157,7 +157,7 @@ class BudgetController extends Controller
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($this->convertToNative);
$cache->addProperty($this->convertToPrimary);
$cache->addProperty('chart.budget.budget.limit');
$cache->addProperty($budgetLimit->id);
$cache->addProperty($budget->id);
@@ -170,14 +170,14 @@ class BudgetController extends Controller
$amount = $budgetLimit->amount ?? '0';
$budgetCollection = new Collection([$budget]);
$currency = $budgetLimit->transactionCurrency;
if ($this->convertToNative) {
if ($this->convertToPrimary) {
$amount = $budgetLimit->native_amount ?? $amount;
$currency = $this->defaultCurrency;
$currency = $this->primaryCurrency;
}
while ($start <= $end) {
$current = clone $start;
$expenses = $this->opsRepository->sumExpenses($current, $current, null, $budgetCollection, $budgetLimit->transactionCurrency, $this->convertToNative);
$expenses = $this->opsRepository->sumExpenses($current, $current, null, $budgetCollection, $budgetLimit->transactionCurrency, $this->convertToPrimary);
$spent = $expenses[$currency->id]['sum'] ?? '0';
$amount = bcadd((string) $amount, $spent);
$format = $start->isoFormat((string) trans('config.month_and_day_js', [], $locale));
@@ -205,7 +205,7 @@ class BudgetController extends Controller
$budgetLimitId = $budgetLimit instanceof BudgetLimit ? $budgetLimit->id : 0;
$cache = new CacheProperties();
$cache->addProperty($budget->id);
$cache->addProperty($this->convertToNative);
$cache->addProperty($this->convertToPrimary);
$cache->addProperty($budgetLimitId);
$cache->addProperty('chart.budget.expense-asset');
$start = session('first', today(config('app.timezone'))->startOfYear());
@@ -237,16 +237,16 @@ class BudgetController extends Controller
$code = $journal['currency_code'];
$name = $journal['currency_name'];
// if convert to native, use the native things, unless it's the foreign amount which is in the native currency.
if ($this->convertToNative && $journal['currency_id'] !== $this->defaultCurrency->id) {
$key = sprintf('%d-%d', $journal['source_account_id'], $this->defaultCurrency->id);
$symbol = $this->defaultCurrency->symbol;
$code = $this->defaultCurrency->code;
$name = $this->defaultCurrency->name;
$amount = $journal['native_amount'];
// if convert to primary, use the primary things, unless it's the foreign amount which is in the primary currency.
if ($this->convertToPrimary && $journal['currency_id'] !== $this->primaryCurrency->id) {
$key = sprintf('%d-%d', $journal['source_account_id'], $this->primaryCurrency->id);
$symbol = $this->primaryCurrency->symbol;
$code = $this->primaryCurrency->code;
$name = $this->primaryCurrency->name;
$amount = $journal['pc_amount'];
}
if ($journal['foreign_currency_id'] === $this->defaultCurrency->id) {
if ($journal['foreign_currency_id'] === $this->primaryCurrency->id) {
$amount = $journal['foreign_amount'];
}
@@ -288,7 +288,7 @@ class BudgetController extends Controller
$budgetLimitId = $budgetLimit instanceof BudgetLimit ? $budgetLimit->id : 0;
$cache = new CacheProperties();
$cache->addProperty($budget->id);
$cache->addProperty($this->convertToNative);
$cache->addProperty($this->convertToPrimary);
$cache->addProperty($budgetLimitId);
$cache->addProperty('chart.budget.expense-category');
$start = session('first', today(config('app.timezone'))->startOfYear());
@@ -315,22 +315,22 @@ class BudgetController extends Controller
$code = $journal['currency_code'];
$name = $journal['currency_name'];
$amount = $journal['amount'];
// if convert to native, use the native things, unless it's the foreign amount which is in the native currency.
if ($this->convertToNative && $journal['currency_id'] !== $this->defaultCurrency->id && $journal['foreign_currency_id'] !== $this->defaultCurrency->id
// if convert to primary, use the primary things, unless it's the foreign amount which is in the primary currency.
if ($this->convertToPrimary && $journal['currency_id'] !== $this->primaryCurrency->id && $journal['foreign_currency_id'] !== $this->primaryCurrency->id
) {
$key = sprintf('%d-%d', $journal['category_id'], $this->defaultCurrency->id);
$symbol = $this->defaultCurrency->symbol;
$code = $this->defaultCurrency->code;
$name = $this->defaultCurrency->name;
$amount = $journal['native_amount'];
$key = sprintf('%d-%d', $journal['category_id'], $this->primaryCurrency->id);
$symbol = $this->primaryCurrency->symbol;
$code = $this->primaryCurrency->code;
$name = $this->primaryCurrency->name;
$amount = $journal['pc_amount'];
}
if ($this->convertToNative && $journal['currency_id'] !== $this->defaultCurrency->id && $journal['foreign_currency_id'] === $this->defaultCurrency->id
if ($this->convertToPrimary && $journal['currency_id'] !== $this->primaryCurrency->id && $journal['foreign_currency_id'] === $this->primaryCurrency->id
) {
$key = sprintf('%d-%d', $journal['category_id'], $this->defaultCurrency->id);
$symbol = $this->defaultCurrency->symbol;
$code = $this->defaultCurrency->code;
$name = $this->defaultCurrency->name;
$key = sprintf('%d-%d', $journal['category_id'], $this->primaryCurrency->id);
$symbol = $this->primaryCurrency->symbol;
$code = $this->primaryCurrency->code;
$name = $this->primaryCurrency->name;
$amount = $journal['foreign_amount'];
}
@@ -371,7 +371,7 @@ class BudgetController extends Controller
$cache = new CacheProperties();
$cache->addProperty($budget->id);
$cache->addProperty($budgetLimitId);
$cache->addProperty($this->convertToNative);
$cache->addProperty($this->convertToPrimary);
$cache->addProperty('chart.budget.expense-expense');
$start = session('first', today(config('app.timezone'))->startOfYear());
$end = today();
@@ -400,20 +400,20 @@ class BudgetController extends Controller
$code = $journal['currency_code'];
$name = $journal['currency_name'];
// if convert to native, use the native things, unless it's the foreign amount which is in the native currency.
if ($this->convertToNative && $journal['currency_id'] !== $this->defaultCurrency->id && $journal['foreign_currency_id'] !== $this->defaultCurrency->id) {
$key = sprintf('%d-%d', $journal['destination_account_id'], $this->defaultCurrency->id);
$symbol = $this->defaultCurrency->symbol;
$code = $this->defaultCurrency->code;
$name = $this->defaultCurrency->name;
$amount = $journal['native_amount'];
// if convert to primary, use the primary things, unless it's the foreign amount which is in the primary currency.
if ($this->convertToPrimary && $journal['currency_id'] !== $this->primaryCurrency->id && $journal['foreign_currency_id'] !== $this->primaryCurrency->id) {
$key = sprintf('%d-%d', $journal['destination_account_id'], $this->primaryCurrency->id);
$symbol = $this->primaryCurrency->symbol;
$code = $this->primaryCurrency->code;
$name = $this->primaryCurrency->name;
$amount = $journal['pc_amount'];
}
if ($this->convertToNative && $journal['currency_id'] !== $this->defaultCurrency->id && $journal['foreign_currency_id'] === $this->defaultCurrency->id) {
$key = sprintf('%d-%d', $journal['destination_account_id'], $this->defaultCurrency->id);
$symbol = $this->defaultCurrency->symbol;
$code = $this->defaultCurrency->code;
$name = $this->defaultCurrency->name;
if ($this->convertToPrimary && $journal['currency_id'] !== $this->primaryCurrency->id && $journal['foreign_currency_id'] === $this->primaryCurrency->id) {
$key = sprintf('%d-%d', $journal['destination_account_id'], $this->primaryCurrency->id);
$symbol = $this->primaryCurrency->symbol;
$code = $this->primaryCurrency->code;
$name = $this->primaryCurrency->name;
$amount = $journal['foreign_amount'];
}
@@ -456,7 +456,7 @@ class BudgetController extends Controller
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($this->convertToNative);
$cache->addProperty($this->convertToPrimary);
$cache->addProperty('chart.budget.frontpage');
if ($cache->has()) {
return response()->json($cache->get());
@@ -466,8 +466,8 @@ class BudgetController extends Controller
$chartGenerator->setUser(auth()->user());
$chartGenerator->setStart($start);
$chartGenerator->setEnd($end);
$chartGenerator->convertToNative = $this->convertToNative;
$chartGenerator->default = $this->defaultCurrency;
$chartGenerator->convertToPrimary = $this->convertToPrimary;
$chartGenerator->default = $this->primaryCurrency;
$chartData = $chartGenerator->generate();
$data = $this->generator->multiSet($chartData);

View File

@@ -73,7 +73,7 @@ class CategoryController extends Controller
$cache = new CacheProperties();
$cache->addProperty('chart.category.all');
$cache->addProperty($category->id);
$cache->addProperty($this->convertToNative);
$cache->addProperty($this->convertToPrimary);
if ($cache->has()) {
return response()->json($cache->get());
}
@@ -87,7 +87,7 @@ class CategoryController extends Controller
/** @var WholePeriodChartGenerator $chartGenerator */
$chartGenerator = app(WholePeriodChartGenerator::class);
$chartGenerator->convertToNative = $this->convertToNative;
$chartGenerator->convertToPrimary = $this->convertToPrimary;
$chartData = $chartGenerator->generate($category, $start, $end);
$data = $this->generator->multiSet($chartData);
@@ -113,7 +113,7 @@ class CategoryController extends Controller
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($this->convertToNative);
$cache->addProperty($this->convertToPrimary);
$cache->addProperty('chart.category.frontpage');
if ($cache->has()) {
return response()->json($cache->get());
@@ -139,7 +139,7 @@ class CategoryController extends Controller
$cache->addProperty('chart.category.period');
$cache->addProperty($accounts->pluck('id')->toArray());
$cache->addProperty($category);
$cache->addProperty($this->convertToNative);
$cache->addProperty($this->convertToPrimary);
if ($cache->has()) {
return response()->json($cache->get());
}

View File

@@ -108,7 +108,7 @@ class ReportController extends Controller
// loop result, add to array.
/** @var array $netWorthItem */
foreach ($result as $key => $netWorthItem) {
if ('native' === $key) {
if ('primary' === $key) {
continue;
}
$currencyId = $netWorthItem['currency_id'];