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

@@ -105,7 +105,7 @@ class GroupCollector implements GroupCollectorInterface
'category_id',
'budget_id',
];
$this->stringFields = ['amount', 'foreign_amount', 'native_amount', 'native_foreign_amount', 'source_balance_after', 'destination_balance_after'];
$this->stringFields = ['amount', 'foreign_amount', 'pc_amount', 'pc_foreign_amount', 'source_balance_after', 'destination_balance_after'];
$this->total = 0;
$this->fields = [
// group
@@ -138,7 +138,7 @@ class GroupCollector implements GroupCollectorInterface
'source.amount as amount',
'source.balance_after as source_balance_after',
'source.balance_dirty as source_balance_dirty',
'source.native_amount as native_amount',
'source.native_amount as pc_amount',
'source.transaction_currency_id as currency_id',
'currency.code as currency_code',
'currency.name as currency_name',
@@ -147,7 +147,7 @@ class GroupCollector implements GroupCollectorInterface
// foreign currency info
'source.foreign_amount as foreign_amount',
'source.native_foreign_amount as native_foreign_amount',
'source.native_foreign_amount as pc_foreign_amount',
'source.foreign_currency_id as foreign_currency_id',
'foreign_currency.code as foreign_currency_code',
'foreign_currency.name as foreign_currency_name',
@@ -735,8 +735,8 @@ class GroupCollector implements GroupCollectorInterface
if (null === $transaction['amount']) {
throw new FireflyException(sprintf('Amount is NULL for a transaction in group #%d, please investigate.', $groudId));
}
$nativeAmount = (string) ('' === $transaction['native_amount'] ? '0' : $transaction['native_amount']);
$nativeForeignAmount = (string) ('' === $transaction['native_foreign_amount'] ? '0' : $transaction['native_foreign_amount']);
$pcAmount = (string) ('' === $transaction['pc_amount'] ? '0' : $transaction['pc_amount']);
$pcForeignAmount = (string) ('' === $transaction['pc_foreign_amount'] ? '0' : $transaction['pc_foreign_amount']);
$foreignAmount = (string) ('' === $transaction['foreign_amount'] ? '0' : $transaction['foreign_amount']);
// set default:
@@ -746,10 +746,10 @@ class GroupCollector implements GroupCollectorInterface
$groups[$groudId]['sums'][$currencyId]['currency_symbol'] = $transaction['currency_symbol'];
$groups[$groudId]['sums'][$currencyId]['currency_decimal_places'] = $transaction['currency_decimal_places'];
$groups[$groudId]['sums'][$currencyId]['amount'] = '0';
$groups[$groudId]['sums'][$currencyId]['native_amount'] = '0';
$groups[$groudId]['sums'][$currencyId]['pc_amount'] = '0';
}
$groups[$groudId]['sums'][$currencyId]['amount'] = bcadd((string) $groups[$groudId]['sums'][$currencyId]['amount'], $transaction['amount']);
$groups[$groudId]['sums'][$currencyId]['native_amount'] = bcadd((string) $groups[$groudId]['sums'][$currencyId]['native_amount'], $nativeAmount);
$groups[$groudId]['sums'][$currencyId]['pc_amount'] = bcadd((string) $groups[$groudId]['sums'][$currencyId]['pc_amount'], $pcAmount);
if (null !== $transaction['foreign_amount'] && null !== $transaction['foreign_currency_id']) {
$currencyId = (int) $transaction['foreign_currency_id'];
@@ -761,10 +761,10 @@ class GroupCollector implements GroupCollectorInterface
$groups[$groudId]['sums'][$currencyId]['currency_symbol'] = $transaction['foreign_currency_symbol'];
$groups[$groudId]['sums'][$currencyId]['currency_decimal_places'] = $transaction['foreign_currency_decimal_places'];
$groups[$groudId]['sums'][$currencyId]['amount'] = '0';
$groups[$groudId]['sums'][$currencyId]['native_amount'] = '0';
$groups[$groudId]['sums'][$currencyId]['pc_amount'] = '0';
}
$groups[$groudId]['sums'][$currencyId]['amount'] = bcadd((string) $groups[$groudId]['sums'][$currencyId]['amount'], $foreignAmount);
$groups[$groudId]['sums'][$currencyId]['native_amount'] = bcadd($groups[$groudId]['sums'][$currencyId]['amount'], $nativeForeignAmount);
$groups[$groudId]['sums'][$currencyId]['pc_amount'] = bcadd($groups[$groudId]['sums'][$currencyId]['amount'], $pcForeignAmount);
}
}
}

View File

@@ -55,7 +55,7 @@ class NetWorth implements NetWorthInterface
/**
* This method collects the user's net worth in ALL the user's currencies
* (1, 4 and 8) and also in the 'native' currency for ease of use.
* (1, 4 and 8) and also in the 'primary' currency for ease of use.
*
* The set of accounts has to be fed to it.
*
@@ -64,11 +64,11 @@ class NetWorth implements NetWorthInterface
public function byAccounts(Collection $accounts, Carbon $date): array
{
// start in the past, end in the future? use $date
$convertToNative = Amount::convertToPrimary();
$convertToPrimary = Amount::convertToPrimary();
$ids = implode(',', $accounts->pluck('id')->toArray());
$cache = new CacheProperties();
$cache->addProperty($date);
$cache->addProperty($convertToNative);
$cache->addProperty($convertToPrimary);
$cache->addProperty('net-worth-by-accounts');
$cache->addProperty($ids);
if ($cache->has()) {
@@ -84,20 +84,20 @@ class NetWorth implements NetWorthInterface
foreach ($accounts as $account) {
// Log::debug(sprintf('Now at account #%d ("%s")', $account->id, $account->name));
$currency = $this->accountRepository->getAccountCurrency($account) ?? $default;
$useNative = $convertToNative && $default->id !== $currency->id;
$currency = $useNative ? $default : $currency;
$usePrimary = $convertToPrimary && $default->id !== $currency->id;
$currency = $usePrimary ? $default : $currency;
$currencyCode = $currency->code;
$balance = '0';
$nativeBalance = '0';
$primaryBalance = '0';
if (array_key_exists($account->id, $balances)) {
$balance = $balances[$account->id]['balance'] ?? '0';
$nativeBalance = $balances[$account->id]['native_balance'] ?? '0';
$primaryBalance = $balances[$account->id]['pc_balance'] ?? '0';
}
// Log::debug(sprintf('Balance is %s, native balance is %s', $balance, $nativeBalance));
// Log::debug(sprintf('Balance is %s, primary balance is %s', $balance, $primaryBalance));
// always subtract virtual balance again.
$balance = '' !== (string) $account->virtual_balance ? bcsub($balance, (string) $account->virtual_balance) : $balance;
$nativeBalance = '' !== (string) $account->native_virtual_balance ? bcsub($nativeBalance, (string) $account->native_virtual_balance) : $nativeBalance;
$amountToUse = $useNative ? $nativeBalance : $balance;
$primaryBalance = '' !== (string) $account->native_virtual_balance ? bcsub($primaryBalance, (string) $account->native_virtual_balance) : $primaryBalance;
$amountToUse = $usePrimary ? $primaryBalance : $balance;
// Log::debug(sprintf('Will use %s %s', $currencyCode, $amountToUse));
$netWorth[$currencyCode] ??= [

View File

@@ -40,9 +40,9 @@ interface NetWorthInterface
* Collect net worth based on the given set of accounts.
*
* Returns X arrays with the net worth in each given currency, and the net worth in
* of that amount in the native currency.
* of that amount in the primary currency.
*
* Includes extra array with the total(!) net worth in the native currency.
* Includes extra array with the total(!) net worth in the primary currency.
*/
public function byAccounts(Collection $accounts, Carbon $date): array;

