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', 'category_id',
'budget_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->total = 0;
$this->fields = [ $this->fields = [
// group // group
@@ -138,7 +138,7 @@ class GroupCollector implements GroupCollectorInterface
'source.amount as amount', 'source.amount as amount',
'source.balance_after as source_balance_after', 'source.balance_after as source_balance_after',
'source.balance_dirty as source_balance_dirty', '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', 'source.transaction_currency_id as currency_id',
'currency.code as currency_code', 'currency.code as currency_code',
'currency.name as currency_name', 'currency.name as currency_name',
@@ -147,7 +147,7 @@ class GroupCollector implements GroupCollectorInterface
// foreign currency info // foreign currency info
'source.foreign_amount as foreign_amount', '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', 'source.foreign_currency_id as foreign_currency_id',
'foreign_currency.code as foreign_currency_code', 'foreign_currency.code as foreign_currency_code',
'foreign_currency.name as foreign_currency_name', 'foreign_currency.name as foreign_currency_name',
@@ -735,8 +735,8 @@ class GroupCollector implements GroupCollectorInterface
if (null === $transaction['amount']) { if (null === $transaction['amount']) {
throw new FireflyException(sprintf('Amount is NULL for a transaction in group #%d, please investigate.', $groudId)); 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']); $pcAmount = (string) ('' === $transaction['pc_amount'] ? '0' : $transaction['pc_amount']);
$nativeForeignAmount = (string) ('' === $transaction['native_foreign_amount'] ? '0' : $transaction['native_foreign_amount']); $pcForeignAmount = (string) ('' === $transaction['pc_foreign_amount'] ? '0' : $transaction['pc_foreign_amount']);
$foreignAmount = (string) ('' === $transaction['foreign_amount'] ? '0' : $transaction['foreign_amount']); $foreignAmount = (string) ('' === $transaction['foreign_amount'] ? '0' : $transaction['foreign_amount']);
// set default: // set default:
@@ -746,10 +746,10 @@ class GroupCollector implements GroupCollectorInterface
$groups[$groudId]['sums'][$currencyId]['currency_symbol'] = $transaction['currency_symbol']; $groups[$groudId]['sums'][$currencyId]['currency_symbol'] = $transaction['currency_symbol'];
$groups[$groudId]['sums'][$currencyId]['currency_decimal_places'] = $transaction['currency_decimal_places']; $groups[$groudId]['sums'][$currencyId]['currency_decimal_places'] = $transaction['currency_decimal_places'];
$groups[$groudId]['sums'][$currencyId]['amount'] = '0'; $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]['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']) { if (null !== $transaction['foreign_amount'] && null !== $transaction['foreign_currency_id']) {
$currencyId = (int) $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_symbol'] = $transaction['foreign_currency_symbol'];
$groups[$groudId]['sums'][$currencyId]['currency_decimal_places'] = $transaction['foreign_currency_decimal_places']; $groups[$groudId]['sums'][$currencyId]['currency_decimal_places'] = $transaction['foreign_currency_decimal_places'];
$groups[$groudId]['sums'][$currencyId]['amount'] = '0'; $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]['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 * 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. * 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 public function byAccounts(Collection $accounts, Carbon $date): array
{ {
// start in the past, end in the future? use $date // start in the past, end in the future? use $date
$convertToNative = Amount::convertToPrimary(); $convertToPrimary = Amount::convertToPrimary();
$ids = implode(',', $accounts->pluck('id')->toArray()); $ids = implode(',', $accounts->pluck('id')->toArray());
$cache = new CacheProperties(); $cache = new CacheProperties();
$cache->addProperty($date); $cache->addProperty($date);
$cache->addProperty($convertToNative); $cache->addProperty($convertToPrimary);
$cache->addProperty('net-worth-by-accounts'); $cache->addProperty('net-worth-by-accounts');
$cache->addProperty($ids); $cache->addProperty($ids);
if ($cache->has()) { if ($cache->has()) {
@@ -84,20 +84,20 @@ class NetWorth implements NetWorthInterface
foreach ($accounts as $account) { foreach ($accounts as $account) {
// Log::debug(sprintf('Now at account #%d ("%s")', $account->id, $account->name)); // Log::debug(sprintf('Now at account #%d ("%s")', $account->id, $account->name));
$currency = $this->accountRepository->getAccountCurrency($account) ?? $default; $currency = $this->accountRepository->getAccountCurrency($account) ?? $default;
$useNative = $convertToNative && $default->id !== $currency->id; $usePrimary = $convertToPrimary && $default->id !== $currency->id;
$currency = $useNative ? $default : $currency; $currency = $usePrimary ? $default : $currency;
$currencyCode = $currency->code; $currencyCode = $currency->code;
$balance = '0'; $balance = '0';
$nativeBalance = '0'; $primaryBalance = '0';
if (array_key_exists($account->id, $balances)) { if (array_key_exists($account->id, $balances)) {
$balance = $balances[$account->id]['balance'] ?? '0'; $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. // always subtract virtual balance again.
$balance = '' !== (string) $account->virtual_balance ? bcsub($balance, (string) $account->virtual_balance) : $balance; $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; $primaryBalance = '' !== (string) $account->native_virtual_balance ? bcsub($primaryBalance, (string) $account->native_virtual_balance) : $primaryBalance;
$amountToUse = $useNative ? $nativeBalance : $balance; $amountToUse = $usePrimary ? $primaryBalance : $balance;
// Log::debug(sprintf('Will use %s %s', $currencyCode, $amountToUse)); // Log::debug(sprintf('Will use %s %s', $currencyCode, $amountToUse));
$netWorth[$currencyCode] ??= [ $netWorth[$currencyCode] ??= [

View File

@@ -40,9 +40,9 @@ interface NetWorthInterface
* Collect net worth based on the given set of accounts. * 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 * 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; public function byAccounts(Collection $accounts, Carbon $date): array;

View File

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

View File

@@ -125,7 +125,7 @@ class EditController extends Controller
$openingBalanceAmount = ''; $openingBalanceAmount = '';
} }
$openingBalanceDate = $repository->getOpeningBalanceDate($account); $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? // include this account in net-worth charts?
$includeNetWorth = $repository->getMetaValue($account, 'include_net_worth'); $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 { function (Account $account) use ($activities, $startBalances, $endBalances): void {
$currency = $this->repository->getAccountCurrency($account); $currency = $this->repository->getAccountCurrency($account);
$account->lastActivityDate = $this->isInArrayDate($activities, $account->id); $account->lastActivityDate = $this->isInArrayDate($activities, $account->id);
$account->startBalances = Steam::filterAccountBalance($startBalances[$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->convertToNative, $currency); $account->endBalances = Steam::filterAccountBalance($endBalances[$account->id] ?? [], $account, $this->convertToPrimary, $currency);
$account->differences = $this->subtract($account->startBalances, $account->endBalances); $account->differences = $this->subtract($account->startBalances, $account->endBalances);
$account->interest = Steam::bcround($this->repository->getMetaValue($account, 'interest'), 4); $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->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->accountTypeString = (string) trans(sprintf('firefly.account_type_%s', $account->accountType->type));
$account->current_debt = '0'; $account->current_debt = '0';
$account->currency = $currency ?? $this->defaultCurrency; $account->currency = $currency ?? $this->primaryCurrency;
$account->iban = implode(' ', str_split((string) $account->iban, 4)); $account->iban = implode(' ', str_split((string) $account->iban, 4));
} }
); );
@@ -183,8 +183,8 @@ class IndexController extends Controller
$interest = '' === $interest ? '0' : $interest; $interest = '' === $interest ? '0' : $interest;
$currency = $this->repository->getAccountCurrency($account); $currency = $this->repository->getAccountCurrency($account);
$account->startBalances = Steam::filterAccountBalance($startBalances[$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->convertToNative, $currency); $account->endBalances = Steam::filterAccountBalance($endBalances[$account->id] ?? [], $account, $this->convertToPrimary, $currency);
$account->differences = $this->subtract($account->startBalances, $account->endBalances); $account->differences = $this->subtract($account->startBalances, $account->endBalances);
$account->lastActivityDate = $this->isInArrayDate($activities, $account->id); $account->lastActivityDate = $this->isInArrayDate($activities, $account->id);
$account->interest = Steam::bcround($interest, 4); $account->interest = Steam::bcround($interest, 4);
@@ -195,7 +195,7 @@ class IndexController extends Controller
$account->location = $this->repository->getLocation($account); $account->location = $this->repository->getLocation($account);
$account->liability_direction = $this->repository->getMetaValue($account, 'liability_direction'); $account->liability_direction = $this->repository->getMetaValue($account, 'liability_direction');
$account->current_debt = $this->repository->getMetaValue($account, 'current_debt') ?? '-'; $account->current_debt = $this->repository->getMetaValue($account, 'current_debt') ?? '-';
$account->currency = $currency ?? $this->defaultCurrency; $account->currency = $currency ?? $this->primaryCurrency;
$account->iban = implode(' ', str_split((string) $account->iban, 4)); $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))])); 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: // no start or end:
$range = app('navigation')->getViewRange(false); $range = app('navigation')->getViewRange(false);
@@ -204,7 +204,7 @@ class ReconcileController extends Controller
} }
$reconciliation = $this->accountRepos->getReconciliation($account); $reconciliation = $this->accountRepos->getReconciliation($account);
$currency = $this->accountRepos->getAccountCurrency($account) ?? $this->defaultCurrency; $currency = $this->accountRepos->getAccountCurrency($account) ?? $this->primaryCurrency;
$source = $reconciliation; $source = $reconciliation;
$destination = $account; $destination = $account;
if (1 === bccomp($difference, '0')) { if (1 === bccomp($difference, '0')) {

View File

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

View File

@@ -77,7 +77,7 @@ class CreateController extends Controller
$periods[$current] = (string) trans('firefly.repeat_freq_'.$current); $periods[$current] = (string) trans('firefly.repeat_freq_'.$current);
} }
$subTitle = (string) trans('firefly.create_new_bill'); $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"). // put previous url in session if not redirect from store (not "create another").
if (true !== session('bills.create.fromStore')) { 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_min = app('steam')->bcround($bill->amount_min, $bill->transactionCurrency->decimal_places);
$bill->amount_max = app('steam')->bcround($bill->amount_max, $bill->transactionCurrency->decimal_places); $bill->amount_max = app('steam')->bcround($bill->amount_max, $bill->transactionCurrency->decimal_places);
$rules = $this->repository->getRulesForBill($bill); $rules = $this->repository->getRulesForBill($bill);
$defaultCurrency = $this->defaultCurrency; $defaultCurrency = $this->primaryCurrency;
// code to handle active-checkboxes // code to handle active-checkboxes
$hasOldInput = null !== $request->old('_token'); $hasOldInput = null !== $request->old('_token');

View File

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

View File

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

View File

@@ -89,7 +89,7 @@ class CreateController extends Controller
$preFilled = [ $preFilled = [
'auto_budget_period' => $hasOldInput ? (bool) $request->old('auto_budget_period') : 'monthly', '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); $request->session()->flash('preFilled', $preFilled);

View File

@@ -94,7 +94,7 @@ class EditController extends Controller
$hasOldInput = null !== $request->old('_token'); $hasOldInput = null !== $request->old('_token');
$preFilled = [ $preFilled = [
'active' => $hasOldInput ? (bool) $request->old('active') : $budget->active, '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) { if ($autoBudget instanceof AutoBudget) {
$amount = $hasOldInput ? $request->old('auto_budget_amount') : $autoBudget->amount; $amount = $hasOldInput ? $request->old('auto_budget_amount') : $autoBudget->amount;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -68,7 +68,7 @@ class BoxController extends Controller
$cache = new CacheProperties(); $cache = new CacheProperties();
$cache->addProperty($start); $cache->addProperty($start);
$cache->addProperty($end); $cache->addProperty($end);
$cache->addProperty($this->convertToNative); $cache->addProperty($this->convertToPrimary);
$cache->addProperty('box-balance'); $cache->addProperty('box-balance');
if ($cache->has()) { if ($cache->has()) {
return response()->json($cache->get()); return response()->json($cache->get());
@@ -77,7 +77,7 @@ class BoxController extends Controller
$incomes = []; $incomes = [];
$expenses = []; $expenses = [];
$sums = []; $sums = [];
$currency = $this->defaultCurrency; $currency = $this->primaryCurrency;
// collect income of user: // collect income of user:
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
@@ -89,7 +89,7 @@ class BoxController extends Controller
/** @var array $journal */ /** @var array $journal */
foreach ($set as $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); $amount = Amount::getAmountFromJournal($journal);
$incomes[$currencyId] ??= '0'; $incomes[$currencyId] ??= '0';
$incomes[$currencyId] = bcadd($incomes[$currencyId], (string) app('steam')->positive($amount)); $incomes[$currencyId] = bcadd($incomes[$currencyId], (string) app('steam')->positive($amount));
@@ -107,7 +107,7 @@ class BoxController extends Controller
/** @var array $journal */ /** @var array $journal */
foreach ($set as $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); $amount = Amount::getAmountFromJournal($journal);
$expenses[$currencyId] ??= '0'; $expenses[$currencyId] ??= '0';
$expenses[$currencyId] = bcadd($expenses[$currencyId], $amount); $expenses[$currencyId] = bcadd($expenses[$currencyId], $amount);
@@ -124,10 +124,10 @@ class BoxController extends Controller
$expenses[$currencyId] = app('amount')->formatAnything($currency, $expenses[$currencyId] ?? '0', false); $expenses[$currencyId] = app('amount')->formatAnything($currency, $expenses[$currencyId] ?? '0', false);
} }
if (0 === count($sums)) { if (0 === count($sums)) {
$currency = $this->defaultCurrency; $currency = $this->primaryCurrency;
$sums[$this->defaultCurrency->id] = app('amount')->formatAnything($this->defaultCurrency, '0', false); $sums[$this->primaryCurrency->id] = app('amount')->formatAnything($this->primaryCurrency, '0', false);
$incomes[$this->defaultCurrency->id] = app('amount')->formatAnything($this->defaultCurrency, '0', false); $incomes[$this->primaryCurrency->id] = app('amount')->formatAnything($this->primaryCurrency, '0', false);
$expenses[$this->defaultCurrency->id] = app('amount')->formatAnything($this->defaultCurrency, '0', false); $expenses[$this->primaryCurrency->id] = app('amount')->formatAnything($this->primaryCurrency, '0', false);
} }
$response = [ $response = [
@@ -182,7 +182,7 @@ class BoxController extends Controller
$netWorthSet = $netWorthHelper->byAccounts($filtered, $date); $netWorthSet = $netWorthHelper->byAccounts($filtered, $date);
$return = []; $return = [];
foreach ($netWorthSet as $key => $data) { foreach ($netWorthSet as $key => $data) {
if ('native' === $key) { if ('primary' === $key) {
continue; continue;
} }
$return[$data['currency_id']] = app('amount')->formatFlat($data['currency_symbol'], $data['currency_decimal_places'], $data['balance'], false); $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(); $set = $repository->getPiggyBanks();
$info = []; $info = [];
$native = Amount::getPrimaryCurrency();
$convertToNative = Amount::convertToPrimary();
/** @var PiggyBank $piggyBank */ /** @var PiggyBank $piggyBank */
foreach ($set as $piggyBank) { foreach ($set as $piggyBank) {
$amount = $repository->getCurrentAmount($piggyBank); $amount = $repository->getCurrentAmount($piggyBank);
$nativeAmount = $repository->getCurrentNativeAmount($piggyBank); $pcAmount = $repository->getCurrentPrimaryCurrencyAmount($piggyBank);
if (1 === bccomp($amount, '0')) { if (1 === bccomp($amount, '0')) {
// percentage! // percentage!
$pct = 0; $pct = 0;
@@ -64,15 +62,15 @@ class FrontpageController extends Controller
'id' => $piggyBank->id, 'id' => $piggyBank->id,
'name' => $piggyBank->name, 'name' => $piggyBank->name,
'amount' => $amount, 'amount' => $amount,
'native_amount' => $nativeAmount, 'pc_amount' => $pcAmount,
'target' => $piggyBank->target_amount, 'target' => $piggyBank->target_amount,
'native_target' => $piggyBank->native_target_amount, 'pc_target' => $piggyBank->native_target_amount,
'percentage' => $pct, 'percentage' => $pct,
// currency: // currency:
'currency_symbol' => $piggyBank->transactionCurrency->symbol, 'currency_symbol' => $piggyBank->transactionCurrency->symbol,
'currency_decimal_places' => $piggyBank->transactionCurrency->decimal_places, 'currency_decimal_places' => $piggyBank->transactionCurrency->decimal_places,
'native_currency_symbol' => $native->symbol, 'primary_currency_symbol' => $this->primaryCurrency->symbol,
'native_currency_decimal_places' => $native->decimal_places, 'primary_currency_decimal_places' => $this->primaryCurrency->decimal_places,
]; ];
@@ -89,7 +87,9 @@ class FrontpageController extends Controller
$html = ''; $html = '';
if (0 !== count($info)) { if (0 !== count($info)) {
try { 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) { } catch (Throwable $e) {
app('log')->error(sprintf('Cannot render json.piggy-banks: %s', $e->getMessage())); app('log')->error(sprintf('Cannot render json.piggy-banks: %s', $e->getMessage()));
app('log')->error($e->getTraceAsString()); app('log')->error($e->getTraceAsString());

View File

@@ -74,7 +74,7 @@ class ReconcileController extends Controller
{ {
$startBalance = $request->get('startBalance'); $startBalance = $request->get('startBalance');
$endBalance = $request->get('endBalance'); $endBalance = $request->get('endBalance');
$accountCurrency = $this->accountRepos->getAccountCurrency($account) ?? $this->defaultCurrency; $accountCurrency = $this->accountRepos->getAccountCurrency($account) ?? $this->primaryCurrency;
$amount = '0'; $amount = '0';
$clearedAmount = '0'; $clearedAmount = '0';
@@ -195,7 +195,7 @@ class ReconcileController extends Controller
$startDate = clone $start; $startDate = clone $start;
$startDate->subDay(); $startDate->subDay();
$currency = $this->accountRepos->getAccountCurrency($account) ?? $this->defaultCurrency; $currency = $this->accountRepos->getAccountCurrency($account) ?? $this->primaryCurrency;
// correct // correct
Log::debug(sprintf('transactions: Call finalAccountBalance with date/time "%s"', $startDate->toIso8601String())); Log::debug(sprintf('transactions: Call finalAccountBalance with date/time "%s"', $startDate->toIso8601String()));
Log::debug(sprintf('transactions2: Call finalAccountBalance with date/time "%s"', $end->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. // enrich each account.
$enrichment = new AccountEnrichment(); $enrichment = new AccountEnrichment();
$enrichment->setUser(auth()->user()); $enrichment->setUser(auth()->user());
$enrichment->setNative($this->defaultCurrency); $enrichment->setPrimary($this->primaryCurrency);
$return = []; $return = [];
/** @var PiggyBank $piggy */ /** @var PiggyBank $piggy */

View File

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

View File

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

View File

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

View File

@@ -117,7 +117,7 @@ class CreateController extends Controller
$optionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data; $optionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
$allowedOpposingTypes = config('firefly.allowed_opposing_types'); $allowedOpposingTypes = config('firefly.allowed_opposing_types');
$accountToTypes = config('firefly.account_to_transaction'); $accountToTypes = config('firefly.account_to_transaction');
$defaultCurrency = $this->defaultCurrency; $defaultCurrency = $this->primaryCurrency;
$previousUrl = $this->rememberPreviousUrl('transactions.create.url'); $previousUrl = $this->rememberPreviousUrl('transactions.create.url');
$parts = parse_url((string) $previousUrl); $parts = parse_url((string) $previousUrl);
$search = sprintf('?%s', $parts['query'] ?? ''); $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; $title = $transactionGroup->transactionJournals()->count() > 1 ? $transactionGroup->title : $transactionGroup->transactionJournals()->first()->description;
$subTitle = (string) trans('firefly.edit_transaction_title', ['description' => $title]); $subTitle = (string) trans('firefly.edit_transaction_title', ['description' => $title]);
$subTitleIcon = 'fa-plus'; $subTitleIcon = 'fa-plus';
$defaultCurrency = $this->defaultCurrency; $defaultCurrency = $this->primaryCurrency;
$cash = $repository->getCashAccount(); $cash = $repository->getCashAccount();
$previousUrl = $this->rememberPreviousUrl('transactions.edit.url'); $previousUrl = $this->rememberPreviousUrl('transactions.edit.url');
$parts = parse_url((string) $previousUrl); $parts = parse_url((string) $previousUrl);

View File

@@ -74,10 +74,10 @@ class IndexController extends Controller
// order so default and enabled are on top: // order so default and enabled are on top:
$collection = $collection->sortBy( $collection = $collection->sortBy(
static function (TransactionCurrency $currency) { static function (TransactionCurrency $currency) {
$native = true === $currency->userGroupNative ? 0 : 1; $primary = true === $currency->userGroupNative ? 0 : 1;
$enabled = true === $currency->userGroupEnabled ? 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(); $total = $collection->count();

View File

@@ -258,7 +258,7 @@ class EventServiceProvider extends ServiceProvider
], ],
// preferences // preferences
UserGroupChangedDefaultCurrency::class => [ 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. * 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') $journal = TransactionJournal::leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.account_id', $account->id) ->where('transactions.account_id', $account->id)
@@ -309,7 +309,7 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
if (null === $transaction) { if (null === $transaction) {
return null; return null;
} }
if ($convertToNative) { if ($convertToPrimary) {
return $transaction->native_amount ?? '0'; return $transaction->native_amount ?? '0';
} }

View File

@@ -117,7 +117,7 @@ interface AccountRepositoryInterface
/** /**
* Returns the amount of the opening balance for this account. * 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. * Return date of opening balance as string or null.

View File

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

View File

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

View File

@@ -91,7 +91,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
$limitRepository = app(BudgetLimitRepository::class); $limitRepository = app(BudgetLimitRepository::class);
$limitRepository->setUser($this->user); $limitRepository->setUser($this->user);
$budgets = $this->getActiveBudgets(); $budgets = $this->getActiveBudgets();
$defaultCurrency = app('amount')->getPrimaryCurrency(); $primaryCurrency = app('amount')->getPrimaryCurrency();
$converter = new ExchangeRateConverter(); $converter = new ExchangeRateConverter();
/** @var Budget $budget */ /** @var Budget $budget */
@@ -103,7 +103,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
foreach ($limits as $limit) { foreach ($limits as $limit) {
app('log')->debug(sprintf('Budget limit #%d', $limit->id)); app('log')->debug(sprintf('Budget limit #%d', $limit->id));
$currency = $limit->transactionCurrency; $currency = $limit->transactionCurrency;
$rate = $converter->getCurrencyRate($currency, $defaultCurrency, $end); $rate = $converter->getCurrencyRate($currency, $primaryCurrency, $end);
$currencyCode = $currency->code; $currencyCode = $currency->code;
$return[$currencyCode] ??= [ $return[$currencyCode] ??= [
'currency_id' => (string) $currency->id, 'currency_id' => (string) $currency->id,
@@ -111,18 +111,18 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
'currency_symbol' => $currency->symbol, 'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code, 'currency_code' => $currency->code,
'currency_decimal_places' => $currency->decimal_places, 'currency_decimal_places' => $currency->decimal_places,
'native_currency_id' => (string) $defaultCurrency->id, 'primary_currency_id' => (string) $primaryCurrency->id,
'native_currency_name' => $defaultCurrency->name, 'primary_currency_name' => $primaryCurrency->name,
'native_currency_symbol' => $defaultCurrency->symbol, 'primary_currency_symbol' => $primaryCurrency->symbol,
'native_currency_code' => $defaultCurrency->code, 'primary_currency_code' => $primaryCurrency->code,
'native_currency_decimal_places' => $defaultCurrency->decimal_places, 'primary_currency_decimal_places' => $primaryCurrency->decimal_places,
'sum' => '0', 'sum' => '0',
'native_sum' => '0', 'pc_sum' => '0',
]; ];
// same period // same period
if ($limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end)) { if ($limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end)) {
$return[$currencyCode]['sum'] = bcadd($return[$currencyCode]['sum'], (string) $limit->amount); $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)); app('log')->debug(sprintf('Add full amount [1]: %s', $limit->amount));
continue; continue;
@@ -130,7 +130,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
// limit is inside of date range // limit is inside of date range
if ($start->lte($limit->start_date) && $end->gte($limit->end_date)) { if ($start->lte($limit->start_date) && $end->gte($limit->end_date)) {
$return[$currencyCode]['sum'] = bcadd($return[$currencyCode]['sum'], (string) $limit->amount); $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)); app('log')->debug(sprintf('Add full amount [2]: %s', $limit->amount));
continue; continue;
@@ -139,7 +139,7 @@ class BudgetRepository implements BudgetRepositoryInterface, UserGroupInterface
$days = $this->daysInOverlap($limit, $start, $end); $days = $this->daysInOverlap($limit, $start, $end);
$amount = bcmul(bcdiv((string) $limit->amount, (string) $total), (string) $days); $amount = bcmul(bcdiv((string) $limit->amount, (string) $total), (string) $days);
$return[$currencyCode]['sum'] = bcadd($return[$currencyCode]['sum'], $amount); $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( app('log')->debug(
sprintf( sprintf(
'Amount per day: %s (%s over %d days). Total amount for %d days: %s', '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(); $journals = $collector->getExtractedJournals();
$array = []; $array = [];
// if needs conversion to native. // if needs conversion to primary.
$convertToNative = Amount::convertToPrimary($this->user); $convertToPrimary = Amount::convertToPrimary($this->user);
$nativeCurrency = Amount::getPrimaryCurrencyByUserGroup($this->userGroup); $primaryCurrency = Amount::getPrimaryCurrencyByUserGroup($this->userGroup);
$currencyId = (int) $nativeCurrency->id; $currencyId = (int) $primaryCurrency->id;
$currencyCode = $nativeCurrency->code; $currencyCode = $primaryCurrency->code;
$currencyName = $nativeCurrency->name; $currencyName = $primaryCurrency->name;
$currencySymbol = $nativeCurrency->symbol; $currencySymbol = $primaryCurrency->symbol;
$currencyDecimalPlaces = $nativeCurrency->decimal_places; $currencyDecimalPlaces = $primaryCurrency->decimal_places;
$converter = new ExchangeRateConverter(); $converter = new ExchangeRateConverter();
$currencies = [ $currencies = [
$currencyId => $nativeCurrency, $currencyId => $primaryCurrency,
]; ];
foreach ($journals as $journal) { foreach ($journals as $journal) {
$amount = app('steam')->negative($journal['amount']); $amount = app('steam')->negative($journal['amount']);
$journalCurrencyId = (int)$journal['currency_id']; $journalCurrencyId = (int)$journal['currency_id'];
if (false === $convertToNative) { if (false === $convertToPrimary) {
$currencyId = $journalCurrencyId; $currencyId = $journalCurrencyId;
$currencyName = $journal['currency_name']; $currencyName = $journal['currency_name'];
$currencySymbol = $journal['currency_symbol']; $currencySymbol = $journal['currency_symbol'];
$currencyCode = $journal['currency_code']; $currencyCode = $journal['currency_code'];
$currencyDecimalPlaces = $journal['currency_decimal_places']; $currencyDecimalPlaces = $journal['currency_decimal_places'];
} }
if (true === $convertToNative && $journalCurrencyId !== $currencyId) { if (true === $convertToPrimary && $journalCurrencyId !== $currencyId) {
$currencies[$journalCurrencyId] ??= TransactionCurrency::find($journalCurrencyId); $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']; $budgetId = (int)$journal['budget_id'];
@@ -230,9 +230,9 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
?Collection $accounts = null, ?Collection $accounts = null,
?Collection $budgets = null, ?Collection $budgets = null,
?TransactionCurrency $currency = null, ?TransactionCurrency $currency = null,
bool $convertToNative = false bool $convertToPrimary = false
): array { ): 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) // 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. // because those expenses only become expenses once they move from the liability to the friend.
// 2024-12-24 disable the exclusion for now. // 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.'); Log::debug('STOP looking for transactions in the foreign currency.');
} }
$summarizer = new TransactionSummarizer($this->user); $summarizer = new TransactionSummarizer($this->user);
// 2025-04-21 overrule "convertToNative" because in this particular view, we never want to do this. // 2025-04-21 overrule "convertToPrimary" because in this particular view, we never want to do this.
$summarizer->setConvertToNative($convertToNative); $summarizer->setConvertToPrimary($convertToPrimary);
return $summarizer->groupByCurrencyId($journals, 'negative', false); return $summarizer->groupByCurrencyId($journals, 'negative', false);
} }

View File

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

View File

@@ -358,8 +358,8 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
} }
$collector->setCategories($categories); $collector->setCategories($categories);
$journals = $collector->getExtractedJournals(); $journals = $collector->getExtractedJournals();
$convertToNative = Amount::convertToPrimary($this->user); $convertToPrimary = Amount::convertToPrimary($this->user);
$default = Amount::getPrimaryCurrency(); $primary = Amount::getPrimaryCurrency();
$array = []; $array = [];
foreach ($journals as $journal) { foreach ($journals as $journal) {
@@ -370,16 +370,16 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
$currencySymbol = $journal['currency_symbol']; $currencySymbol = $journal['currency_symbol'];
$currencyCode = $journal['currency_code']; $currencyCode = $journal['currency_code'];
$currencyDecimalPlaces = $journal['currency_decimal_places']; $currencyDecimalPlaces = $journal['currency_decimal_places'];
if ($convertToNative) { if ($convertToPrimary) {
$amount = Amount::getAmountFromJournal($journal); $amount = Amount::getAmountFromJournal($journal);
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 = $default->id; $currencyId = $primary->id;
$currencyName = $default->name; $currencyName = $primary->name;
$currencySymbol = $default->symbol; $currencySymbol = $primary->symbol;
$currencyCode = $default->code; $currencyCode = $primary->code;
$currencyDecimalPlaces = $default->decimal_places; $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']; $currencyId = $journal['foreign_currency_id'];
$currencyName = $journal['foreign_currency_name']; $currencyName = $journal['foreign_currency_name'];
$currencySymbol = $journal['foreign_currency_symbol']; $currencySymbol = $journal['foreign_currency_symbol'];
@@ -388,7 +388,7 @@ class OperationsRepository implements OperationsRepositoryInterface, UserGroupIn
} }
Log::debug(sprintf('[a] Add amount %s %s', $currencyCode, $amount)); Log::debug(sprintf('[a] Add amount %s %s', $currencyCode, $amount));
} }
if (!$convertToNative) { if (!$convertToPrimary) {
// ignore the amount in foreign currency. // ignore the amount in foreign currency.
Log::debug(sprintf('[b] Add amount %s %s', $currencyCode, $journal['amount'])); Log::debug(sprintf('[b] Add amount %s %s', $currencyCode, $journal['amount']));
$amount = $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) { return $all->map(static function (TransactionCurrency $current) use ($local) {
$hasId = $local->contains(static fn (TransactionCurrency $entry) => $entry->id === $current->id); $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->userGroupEnabled = $hasId;
$current->userGroupNative = $isNative; $current->userGroupNative = $isPrimary;
return $current; return $current;
}); });
@@ -437,7 +437,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
$this->userGroup->currencies()->syncWithoutDetaching([$currency->id => ['group_default' => true]]); $this->userGroup->currencies()->syncWithoutDetaching([$currency->id => ['group_default' => true]]);
if ($current->id !== $currency->id) { if ($current->id !== $currency->id) {
Log::debug('Trigger on a different default currency.'); 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)); event(new UserGroupChangedDefaultCurrency($this->userGroup));
} }
} }

View File

@@ -131,7 +131,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
/** /**
* Get current amount saved in piggy bank. * 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'; $sum = '0';
foreach ($piggyBank->accounts as $current) { foreach ($piggyBank->accounts as $current) {
@@ -171,7 +171,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface, UserGroupInte
$accountRepos = app(AccountRepositoryInterface::class); $accountRepos = app(AccountRepositoryInterface::class);
$accountRepos->setUser($this->user); $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)); 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: // matches source, which means amount will be removed from piggy:
if ($account->id === $source->account_id) { if ($account->id === $source->account_id) {
$operator = 'negative'; $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)); app('log')->debug(sprintf('Currency will draw money out of piggy bank. Source currency is %s', $currency->code));
++$hits; ++$hits;
} }
// matches destination, which means amount will be added to piggy. // matches destination, which means amount will be added to piggy.
if ($account->id === $destination->account_id) { if ($account->id === $destination->account_id) {
$operator = 'positive'; $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)); app('log')->debug(sprintf('Currency will add money to piggy bank. Destination currency is %s', $currency->code));
++$hits; ++$hits;
} }

View File

@@ -80,7 +80,7 @@ interface PiggyBankRepositoryInterface
*/ */
public function getCurrentAmount(PiggyBank $piggyBank, ?Account $account = null): string; 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. * Get all events.

View File

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

View File

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

View File

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

View File

@@ -182,9 +182,9 @@ class CurrencyRepository implements CurrencyRepositoryInterface
return $all->map(static function (TransactionCurrency $current) use ($local) { return $all->map(static function (TransactionCurrency $current) use ($local) {
$hasId = $local->contains(static fn (TransactionCurrency $entry) => $entry->id === $current->id); $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->userGroupEnabled = $hasId;
$current->userGroupNative = $isNative; $current->userGroupNative = $isPrimary;
return $current; return $current;
}); });
@@ -385,7 +385,7 @@ class CurrencyRepository implements CurrencyRepositoryInterface
$this->userGroup->currencies()->syncWithoutDetaching([$currency->id => ['group_default' => true]]); $this->userGroup->currencies()->syncWithoutDetaching([$currency->id => ['group_default' => true]]);
if ($current->id !== $currency->id) { if ($current->id !== $currency->id) {
Log::debug('Trigger on a different default currency.'); 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)); event(new UserGroupChangedDefaultCurrency($this->userGroup));
} }
} }