View File

@@ -105,7 +105,7 @@ class CreateController extends Controller
$request->session()->flash(
'preFilled',
[
'currency_id' => $this->defaultCurrency->id,
'currency_id' => $this->primaryCurrency->id,
'include_net_worth' => $hasOldInput ? (bool) $request->old('include_net_worth') : true,
]
);

View File

@@ -125,7 +125,7 @@ class EditController extends Controller
$openingBalanceAmount = '';
}
$openingBalanceDate = $repository->getOpeningBalanceDate($account);
$currency = $this->repository->getAccountCurrency($account) ?? $this->defaultCurrency;
$currency = $this->repository->getAccountCurrency($account) ?? $this->primaryCurrency;
// include this account in net-worth charts?
$includeNetWorth = $repository->getMetaValue($account, 'include_net_worth');

View File

@@ -104,14 +104,14 @@ class IndexController extends Controller
function (Account $account) use ($activities, $startBalances, $endBalances): void {
$currency = $this->repository->getAccountCurrency($account);
$account->lastActivityDate = $this->isInArrayDate($activities, $account->id);
$account->startBalances = Steam::filterAccountBalance($startBalances[$account->id] ?? [], $account, $this->convertToNative, $currency);
$account->endBalances = Steam::filterAccountBalance($endBalances[$account->id] ?? [], $account, $this->convertToNative, $currency);
$account->startBalances = Steam::filterAccountBalance($startBalances[$account->id] ?? [], $account, $this->convertToPrimary, $currency);
$account->endBalances = Steam::filterAccountBalance($endBalances[$account->id] ?? [], $account, $this->convertToPrimary, $currency);
$account->differences = $this->subtract($account->startBalances, $account->endBalances);
$account->interest = Steam::bcround($this->repository->getMetaValue($account, 'interest'), 4);
$account->interestPeriod = (string) trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period')));
$account->accountTypeString = (string) trans(sprintf('firefly.account_type_%s', $account->accountType->type));
$account->current_debt = '0';
$account->currency = $currency ?? $this->defaultCurrency;
$account->currency = $currency ?? $this->primaryCurrency;
$account->iban = implode(' ', str_split((string) $account->iban, 4));
}
);
@@ -183,8 +183,8 @@ class IndexController extends Controller
$interest = '' === $interest ? '0' : $interest;
$currency = $this->repository->getAccountCurrency($account);
$account->startBalances = Steam::filterAccountBalance($startBalances[$account->id] ?? [], $account, $this->convertToNative, $currency);
$account->endBalances = Steam::filterAccountBalance($endBalances[$account->id] ?? [], $account, $this->convertToNative, $currency);
$account->startBalances = Steam::filterAccountBalance($startBalances[$account->id] ?? [], $account, $this->convertToPrimary, $currency);
$account->endBalances = Steam::filterAccountBalance($endBalances[$account->id] ?? [], $account, $this->convertToPrimary, $currency);
$account->differences = $this->subtract($account->startBalances, $account->endBalances);
$account->lastActivityDate = $this->isInArrayDate($activities, $account->id);
$account->interest = Steam::bcround($interest, 4);
@@ -195,7 +195,7 @@ class IndexController extends Controller
$account->location = $this->repository->getLocation($account);
$account->liability_direction = $this->repository->getMetaValue($account, 'liability_direction');
$account->current_debt = $this->repository->getMetaValue($account, 'current_debt') ?? '-';
$account->currency = $currency ?? $this->defaultCurrency;
$account->currency = $currency ?? $this->primaryCurrency;
$account->iban = implode(' ', str_split((string) $account->iban, 4));

View File

@@ -87,7 +87,7 @@ class ReconcileController extends Controller
return redirect(route('accounts.index', [config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type))]));
}
$currency = $this->accountRepos->getAccountCurrency($account) ?? $this->defaultCurrency;
$currency = $this->accountRepos->getAccountCurrency($account) ?? $this->primaryCurrency;
// no start or end:
$range = app('navigation')->getViewRange(false);
@@ -204,7 +204,7 @@ class ReconcileController extends Controller
}
$reconciliation = $this->accountRepos->getReconciliation($account);
$currency = $this->accountRepos->getAccountCurrency($account) ?? $this->defaultCurrency;
$currency = $this->accountRepos->getAccountCurrency($account) ?? $this->primaryCurrency;
$source = $reconciliation;
$destination = $account;
if (1 === bccomp($difference, '0')) {

View File

@@ -108,7 +108,7 @@ class ShowController extends Controller
$page = (int) $request->get('page');
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$accountCurrency = $this->repository->getAccountCurrency($account);
$currency = $accountCurrency ?? $this->defaultCurrency;
$currency = $accountCurrency ?? $this->primaryCurrency;
$fStart = $start->isoFormat($this->monthAndDayFormat);
$fEnd = $end->isoFormat($this->monthAndDayFormat);
$subTitle = (string) trans('firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $fStart, 'end' => $fEnd]);
@@ -165,7 +165,7 @@ class ShowController extends Controller
}
Log::debug(sprintf('show: Call finalAccountBalance with date/time "%s"', $now->toIso8601String()));
$balances = Steam::filterAccountBalance(Steam::finalAccountBalance($account, $now), $account, $this->convertToNative, $accountCurrency);
$balances = Steam::filterAccountBalance(Steam::finalAccountBalance($account, $now), $account, $this->convertToPrimary, $accountCurrency);
return view(
'accounts.show',
@@ -212,7 +212,7 @@ class ShowController extends Controller
$subTitleIcon = config('firefly.subIconsByIdentifier.'.$account->accountType->type);
$page = (int) $request->get('page');
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$currency = $this->repository->getAccountCurrency($account) ?? $this->defaultCurrency;
$currency = $this->repository->getAccountCurrency($account) ?? $this->primaryCurrency;
$subTitle = (string) trans('firefly.all_journals_for_account', ['name' => $account->name]);
$periods = new Collection();
@@ -232,7 +232,7 @@ class ShowController extends Controller
$showAll = true;
// correct
Log::debug(sprintf('showAll: Call finalAccountBalance with date/time "%s"', $end->toIso8601String()));
$balances = Steam::filterAccountBalance(Steam::finalAccountBalance($account, $end), $account, $this->convertToNative, $accountCurrency);
$balances = Steam::filterAccountBalance(Steam::finalAccountBalance($account, $end), $account, $this->convertToPrimary, $accountCurrency);
return view(
'accounts.show',

View File

@@ -77,7 +77,7 @@ class CreateController extends Controller
$periods[$current] = (string) trans('firefly.repeat_freq_'.$current);
}
$subTitle = (string) trans('firefly.create_new_bill');
$defaultCurrency = $this->defaultCurrency;
$defaultCurrency = $this->primaryCurrency;
// put previous url in session if not redirect from store (not "create another").
if (true !== session('bills.create.fromStore')) {

View File

@@ -88,7 +88,7 @@ class EditController extends Controller
$bill->amount_min = app('steam')->bcround($bill->amount_min, $bill->transactionCurrency->decimal_places);
$bill->amount_max = app('steam')->bcround($bill->amount_max, $bill->transactionCurrency->decimal_places);
$rules = $this->repository->getRulesForBill($bill);
$defaultCurrency = $this->defaultCurrency;
$defaultCurrency = $this->primaryCurrency;
// code to handle active-checkboxes
$hasOldInput = null !== $request->old('_token');

View File

@@ -91,8 +91,8 @@ class IndexController extends Controller
$admin = auth()->user();
$enrichment = new SubscriptionEnrichment();
$enrichment->setUser($admin);
$enrichment->setConvertToNative($this->convertToNative);
$enrichment->setNative($this->defaultCurrency);
$enrichment->setConvertToPrimary($this->convertToPrimary);
$enrichment->setPrimary($this->primaryCurrency);
$enrichment->setStart($tempStart);
$enrichment->setEnd($end);
$collection = $enrichment->enrich($collection);
@@ -100,8 +100,8 @@ class IndexController extends Controller
$parameters->set('start', $tempStart);
$parameters->set('end', $end);
$parameters->set('convertToNative', $this->convertToNative);
$parameters->set('defaultCurrency', $this->defaultCurrency);
$parameters->set('convertToPrimary', $this->convertToPrimary);
$parameters->set('defaultCurrency', $this->primaryCurrency);
/** @var BillTransformer $transformer */
$transformer = app(BillTransformer::class);
@@ -130,7 +130,7 @@ class IndexController extends Controller
'bills' => [],
];
$currency = $bill->transactionCurrency ?? $this->defaultCurrency;
$currency = $bill->transactionCurrency ?? $this->primaryCurrency;
$array['currency_id'] = $currency->id;
$array['currency_name'] = $currency->name;
$array['currency_symbol'] = $currency->symbol;

View File

@@ -149,8 +149,8 @@ class ShowController extends Controller
$admin = auth()->user();
$enrichment = new SubscriptionEnrichment();
$enrichment->setUser($admin);
$enrichment->setConvertToNative($this->convertToNative);
$enrichment->setNative($this->defaultCurrency);
$enrichment->setConvertToPrimary($this->convertToPrimary);
$enrichment->setPrimary($this->primaryCurrency);
$enrichment->setStart($start);
$enrichment->setEnd($end);
$bill = $enrichment->enrichSingle($bill);

View File

@@ -89,7 +89,7 @@ class CreateController extends Controller
$preFilled = [
'auto_budget_period' => $hasOldInput ? (bool) $request->old('auto_budget_period') : 'monthly',
'auto_budget_currency_id' => $hasOldInput ? (int) $request->old('auto_budget_currency_id') : $this->defaultCurrency->id,
'auto_budget_currency_id' => $hasOldInput ? (int) $request->old('auto_budget_currency_id') : $this->primaryCurrency->id,
];
$request->session()->flash('preFilled', $preFilled);

View File

@@ -94,7 +94,7 @@ class EditController extends Controller
$hasOldInput = null !== $request->old('_token');
$preFilled = [
'active' => $hasOldInput ? (bool) $request->old('active') : $budget->active,
'auto_budget_currency_id' => $hasOldInput ? (int) $request->old('auto_budget_currency_id') : $this->defaultCurrency->id,
'auto_budget_currency_id' => $hasOldInput ? (int) $request->old('auto_budget_currency_id') : $this->primaryCurrency->id,
];
if ($autoBudget instanceof AutoBudget) {
$amount = $hasOldInput ? $request->old('auto_budget_amount') : $autoBudget->amount;

View File

@@ -119,14 +119,14 @@ class IndexController extends Controller
// get all available budgets:
$availableBudgets = $this->getAllAvailableBudgets($start, $end);
// get all active budgets:
$budgets = $this->getAllBudgets($start, $end, $currencies, $this->defaultCurrency);
$budgets = $this->getAllBudgets($start, $end, $currencies, $this->primaryCurrency);
$sums = $this->getSums($budgets);
// get budgeted for default currency:
if (0 === count($availableBudgets)) {
$budgeted = $this->blRepository->budgeted($start, $end, $this->defaultCurrency);
$spentArr = $this->opsRepository->sumExpenses($start, $end, null, null, $this->defaultCurrency);
$spent = $spentArr[$this->defaultCurrency->id]['sum'] ?? '0';
$budgeted = $this->blRepository->budgeted($start, $end, $this->primaryCurrency);
$spentArr = $this->opsRepository->sumExpenses($start, $end, null, null, $this->primaryCurrency);
$spent = $spentArr[$this->primaryCurrency->id]['sum'] ?? '0';
unset($spentArr);
}
@@ -136,7 +136,7 @@ class IndexController extends Controller
// get all inactive budgets, and simply list them:
$inactive = $this->repository->getInactiveBudgets();
$defaultCurrency = $this->defaultCurrency;
$defaultCurrency = $this->primaryCurrency;
return view(
'budgets.index',
@@ -179,11 +179,11 @@ class IndexController extends Controller
// spent in period:
$spentArr = $this->opsRepository->sumExpenses($entry->start_date, $entry->end_date, null, null, $entry->transactionCurrency, false);
$array['spent'] = $spentArr[$entry->transaction_currency_id]['sum'] ?? '0';
$array['native_spent'] = $this->convertToNative && $entry->transaction_currency_id !== $this->defaultCurrency->id ? $converter->convert($entry->transactionCurrency, $this->defaultCurrency, $entry->start_date, $array['spent']) : null;
$array['pc_spent'] = $this->convertToPrimary && $entry->transaction_currency_id !== $this->primaryCurrency->id ? $converter->convert($entry->transactionCurrency, $this->primaryCurrency, $entry->start_date, $array['spent']) : null;
// budgeted in period:
$budgeted = $this->blRepository->budgeted($entry->start_date, $entry->end_date, $entry->transactionCurrency);
$array['budgeted'] = $budgeted;
$array['native_budgeted'] = $this->convertToNative && $entry->transaction_currency_id !== $this->defaultCurrency->id ? $converter->convert($entry->transactionCurrency, $this->defaultCurrency, $entry->start_date, $budgeted) : null;
$array['pc_budgeted'] = $this->convertToPrimary && $entry->transaction_currency_id !== $this->primaryCurrency->id ? $converter->convert($entry->transactionCurrency, $this->primaryCurrency, $entry->start_date, $budgeted) : null;
// this time, because of complex sums, use the currency converter.

View File

@@ -188,8 +188,8 @@ class ShowController extends Controller
'currency' => $budgetLimit->transactionCurrency->name,
]
);
if ($this->convertToNative) {
$currencySymbol = $this->defaultCurrency->symbol;
if ($this->convertToPrimary) {
$currencySymbol = $this->primaryCurrency->symbol;
}
// collector:

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'];

View File

@@ -55,9 +55,9 @@ abstract class Controller extends BaseController
// fails on PHP < 8.4
public protected(set) string $name;
protected bool $convertToNative = false;
protected bool $convertToPrimary = false;
protected string $dateTimeFormat;
protected ?TransactionCurrency $defaultCurrency;
protected ?TransactionCurrency $primaryCurrency;
protected string $monthAndDayFormat;
protected string $monthFormat;
protected string $redirectUrl = '/';
@@ -125,19 +125,19 @@ abstract class Controller extends BaseController
$this->monthAndDayFormat = (string) trans('config.month_and_day_js', [], $locale);
$this->dateTimeFormat = (string) trans('config.date_time_js', [], $locale);
$darkMode = 'browser';
$this->defaultCurrency = null;
$this->primaryCurrency = null;
// get shown-intro-preference:
if (auth()->check()) {
$this->defaultCurrency = Amount::getPrimaryCurrency();
$this->primaryCurrency = Amount::getPrimaryCurrency();
$language = Steam::getLanguage();
$locale = Steam::getLocale();
$darkMode = app('preferences')->get('darkMode', 'browser')->data;
$this->convertToNative = Amount::convertToPrimary();
$this->convertToPrimary = Amount::convertToPrimary();
$page = $this->getPageName();
$shownDemo = $this->hasSeenDemo();
View::share('language', $language);
View::share('locale', $locale);
View::share('convertToNative', $this->convertToNative);
View::share('convertToPrimary', $this->convertToPrimary);
View::share('shownDemo', $shownDemo);
View::share('current_route_name', $page);
View::share('original_route_name', Route::currentRouteName());

View File

@@ -285,8 +285,8 @@ class DebugController extends Controller
'user_count' => User::count(),
'user_flags' => $userFlags,
'user_agent' => $userAgent,
'native' => Amount::getPrimaryCurrency(),
'convert_to_native' => Amount::convertToPrimary(),
'primary' => Amount::getPrimaryCurrency(),
'convert_to_primary' => Amount::convertToPrimary(),
'locale_attempts' => $localeAttempts,
'locale' => Steam::getLocale(),
'language' => Steam::getLanguage(),

View File

@@ -55,7 +55,7 @@ class JavascriptController extends Controller
foreach ($accounts as $account) {
$accountId = $account->id;
$currency = (int) $repository->getMetaValue($account, 'currency_id');
$currency = 0 === $currency ? $this->defaultCurrency->id : $currency;
$currency = 0 === $currency ? $this->primaryCurrency->id : $currency;
$entry = ['preferredCurrency' => $currency, 'name' => $account->name];
$data['accounts'][$accountId] = $entry;
}
@@ -95,9 +95,9 @@ class JavascriptController extends Controller
public function variables(Request $request, AccountRepositoryInterface $repository): Response
{
$account = $repository->find((int) $request->get('account'));
$currency = $this->defaultCurrency;
$currency = $this->primaryCurrency;
if ($account instanceof Account) {
$currency = $repository->getAccountCurrency($account) ?? $this->defaultCurrency;
$currency = $repository->getAccountCurrency($account) ?? $this->primaryCurrency;
}
$locale = app('steam')->getLocale();
$accounting = app('amount')->getJsConfig();

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()));

View File

@@ -148,7 +148,7 @@ class IndexController extends Controller
// enrich each account.
$enrichment = new AccountEnrichment();
$enrichment->setUser(auth()->user());
$enrichment->setNative($this->defaultCurrency);
$enrichment->setPrimary($this->primaryCurrency);
$return = [];
/** @var PiggyBank $piggy */

View File

@@ -112,7 +112,7 @@ class PreferencesController extends Controller
$darkMode = Preferences::get('darkMode', 'browser')->data;
$customFiscalYear = Preferences::get('customFiscalYear', 0)->data;
$fiscalYearStartStr = Preferences::get('fiscalYearStart', '01-01')->data;
$convertToNative = $this->convertToNative;
$convertToPrimary = $this->convertToPrimary;
if (is_array($fiscalYearStartStr)) {
$fiscalYearStartStr = '01-01';
}
@@ -198,7 +198,7 @@ class PreferencesController extends Controller
'darkMode',
'availableDarkModes',
'notifications',
'convertToNative',
'convertToPrimary',
'slackUrl',
'locales',
'locale',
@@ -265,15 +265,15 @@ class PreferencesController extends Controller
Preferences::set('ntfy_auth', $all['ntfy_auth'] ?? false);
}
// convert native
$convertToNative = 1 === (int) $request->get('convertToNative');
if ($convertToNative && !$this->convertToNative) {
// convert primary
$convertToPrimary = 1 === (int) $request->get('convertToPrimary');
if ($convertToPrimary && !$this->convertToPrimary) {
// set to true!
Log::debug('User sets convertToNative to true.');
Preferences::set('convert_to_native', $convertToNative);
Log::debug('User sets convertToPrimary to true.');
Preferences::set('convert_to_primary', $convertToPrimary);
event(new UserGroupChangedDefaultCurrency(auth()->user()->userGroup));
}
Preferences::set('convert_to_native', $convertToNative);
Preferences::set('convert_to_primary', $convertToPrimary);
// custom fiscal year
$customFiscalYear = 1 === (int) $request->get('customFiscalYear');

View File

@@ -84,7 +84,7 @@ class CreateController extends Controller
{
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgetRepos->getActiveBudgets());
$bills = app('expandedform')->makeSelectListWithEmpty($this->billRepository->getActiveBills());
$defaultCurrency = $this->defaultCurrency;
$defaultCurrency = $this->primaryCurrency;
$tomorrow = today(config('app.timezone'));
$oldRepetitionType = $request->old('repetition_type');
$tomorrow->addDay();
@@ -129,7 +129,7 @@ class CreateController extends Controller
{
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgetRepos->getActiveBudgets());
$bills = app('expandedform')->makeSelectListWithEmpty($this->billRepository->getActiveBills());
$defaultCurrency = $this->defaultCurrency;
$defaultCurrency = $this->primaryCurrency;
$tomorrow = today(config('app.timezone'));
$oldRepetitionType = $request->old('repetition_type');
$tomorrow->addDay();

View File

@@ -228,7 +228,7 @@ class ConvertController extends Controller
$date = today()->endOfDay();
Log::debug(sprintf('getLiabilities: Call finalAccountBalance with date/time "%s"', $date->toIso8601String()));
$balance = Steam::finalAccountBalance($account, $date)['balance'];
$currency = $this->accountRepository->getAccountCurrency($account) ?? $this->defaultCurrency;
$currency = $this->accountRepository->getAccountCurrency($account) ?? $this->primaryCurrency;
$role = 'l_'.$account->accountType->type;
$key = (string) trans('firefly.opt_group_'.$role);
$grouped[$key][$account->id] = $account->name.' ('.app('amount')->formatAnything($currency, $balance, false).')';
@@ -252,7 +252,7 @@ class ConvertController extends Controller
$date = today()->endOfDay();
Log::debug(sprintf('getAssetAccounts: Call finalAccountBalance with date/time "%s"', $date->toIso8601String()));
$balance = Steam::finalAccountBalance($account, $date)['balance'];
$currency = $this->accountRepository->getAccountCurrency($account) ?? $this->defaultCurrency;
$currency = $this->accountRepository->getAccountCurrency($account) ?? $this->primaryCurrency;
$role = (string) $this->accountRepository->getMetaValue($account, 'account_role');
if ('' === $role) {
$role = 'no_account_type';

View File

@@ -117,7 +117,7 @@ class CreateController extends Controller
$optionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
$allowedOpposingTypes = config('firefly.allowed_opposing_types');
$accountToTypes = config('firefly.account_to_transaction');
$defaultCurrency = $this->defaultCurrency;
$defaultCurrency = $this->primaryCurrency;
$previousUrl = $this->rememberPreviousUrl('transactions.create.url');
$parts = parse_url((string) $previousUrl);
$search = sprintf('?%s', $parts['query'] ?? '');

View File

@@ -84,7 +84,7 @@ class EditController extends Controller
$title = $transactionGroup->transactionJournals()->count() > 1 ? $transactionGroup->title : $transactionGroup->transactionJournals()->first()->description;
$subTitle = (string) trans('firefly.edit_transaction_title', ['description' => $title]);
$subTitleIcon = 'fa-plus';
$defaultCurrency = $this->defaultCurrency;
$defaultCurrency = $this->primaryCurrency;
$cash = $repository->getCashAccount();
$previousUrl = $this->rememberPreviousUrl('transactions.edit.url');
$parts = parse_url((string) $previousUrl);

View File

@@ -74,10 +74,10 @@ class IndexController extends Controller
// order so default and enabled are on top:
$collection = $collection->sortBy(
static function (TransactionCurrency $currency) {
$native = true === $currency->userGroupNative ? 0 : 1;
$primary = true === $currency->userGroupNative ? 0 : 1;
$enabled = true === $currency->userGroupEnabled ? 0 : 1;
return sprintf('%s-%s-%s', $native, $enabled, $currency->code);
return sprintf('%s-%s-%s', $primary, $enabled, $currency->code);
}
);
$total = $collection->count();

View File

@@ -258,7 +258,7 @@ class EventServiceProvider extends ServiceProvider
],
// preferences
UserGroupChangedDefaultCurrency::class => [
'FireflyIII\Handlers\Events\PreferencesEventHandler@resetNativeAmounts',
'FireflyIII\Handlers\Events\PreferencesEventHandler@resetPrimaryCurrencyAmounts',
],
];

View File

@@ -295,7 +295,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
/**
* Returns the amount of the opening balance for this account.
*/
public function getOpeningBalanceAmount(Account $account, bool $convertToNative): ?string
public function getOpeningBalanceAmount(Account $account, bool $convertToPrimary): ?string
{
$journal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.account_id', $account->id)
@@ -309,7 +309,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
if (null === $transaction) {
return null;
}
if ($convertToNative) {
if ($convertToPrimary) {
return $transaction->native_amount ?? '0';
}

View File

@@ -117,7 +117,7 @@ interface AccountRepositoryInterface
/**
* Returns the amount of the opening balance for this account.
*/
public function getOpeningBalanceAmount(Account $account, bool $convertToNative): ?string;
public function getOpeningBalanceAmount(Account $account, bool $convertToPrimary): ?string;
/**
* Return date of opening balance as string or null.

View File

@@ -58,7 +58,7 @@ class AccountTasker implements AccountTaskerInterface, UserGroupInterface
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$defaultCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
$primaryCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
$return = [
'accounts' => [],
@@ -68,7 +68,7 @@ class AccountTasker implements AccountTaskerInterface, UserGroupInterface
/** @var Account $account */
foreach ($accounts as $account) {
$id = $account->id;
$currency = $repository->getAccountCurrency($account) ?? $defaultCurrency;
$currency = $repository->getAccountCurrency($account) ?? $primaryCurrency;
$return['sums'][$currency->id] ??= [
'start' => '0',
'end' => '0',
@@ -148,11 +148,11 @@ class AccountTasker implements AccountTaskerInterface, UserGroupInterface
*/
private function groupExpenseByDestination(array $array): array
{
$defaultCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
$primaryCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
/** @var CurrencyRepositoryInterface $currencyRepos */
$currencyRepos = app(CurrencyRepositoryInterface::class);
$currencies = [$defaultCurrency->id => $defaultCurrency];
$currencies = [$primaryCurrency->id => $primaryCurrency];
$report = [
'accounts' => [],
'sums' => [],
@@ -236,11 +236,11 @@ class AccountTasker implements AccountTaskerInterface, UserGroupInterface
*/
private function groupIncomeBySource(array $array): array
{
$defaultCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
$primaryCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
/** @var CurrencyRepositoryInterface $currencyRepos */
$currencyRepos = app(CurrencyRepositoryInterface::class);
$currencies = [$defaultCurrency->id => $defaultCurrency];
$currencies = [$primaryCurrency->id => $primaryCurrency];
$report = [
'accounts' => [],
'sums' => [],

View File

@@ -264,19 +264,19 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
$currency = $journal->transactionCurrency;
$result[$currencyId] ??= [
'sum' => '0',
'native_sum' => '0',
'pc_sum' => '0',
'count' => 0,
'avg' => '0',
'native_avg' => '0',
'pc_avg' => '0',
'currency_id' => $currency->id,
'currency_code' => $currency->code,
'currency_symbol' => $currency->symbol,
'currency_decimal_places' => $currency->decimal_places,
];
$result[$currencyId]['sum'] = bcadd($result[$currencyId]['sum'], (string) $transaction->amount);
$result[$currencyId]['native_sum'] = bcadd($result[$currencyId]['native_sum'], $transaction->native_amount ?? '0');
$result[$currencyId]['pc_sum'] = bcadd($result[$currencyId]['pc_sum'], $transaction->native_amount ?? '0');
if ($journal->foreign_currency_id === Amount::getPrimaryCurrency()->id) {
$result[$currencyId]['native_sum'] = bcadd($result[$currencyId]['native_sum'], (string) $transaction->amount);
$result[$currencyId]['pc_sum'] = bcadd($result[$currencyId]['pc_sum'], (string) $transaction->amount);
}
++$result[$currencyId]['count'];
}
@@ -288,7 +288,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
*/
foreach ($result as $currencyId => $arr) {
$result[$currencyId]['avg'] = bcdiv((string) $arr['sum'], (string) $arr['count']);
$result[$currencyId]['native_avg'] = bcdiv((string) $arr['native_sum'], (string) $arr['count']);
$result[$currencyId]['pc_avg'] = bcdiv((string) $arr['pc_sum'], (string) $arr['count']);
}
return $result;
@@ -401,7 +401,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
$currency = $journal->transactionCurrency;
$result[$currencyId] ??= [
'sum' => '0',
'native_sum' => '0',
'pc_sum' => '0',
'count' => 0,
'avg' => '0',
'currency_id' => $currency->id,
@@ -410,9 +410,9 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
'currency_decimal_places' => $currency->decimal_places,
];
$result[$currencyId]['sum'] = bcadd($result[$currencyId]['sum'], (string) $transaction->amount);
$result[$currencyId]['native_sum'] = bcadd($result[$currencyId]['native_sum'], $transaction->native_amount ?? '0');
$result[$currencyId]['pc_sum'] = bcadd($result[$currencyId]['pc_sum'], $transaction->native_amount ?? '0');
if ($journal->foreign_currency_id === Amount::getPrimaryCurrency()->id) {
$result[$currencyId]['native_sum'] = bcadd($result[$currencyId]['native_sum'], (string) $transaction->amount);
$result[$currencyId]['pc_sum'] = bcadd($result[$currencyId]['pc_sum'], (string) $transaction->amount);
}
++$result[$currencyId]['count'];
}
@@ -424,7 +424,7 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
*/
foreach ($result as $currencyId => $arr) {
$result[$currencyId]['avg'] = bcdiv((string) $arr['sum'], (string) $arr['count']);
$result[$currencyId]['native_avg'] = bcdiv((string) $arr['native_sum'], (string) $arr['count']);
$result[$currencyId]['pc_avg'] = bcdiv((string) $arr['pc_sum'], (string) $arr['count']);
}
return $result;
@@ -534,15 +534,15 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
Log::debug(sprintf('sumPaidInRange from %s to %s', $start->toW3cString(), $end->toW3cString()));
$bills = $this->getActiveBills();
$return = [];
$convertToNative = Amount::convertToPrimary($this->user);
$default = app('amount')->getPrimaryCurrency();
$convertToPrimary = Amount::convertToPrimary($this->user);
$primary = app('amount')->getPrimaryCurrency();
/** @var Bill $bill */
foreach ($bills as $bill) {
/** @var Collection $set */
$set = $bill->transactionJournals()->after($start)->before($end)->get(['transaction_journals.*']);
$currency = $convertToNative && $bill->transactionCurrency->id !== $default->id ? $default : $bill->transactionCurrency;
$currency = $convertToPrimary && $bill->transactionCurrency->id !== $primary->id ? $primary : $bill->transactionCurrency;
$return[(int) $currency->id] ??= [
'id' => (string) $currency->id,
'name' => $currency->name,
@@ -600,8 +600,8 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
app('log')->debug(sprintf('Now in sumUnpaidInRange("%s", "%s")', $start->format('Y-m-d'), $end->format('Y-m-d')));
$bills = $this->getActiveBills();
$return = [];
$convertToNative = Amount::convertToPrimary($this->user);
$default = app('amount')->getPrimaryCurrency();
$convertToPrimary = Amount::convertToPrimary($this->user);
$primary = app('amount')->getPrimaryCurrency();
/** @var Bill $bill */
foreach ($bills as $bill) {
@@ -612,12 +612,12 @@ class BillRepository implements BillRepositoryInterface, UserGroupInterface
// app('log')->debug(sprintf('Pay dates: %d, count: %d, left: %d', $dates->count(), $count, $total));
// app('log')->debug('dates', $dates->toArray());
$minField = $convertToNative && $bill->transactionCurrency->id !== $default->id ? 'native_amount_min' : 'amount_min';
$maxField = $convertToNative && $bill->transactionCurrency->id !== $default->id ? 'native_amount_max' : 'amount_max';
$minField = $convertToPrimary && $bill->transactionCurrency->id !== $primary->id ? 'native_amount_min' : 'amount_min';
$maxField = $convertToPrimary && $bill->transactionCurrency->id !== $primary->id ? 'native_amount_max' : 'amount_max';
// Log::debug(sprintf('min field is %s, max field is %s', $minField, $maxField));
if ($total > 0) {
$currency = $convertToNative && $bill->transactionCurrency->id !== $default->id ? $default : $bill->transactionCurrency;
$currency = $convertToPrimary && $bill->transactionCurrency->id !== $primary->id ? $primary : $bill->transactionCurrency;
$average = bcdiv(bcadd($bill->{$maxField} ?? '0', $bill->{$minField} ?? '0'), '2');
Log::debug(sprintf('Amount to pay is %s %s (%d times)', $currency->code, $average, $total));
$return[$currency->id] ??= [

View File

@@ -141,14 +141,14 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface, U
Log::debug(sprintf('Found %d available budgets (already converted)', $availableBudgets->count()));
// use native amount if necessary?
$convertToNative = Amount::convertToPrimary($this->user);
$default = Amount::getPrimaryCurrency();
// use primary amount if necessary?
$convertToPrimary = Amount::convertToPrimary($this->user);
$primary = Amount::getPrimaryCurrency();
/** @var AvailableBudget $availableBudget */
foreach ($availableBudgets as $availableBudget) {
$currencyId = $convertToNative && $availableBudget->transaction_currency_id !== $default->id ? $default->id : $availableBudget->transaction_currency_id;
$field = $convertToNative && $availableBudget->transaction_currency_id !== $default->id ? 'native_amount' : 'amount';
$currencyId = $convertToPrimary && $availableBudget->transaction_currency_id !== $primary->id ? $primary->id : $availableBudget->transaction_currency_id;
$field = $convertToPrimary && $availableBudget->transaction_currency_id !== $primary->id ? 'native_amount' : 'amount';
$return[$currencyId] ??= '0';
$amount = '' === (string) $availableBudget->{$field} ? '0' : (string) $availableBudget->{$field};
$return[$currencyId] = bcadd($return[$currencyId], $amount);

View File

@@ -91,7 +91,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
$limitRepository = app(BudgetLimitRepository::class);
$limitRepository->setUser($this->user);
$budgets = $this->getActiveBudgets();
$defaultCurrency = app('amount')->getPrimaryCurrency();
$primaryCurrency = app('amount')->getPrimaryCurrency();
$converter = new ExchangeRateConverter();
/** @var Budget $budget */
@@ -103,7 +103,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
foreach ($limits as $limit) {
app('log')->debug(sprintf('Budget limit #%d', $limit->id));
$currency = $limit->transactionCurrency;
$rate = $converter->getCurrencyRate($currency, $defaultCurrency, $end);
$rate = $converter->getCurrencyRate($currency, $primaryCurrency, $end);
$currencyCode = $currency->code;
$return[$currencyCode] ??= [
'currency_id' => (string) $currency->id,
@@ -111,18 +111,18 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code,
'currency_decimal_places' => $currency->decimal_places,
'native_currency_id' => (string) $defaultCurrency->id,
'native_currency_name' => $defaultCurrency->name,
'native_currency_symbol' => $defaultCurrency->symbol,
'native_currency_code' => $defaultCurrency->code,
'native_currency_decimal_places' => $defaultCurrency->decimal_places,
'primary_currency_id' => (string) $primaryCurrency->id,
'primary_currency_name' => $primaryCurrency->name,
'primary_currency_symbol' => $primaryCurrency->symbol,
'primary_currency_code' => $primaryCurrency->code,
'primary_currency_decimal_places' => $primaryCurrency->decimal_places,
'sum' => '0',
'native_sum' => '0',
'pc_sum' => '0',
];
// same period
if ($limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end)) {
$return[$currencyCode]['sum'] = bcadd($return[$currencyCode]['sum'], (string) $limit->amount);
$return[$currencyCode]['native_sum'] = bcmul($rate, $return[$currencyCode]['sum']);
$return[$currencyCode]['pc_sum'] = bcmul($rate, $return[$currencyCode]['sum']);
app('log')->debug(sprintf('Add full amount [1]: %s', $limit->amount));
continue;
@@ -130,7 +130,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
// limit is inside of date range
if ($start->lte($limit->start_date) && $end->gte($limit->end_date)) {
$return[$currencyCode]['sum'] = bcadd($return[$currencyCode]['sum'], (string) $limit->amount);
$return[$currencyCode]['native_sum'] = bcmul($rate, $return[$currencyCode]['sum']);
$return[$currencyCode]['pc_sum'] = bcmul($rate, $return[$currencyCode]['sum']);
app('log')->debug(sprintf('Add full amount [2]: %s', $limit->amount));
continue;
@@ -139,7 +139,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
$days = $this->daysInOverlap($limit, $start, $end);
$amount = bcmul(bcdiv((string) $limit->amount, (string) $total), (string) $days);
$return[$currencyCode]['sum'] = bcadd($return[$currencyCode]['sum'], $amount);
$return[$currencyCode]['native_sum'] = bcmul($rate, $return[$currencyCode]['sum']);
$return[$currencyCode]['pc_sum'] = bcmul($rate, $return[$currencyCode]['sum']);
app('log')->debug(
sprintf(
'Amount per day: %s (%s over %d days). Total amount for %d days: %s',

View File

@@ -141,32 +141,32 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
$journals = $collector->getExtractedJournals();
$array = [];
// if needs conversion to native.
$convertToNative = Amount::convertToPrimary($this->user);
$nativeCurrency = Amount::getPrimaryCurrencyByUserGroup($this->userGroup);
$currencyId = (int) $nativeCurrency->id;
$currencyCode = $nativeCurrency->code;
$currencyName = $nativeCurrency->name;
$currencySymbol = $nativeCurrency->symbol;
$currencyDecimalPlaces = $nativeCurrency->decimal_places;
// if needs conversion to primary.
$convertToPrimary = Amount::convertToPrimary($this->user);
$primaryCurrency = Amount::getPrimaryCurrencyByUserGroup($this->userGroup);
$currencyId = (int) $primaryCurrency->id;
$currencyCode = $primaryCurrency->code;
$currencyName = $primaryCurrency->name;
$currencySymbol = $primaryCurrency->symbol;
$currencyDecimalPlaces = $primaryCurrency->decimal_places;
$converter = new ExchangeRateConverter();
$currencies = [
$currencyId => $nativeCurrency,
$currencyId => $primaryCurrency,
];
foreach ($journals as $journal) {
$amount = app('steam')->negative($journal['amount']);
$journalCurrencyId = (int)$journal['currency_id'];
if (false === $convertToNative) {
if (false === $convertToPrimary) {
$currencyId = $journalCurrencyId;
$currencyName = $journal['currency_name'];
$currencySymbol = $journal['currency_symbol'];
$currencyCode = $journal['currency_code'];
$currencyDecimalPlaces = $journal['currency_decimal_places'];
}
if (true === $convertToNative && $journalCurrencyId !== $currencyId) {
if (true === $convertToPrimary && $journalCurrencyId !== $currencyId) {
$currencies[$journalCurrencyId] ??= TransactionCurrency::find($journalCurrencyId);
$amount = $converter->convert($currencies[$journalCurrencyId], $nativeCurrency, $journal['date'], $amount);
$amount = $converter->convert($currencies[$journalCurrencyId], $primaryCurrency, $journal['date'], $amount);
}
$budgetId = (int)$journal['budget_id'];
@@ -230,9 +230,9 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
?Collection $accounts = null,
?Collection $budgets = null,
?TransactionCurrency $currency = null,
bool $convertToNative = false
bool $convertToPrimary = false
): array {
Log::debug(sprintf('Start of %s(date, date, array, array, "%s", %s).', __METHOD__, $currency?->code, var_export($convertToNative, true)));
Log::debug(sprintf('Start of %s(date, date, array, array, "%s", %s).', __METHOD__, $currency?->code, var_export($convertToPrimary, true)));
// this collector excludes all transfers TO liabilities (which are also withdrawals)
// because those expenses only become expenses once they move from the liability to the friend.
// 2024-12-24 disable the exclusion for now.
@@ -277,8 +277,8 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
Log::debug('STOP looking for transactions in the foreign currency.');
}
$summarizer = new TransactionSummarizer($this->user);
// 2025-04-21 overrule "convertToNative" because in this particular view, we never want to do this.
$summarizer->setConvertToNative($convertToNative);
// 2025-04-21 overrule "convertToPrimary" because in this particular view, we never want to do this.
$summarizer->setConvertToPrimary($convertToPrimary);
return $summarizer->groupByCurrencyId($journals, 'negative', false);
}

View File

@@ -71,6 +71,6 @@ interface OperationsRepositoryInterface
?Collection $accounts = null,
?Collection $budgets = null,
?TransactionCurrency $currency = null,
bool $convertToNative = false
bool $convertToPrimary = false
): array;
}

View File

@@ -358,8 +358,8 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
}
$collector->setCategories($categories);
$journals = $collector->getExtractedJournals();
$convertToNative = Amount::convertToPrimary($this->user);
$default = Amount::getPrimaryCurrency();
$convertToPrimary = Amount::convertToPrimary($this->user);
$primary = Amount::getPrimaryCurrency();
$array = [];
foreach ($journals as $journal) {
@@ -370,16 +370,16 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
$currencySymbol = $journal['currency_symbol'];
$currencyCode = $journal['currency_code'];
$currencyDecimalPlaces = $journal['currency_decimal_places'];
if ($convertToNative) {
if ($convertToPrimary) {
$amount = Amount::getAmountFromJournal($journal);
if ($default->id !== (int) $journal['currency_id'] && $default->id !== (int) $journal['foreign_currency_id']) {
$currencyId = $default->id;
$currencyName = $default->name;
$currencySymbol = $default->symbol;
$currencyCode = $default->code;
$currencyDecimalPlaces = $default->decimal_places;
if ($primary->id !== (int) $journal['currency_id'] && $primary->id !== (int) $journal['foreign_currency_id']) {
$currencyId = $primary->id;
$currencyName = $primary->name;
$currencySymbol = $primary->symbol;
$currencyCode = $primary->code;
$currencyDecimalPlaces = $primary->decimal_places;
}
if ($default->id !== (int) $journal['currency_id'] && $default->id === (int) $journal['foreign_currency_id']) {
if ($primary->id !== (int) $journal['currency_id'] && $primary->id === (int) $journal['foreign_currency_id']) {
$currencyId = $journal['foreign_currency_id'];
$currencyName = $journal['foreign_currency_name'];
$currencySymbol = $journal['foreign_currency_symbol'];
@@ -388,7 +388,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
}
Log::debug(sprintf('[a] Add amount %s %s', $currencyCode, $amount));
}
if (!$convertToNative) {
if (!$convertToPrimary) {
// ignore the amount in foreign currency.
Log::debug(sprintf('[b] Add amount %s %s', $currencyCode, $journal['amount']));
$amount = $journal['amount'];

View File

@@ -183,9 +183,9 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
return $all->map(static function (TransactionCurrency $current) use ($local) {
$hasId = $local->contains(static fn (TransactionCurrency $entry) => $entry->id === $current->id);
$isNative = $local->contains(static fn (TransactionCurrency $entry) => 1 === (int) $entry->pivot->group_default && $entry->id === $current->id);
$isPrimary = $local->contains(static fn (TransactionCurrency $entry) => 1 === (int) $entry->pivot->group_default && $entry->id === $current->id);
$current->userGroupEnabled = $hasId;
$current->userGroupNative = $isNative;
$current->userGroupNative = $isPrimary;
return $current;
});
@@ -437,7 +437,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
$this->userGroup->currencies()->syncWithoutDetaching([$currency->id => ['group_default' => true]]);
if ($current->id !== $currency->id) {
Log::debug('Trigger on a different default currency.');
// clear all native amounts through an event.
// clear all primary currency amounts through an event.
event(new UserGroupChangedDefaultCurrency($this->userGroup));
}
}

View File

@@ -131,7 +131,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
/**
* Get current amount saved in piggy bank.
*/
public function getCurrentNativeAmount(PiggyBank $piggyBank, ?Account $account = null): string
public function getCurrentPrimaryAmount(PiggyBank $piggyBank, ?Account $account = null): string
{
$sum = '0';
foreach ($piggyBank->accounts as $current) {
@@ -171,7 +171,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
$accountRepos = app(AccountRepositoryInterface::class);
$accountRepos->setUser($this->user);
$defaultCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
$primaryCurrency = app('amount')->getPrimaryCurrencyByUserGroup($this->user->userGroup);
app('log')->debug(sprintf('Piggy bank #%d currency is %s', $piggyBank->id, $piggyBank->transactionCurrency->code));
@@ -186,14 +186,14 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
// matches source, which means amount will be removed from piggy:
if ($account->id === $source->account_id) {
$operator = 'negative';
$currency = $accountRepos->getAccountCurrency($source->account) ?? $defaultCurrency;
$currency = $accountRepos->getAccountCurrency($source->account) ?? $primaryCurrency;
app('log')->debug(sprintf('Currency will draw money out of piggy bank. Source currency is %s', $currency->code));
++$hits;
}
// matches destination, which means amount will be added to piggy.
if ($account->id === $destination->account_id) {
$operator = 'positive';
$currency = $accountRepos->getAccountCurrency($destination->account) ?? $defaultCurrency;
$currency = $accountRepos->getAccountCurrency($destination->account) ?? $primaryCurrency;
app('log')->debug(sprintf('Currency will add money to piggy bank. Destination currency is %s', $currency->code));
++$hits;
}

View File

@@ -80,7 +80,7 @@ interface PiggyBankRepositoryInterface
*/
public function getCurrentAmount(PiggyBank $piggyBank, ?Account $account = null): string;
public function getCurrentNativeAmount(PiggyBank $piggyBank, ?Account $account = null): string;
public function getCurrentPrimaryAmount(PiggyBank $piggyBank, ?Account $account = null): string;
/**
* Get all events.

View File

@@ -199,14 +199,14 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
/** @var CurrencyRepositoryInterface $repository */
$repository = app(CurrencyRepositoryInterface::class);
if (array_key_exists('native_currency_code', $data)) {
if (array_key_exists('primary_currency_code', $data)) {
$repository->setUser($this->user);
$currency = $repository->findByCode($data['native_currency_code']);
$currency = $repository->findByCode($data['primary_currency_code']);
}
if (array_key_exists('native_currency_id', $data) && null === $currency) {
if (array_key_exists('primary_currency_id', $data) && null === $currency) {
$repository->setUser($this->user);
$currency = $repository->find((int) $data['native_currency_id']);
$currency = $repository->find((int) $data['primary_currency_id']);
}
if (null !== $currency) {
$repository->makeDefault($currency);

View File

@@ -71,7 +71,7 @@ class BillRepository implements BillRepositoryInterface
{
Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__));
$bills = $this->getActiveBills();
$default = app('amount')->getPrimaryCurrency();
$primary = app('amount')->getPrimaryCurrency();
$return = [];
$converter = new ExchangeRateConverter();
@@ -88,13 +88,13 @@ class BillRepository implements BillRepositoryInterface
'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code,
'currency_decimal_places' => $currency->decimal_places,
'native_currency_id' => (string) $default->id,
'native_currency_name' => $default->name,
'native_currency_symbol' => $default->symbol,
'native_currency_code' => $default->code,
'native_currency_decimal_places' => $default->decimal_places,
'primary_currency_id' => (string) $primary->id,
'primary_currency_name' => $primary->name,
'primary_currency_symbol' => $primary->symbol,
'primary_currency_code' => $primary->code,
'primary_currency_decimal_places' => $primary->decimal_places,
'sum' => '0',
'native_sum' => '0',
'pc_sum' => '0',
];
/** @var TransactionJournal $transactionJournal */
@@ -107,18 +107,18 @@ class BillRepository implements BillRepositoryInterface
// use foreign amount instead!
$amount = (string) $sourceTransaction->foreign_amount;
}
// convert to native currency
$nativeAmount = $amount;
if ($currencyId !== $default->id) {
// convert to primary currency
$pcAmount = $amount;
if ($currencyId !== $primary->id) {
// get rate and convert.
$nativeAmount = $converter->convert($currency, $default, $transactionJournal->date, $amount);
$pcAmount = $converter->convert($currency, $primary, $transactionJournal->date, $amount);
}
if ((int) $sourceTransaction->foreign_currency_id === $default->id) {
if ((int) $sourceTransaction->foreign_currency_id === $primary->id) {
// ignore conversion, use foreign amount
$nativeAmount = (string) $sourceTransaction->foreign_amount;
$pcAmount = (string) $sourceTransaction->foreign_amount;
}
$return[$currencyId]['sum'] = bcadd($return[$currencyId]['sum'], (string) $amount);
$return[$currencyId]['native_sum'] = bcadd($return[$currencyId]['native_sum'], (string) $nativeAmount);
$return[$currencyId]['pc_sum'] = bcadd($return[$currencyId]['pc_sum'], (string) $pcAmount);
}
}
}
@@ -141,7 +141,7 @@ class BillRepository implements BillRepositoryInterface
Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__));
$bills = $this->getActiveBills();
$return = [];
$default = app('amount')->getPrimaryCurrency();
$primary = app('amount')->getPrimaryCurrency();
$converter = new ExchangeRateConverter();
/** @var Bill $bill */
@@ -154,23 +154,23 @@ class BillRepository implements BillRepositoryInterface
$currency = $bill->transactionCurrency;
$currencyId = $bill->transaction_currency_id;
$average = bcdiv(bcadd((string) $bill->amount_max, (string) $bill->amount_min), '2');
$nativeAverage = $converter->convert($currency, $default, $start, $average);
$pcAverage = $converter->convert($currency, $primary, $start, $average);
$return[$currencyId] ??= [
'currency_id' => (string) $currency->id,
'currency_name' => $currency->name,
'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code,
'currency_decimal_places' => $currency->decimal_places,
'native_currency_id' => (string) $default->id,
'native_currency_name' => $default->name,
'native_currency_symbol' => $default->symbol,
'native_currency_code' => $default->code,
'native_currency_decimal_places' => $default->decimal_places,
'primary_currency_id' => (string) $primary->id,
'primary_currency_name' => $primary->name,
'primary_currency_symbol' => $primary->symbol,
'primary_currency_code' => $primary->code,
'primary_currency_decimal_places' => $primary->decimal_places,
'sum' => '0',
'native_sum' => '0',
'pc_sum' => '0',
];
$return[$currencyId]['sum'] = bcadd($return[$currencyId]['sum'], bcmul($average, (string) $total));
$return[$currencyId]['native_sum'] = bcadd($return[$currencyId]['native_sum'], bcmul($nativeAverage, (string) $total));
$return[$currencyId]['pc_sum'] = bcadd($return[$currencyId]['pc_sum'], bcmul($pcAverage, (string) $total));
}
}
$converter->summarize();

View File

@@ -44,7 +44,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__));
$return = [];
$converter = new ExchangeRateConverter();
$default = app('amount')->getPrimaryCurrency();
$primary = app('amount')->getPrimaryCurrency();
$availableBudgets = $this->userGroup->availableBudgets()
->where('start_date', $start->format('Y-m-d'))
->where('end_date', $end->format('Y-m-d'))->get()
@@ -59,17 +59,17 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
'currency_symbol' => $availableBudget->transactionCurrency->symbol,
'currency_name' => $availableBudget->transactionCurrency->name,
'currency_decimal_places' => $availableBudget->transactionCurrency->decimal_places,
'native_currency_id' => $default->id,
'native_currency_code' => $default->code,
'native_currency_symbol' => $default->symbol,
'native_currency_name' => $default->name,
'native_currency_decimal_places' => $default->decimal_places,
'primary_currency_id' => $primary->id,
'primary_currency_code' => $primary->code,
'primary_currency_symbol' => $primary->symbol,
'primary_currency_name' => $primary->name,
'primary_currency_decimal_places' => $primary->decimal_places,
'amount' => '0',
'native_amount' => '0',
'pc_amount' => '0',
];
$nativeAmount = $converter->convert($availableBudget->transactionCurrency, $default, $availableBudget->start_date, $availableBudget->amount);
$pcAmount = $converter->convert($availableBudget->transactionCurrency, $primary, $availableBudget->start_date, $availableBudget->amount);
$return[$currencyId]['amount'] = bcadd($return[$currencyId]['amount'], (string) $availableBudget->amount);
$return[$currencyId]['native_amount'] = bcadd($return[$currencyId]['native_amount'], $nativeAmount);
$return[$currencyId]['pc_amount'] = bcadd($return[$currencyId]['pc_amount'], $pcAmount);
}
$converter->summarize();

View File

@@ -182,9 +182,9 @@ class CurrencyRepository implements CurrencyRepositoryInterface
return $all->map(static function (TransactionCurrency $current) use ($local) {
$hasId = $local->contains(static fn (TransactionCurrency $entry) => $entry->id === $current->id);
$isNative = $local->contains(static fn (TransactionCurrency $entry) => 1 === (int) $entry->pivot->group_default && $entry->id === $current->id);
$isPrimary = $local->contains(static fn (TransactionCurrency $entry) => 1 === (int) $entry->pivot->group_default && $entry->id === $current->id);
$current->userGroupEnabled = $hasId;
$current->userGroupNative = $isNative;
$current->userGroupNative = $isPrimary;
return $current;
});
@@ -385,7 +385,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
$this->userGroup->currencies()->syncWithoutDetaching([$currency->id => ['group_default' => true]]);
if ($current->id !== $currency->id) {
Log::debug('Trigger on a different default currency.');
// clear all native amounts through an event.
// clear all primary currency amounts through an event.
event(new UserGroupChangedDefaultCurrency($this->userGroup));
}
}