Rename "native" references to "primary" or "pc".

This commit is contained in:
James Cole
2025-07-31 20:47:20 +02:00
parent d6d9f665c7
commit da36d84b79
25 changed files with 146 additions and 154 deletions

View File

@@ -99,7 +99,7 @@ class AccountController extends Controller
// this one is correct.
Log::debug(sprintf('accounts: Call finalAccountBalance with date/time "%s"', $date->toIso8601String()));
$balance = Steam::finalAccountBalance($account, $date);
$key = $this->convertToPrimary && $currency->id !== $this->primaryCurrency->id ? 'native_balance' : 'balance';
$key = $this->convertToPrimary && $currency->id !== $this->primaryCurrency->id ? 'pc_balance' : 'balance';
$useCurrency = $this->convertToPrimary && $currency->id !== $this->primaryCurrency->id ? $this->primaryCurrency : $currency;
$amount = $balance[$key] ?? '0';
$nameWithBalance = sprintf(

View File

@@ -87,7 +87,7 @@ class AccountController extends Controller
// move date to end of day
$queryParameters['start']->startOfDay();
$queryParameters['end']->endOfDay();
Log::debug(sprintf('dashboard(), convert to native: %s', var_export($this->convertToPrimary, true)));
Log::debug(sprintf('dashboard(), convert to primary: %s', var_export($this->convertToPrimary, true)));
// loop each account, and collect info:
/** @var Account $account */
@@ -111,7 +111,7 @@ class AccountController extends Controller
$previous = array_values($range)[0]['balance'];
$nativePrevious = null;
$pcPrevious = null;
if (!$currency instanceof TransactionCurrency) {
$currency = $this->default;
}
@@ -132,12 +132,12 @@ class AccountController extends Controller
'entries' => [],
];
if ($this->convertToPrimary) {
$currentSet['native_entries'] = [];
$currentSet['native_currency_id'] = (string)$this->primaryCurrency->id;
$currentSet['native_currency_code'] = $this->primaryCurrency->code;
$currentSet['native_currency_symbol'] = $this->primaryCurrency->symbol;
$currentSet['native_currency_decimal_places'] = $this->primaryCurrency->decimal_places;
$nativePrevious = array_values($range)[0]['native_balance'];
$currentSet['pc_entries'] = [];
$currentSet['primary_currency_id'] = (string)$this->primaryCurrency->id;
$currentSet['primary_currency_code'] = $this->primaryCurrency->code;
$currentSet['primary_currency_symbol'] = $this->primaryCurrency->symbol;
$currentSet['primary_currency_decimal_places'] = $this->primaryCurrency->decimal_places;
$pcPrevious = array_values($range)[0]['pc_balance'];
}
@@ -149,12 +149,12 @@ class AccountController extends Controller
$currentSet['entries'][$label] = $balance;
// do the same for the native balance, if relevant:
$nativeBalance = null;
// do the same for the primary currency balance, if relevant:
$pcBalance = null;
if ($this->convertToPrimary) {
$nativeBalance = array_key_exists($format, $range) ? $range[$format]['native_balance'] : $nativePrevious;
$nativePrevious = $nativeBalance;
$currentSet['native_entries'][$label] = $nativeBalance;
$pcBalance = array_key_exists($format, $range) ? $range[$format]['pc_balance'] : $pcPrevious;
$pcPrevious = $pcBalance;
$currentSet['pc_entries'][$label] = $pcBalance;
}
$currentStart->addDay();
@@ -195,7 +195,7 @@ class AccountController extends Controller
$currentStart = clone $start;
$range = Steam::finalAccountBalanceInRange($account, $start, clone $end, $this->convertToPrimary);
$previous = array_values($range)[0]['balance'];
$nativePrevious = null;
$pcPrevious = null;
$currentSet = [
'label' => $account->name,
'currency_id' => (string)$currency->id,
@@ -209,18 +209,18 @@ class AccountController extends Controller
'entries' => [],
];
// add "native_entries" if convertToNative is true:
// add "pc_entries" if convertToPrimary is true:
if ($this->convertToPrimary) {
$currentSet['native_entries'] = [];
$currentSet['native_currency_id'] = (string)$this->primaryCurrency->id;
$currentSet['native_currency_code'] = $this->primaryCurrency->code;
$currentSet['native_currency_symbol'] = $this->primaryCurrency->symbol;
$currentSet['native_currency_decimal_places'] = $this->primaryCurrency->decimal_places;
$nativePrevious = array_values($range)[0]['native_balance'];
$currentSet['pc_entries'] = [];
$currentSet['primary_currency_id'] = (string)$this->primaryCurrency->id;
$currentSet['primary_currency_code'] = $this->primaryCurrency->code;
$currentSet['primary_currency_symbol'] = $this->primaryCurrency->symbol;
$currentSet['primary_currency_decimal_places'] = $this->primaryCurrency->decimal_places;
$pcPrevious = array_values($range)[0]['pc_balance'];
}
// also get the native balance if convertToNative is true:
// also get the primary balance if convertToPrimary is true:
while ($currentStart <= $end) {
$format = $currentStart->format('Y-m-d');
$label = $currentStart->toAtomString();
@@ -230,12 +230,12 @@ class AccountController extends Controller
$previous = $balance;
$currentSet['entries'][$label] = $balance;
// do the same for the native balance, if relevant:
$nativeBalance = null;
// do the same for the primary balance, if relevant:
$pcBalance = null;
if ($this->convertToPrimary) {
$nativeBalance = array_key_exists($format, $range) ? $range[$format]['native_balance'] : $nativePrevious;
$nativePrevious = $nativeBalance;
$currentSet['native_entries'][$label] = $nativeBalance;
$pcBalance = array_key_exists($format, $range) ? $range[$format]['pc_balance'] : $pcPrevious;
$pcPrevious = $pcBalance;
$currentSet['pc_entries'][$label] = $pcBalance;
}
$currentStart->addDay();

View File

@@ -264,7 +264,7 @@ class BudgetController extends Controller
$compare = bccomp($limit->amount, (string)app('steam')->positive($result[$limitCurrencyId]['spent']));
$result[$limitCurrencyId]['budgeted'] = $limit->amount;
if (1 === $compare) {
// convert this amount into the native currency:
// convert this amount into the primary currency:
$result[$limitCurrencyId]['left'] = bcadd($limit->amount, (string)$result[$limitCurrencyId]['spent']);
}
if ($compare <= 0) {

View File

@@ -69,8 +69,8 @@ class BillController extends Controller
$bills = $request->getBills();
$start = $request->getStart();
$end = $request->getEnd();
$convertToNative = Amount::convertToPrimary();
$default = Amount::getPrimaryCurrency();
$convertToPrimary = Amount::convertToPrimary();
$primary = Amount::getPrimaryCurrency();
$response = [];
// get all bills:
@@ -90,14 +90,14 @@ class BillController extends Controller
$currencyCode = $journal['currency_code'];
$field = 'amount';
// use the native amount if the user wants to convert to native currency
if ($convertToNative && $currencyId !== $default->id) {
$currencyId = $default->id;
$currencyCode = $default->code;
$field = 'native_amount';
// use the primary amount if the user wants to convert to primary currency
if ($convertToPrimary && $currencyId !== $primary->id) {
$currencyId = $primary->id;
$currencyCode = $primary->code;
$field = 'pc_amount';
}
// use foreign amount when the foreign currency IS the default currency.
if ($convertToNative && $journal['currency_id'] !== $default->id && $default->id === $journal['foreign_currency_id']) {
if ($convertToPrimary && $journal['currency_id'] !== $primary->id && $primary->id === $journal['foreign_currency_id']) {
$field = 'foreign_amount';
}
Log::debug(sprintf('Journal #%d in bill #%d will use %s (%s %s)', $journal['transaction_group_id'], $billId, $field, $currencyCode, $journal[$field] ?? '0'));
@@ -132,8 +132,8 @@ class BillController extends Controller
$accounts = $request->getAssetAccounts();
$start = $request->getStart();
$end = $request->getEnd();
$convertToNative = Amount::convertToPrimary();
$default = Amount::getPrimaryCurrency();
$convertToPrimary = Amount::convertToPrimary();
$primary = Amount::getPrimaryCurrency();
$response = [];
// collect all expenses in this period (regardless of type) by the given bills and accounts.
@@ -148,14 +148,14 @@ class BillController extends Controller
$currencyCode = $journal['currency_code'];
$field = 'amount';
// use the native amount if the user wants to convert to native currency
if ($convertToNative && $currencyId !== $default->id) {
$currencyId = $default->id;
$currencyCode = $default->code;
$field = 'native_amount';
// use the primary amount if the user wants to convert to primary currency
if ($convertToPrimary && $currencyId !== $primary->id) {
$currencyId = $primary->id;
$currencyCode = $primary->code;
$field = 'pc_amount';
}
// use foreign amount when the foreign currency IS the default currency.
if ($convertToNative && $journal['currency_id'] !== $default->id && $default->id === $journal['foreign_currency_id']) {
if ($convertToPrimary && $journal['currency_id'] !== $primary->id && $primary->id === $journal['foreign_currency_id']) {
$field = 'foreign_amount';
}
Log::debug(sprintf('Journal #%d will use %s (%s %s)', $journal['transaction_group_id'], $field, $currencyCode, $journal[$field] ?? '0'));

View File

@@ -47,8 +47,8 @@ class PeriodController extends Controller
$start = $request->getStart();
$end = $request->getEnd();
$response = [];
$convertToNative = Amount::convertToPrimary();
$default = Amount::getPrimaryCurrency();
$convertToPrimary = Amount::convertToPrimary();
$primary = Amount::getPrimaryCurrency();
// collect all expenses in this period (regardless of type)
$collector = app(GroupCollectorInterface::class);
@@ -59,19 +59,19 @@ class PeriodController extends Controller
$amount = '0';
$currencyId = (int) $journal['currency_id'];
$currencyCode = $journal['currency_code'];
if ($convertToNative) {
if ($convertToPrimary) {
$amount = Amount::getAmountFromJournal($journal);
if ($default->id !== (int) $journal['currency_id'] && $default->id !== (int) $journal['foreign_currency_id']) {
$currencyId = $default->id;
$currencyCode = $default->code;
if ($primary->id !== (int) $journal['currency_id'] && $primary->id !== (int) $journal['foreign_currency_id']) {
$currencyId = $primary->id;
$currencyCode = $primary->code;
}
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'];
$currencyCode = $journal['foreign_currency_code'];
}
Log::debug(sprintf('[a] Add amount %s %s', $currencyCode, $amount));
}
if (!$convertToNative) {
if (!$convertToPrimary) {
// ignore the amount in foreign currency.
Log::debug(sprintf('[b] Add amount %s %s', $currencyCode, $journal['amount']));
$amount = $journal['amount'];

View File

@@ -68,8 +68,8 @@ class TagController extends Controller
$start = $request->getStart();
$end = $request->getEnd();
$response = [];
$convertToNative = Amount::convertToPrimary();
$default = Amount::getPrimaryCurrency();
$convertToPrimary = Amount::convertToPrimary();
$primary = Amount::getPrimaryCurrency();
// collect all expenses in this period (regardless of type) by the given bills and accounts.
$collector = app(GroupCollectorInterface::class);
@@ -83,19 +83,19 @@ class TagController extends Controller
$amount = '0';
$currencyId = (int) $journal['currency_id'];
$currencyCode = $journal['currency_code'];
if ($convertToNative) {
if ($convertToPrimary) {
$amount = Amount::getAmountFromJournal($journal);
if ($default->id !== (int) $journal['currency_id'] && $default->id !== (int) $journal['foreign_currency_id']) {
$currencyId = $default->id;
$currencyCode = $default->code;
if ($primary->id !== (int) $journal['currency_id'] && $primary->id !== (int) $journal['foreign_currency_id']) {
$currencyId = $primary->id;
$currencyCode = $primary->code;
}
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'];
$currencyCode = $journal['foreign_currency_code'];
}
Log::debug(sprintf('[a] Add amount %s %s', $currencyCode, $amount));
}
if (!$convertToNative) {
if (!$convertToPrimary) {
// ignore the amount in foreign currency.
Log::debug(sprintf('[b] Add amount %s %s', $currencyCode, $journal['amount']));
$amount = $journal['amount'];

View File

@@ -46,8 +46,8 @@ class PeriodController extends Controller
$start = $request->getStart();
$end = $request->getEnd();
$response = [];
$convertToNative = Amount::convertToPrimary();
$default = Amount::getPrimaryCurrency();
$convertToPrimary = Amount::convertToPrimary();
$primary = Amount::getPrimaryCurrency();
// collect all expenses in this period (regardless of type)
$collector = app(GroupCollectorInterface::class);
@@ -57,15 +57,15 @@ class PeriodController extends Controller
// currency
$currencyId = $journal['currency_id'];
$currencyCode = $journal['currency_code'];
$field = $convertToNative && $currencyId !== $default->id ? 'native_amount' : 'amount';
$field = $convertToPrimary && $currencyId !== $primary->id ? 'pc_amount' : 'amount';
// perhaps use default currency instead?
if ($convertToNative && $journal['currency_id'] !== $default->id) {
$currencyId = $default->id;
$currencyCode = $default->code;
if ($convertToPrimary && $journal['currency_id'] !== $primary->id) {
$currencyId = $primary->id;
$currencyCode = $primary->code;
}
// use foreign amount when the foreign currency IS the default currency.
if ($convertToNative && $journal['currency_id'] !== $default->id && $default->id === $journal['foreign_currency_id']) {
if ($convertToPrimary && $journal['currency_id'] !== $primary->id && $primary->id === $journal['foreign_currency_id']) {
$field = 'foreign_amount';
}

View File

@@ -68,8 +68,8 @@ class TagController extends Controller
$start = $request->getStart();
$end = $request->getEnd();
$response = [];
$convertToNative = Amount::convertToPrimary();
$default = Amount::getPrimaryCurrency();
$convertToPrimary = Amount::convertToPrimary();
$primary = Amount::getPrimaryCurrency();
// collect all expenses in this period (regardless of type) by the given bills and accounts.
$collector = app(GroupCollectorInterface::class);
@@ -82,15 +82,15 @@ class TagController extends Controller
// currency
$currencyId = $journal['currency_id'];
$currencyCode = $journal['currency_code'];
$field = $convertToNative && $currencyId !== $default->id ? 'native_amount' : 'amount';
$field = $convertToPrimary && $currencyId !== $primary->id ? 'pc_amount' : 'amount';
// perhaps use default currency instead?
if ($convertToNative && $journal['currency_id'] !== $default->id) {
$currencyId = $default->id;
$currencyCode = $default->code;
if ($convertToPrimary && $journal['currency_id'] !== $primary->id) {
$currencyId = $primary->id;
$currencyCode = $primary->code;
}
// use foreign amount when the foreign currency IS the default currency.
if ($convertToNative && $journal['currency_id'] !== $default->id && $default->id === $journal['foreign_currency_id']) {
if ($convertToPrimary && $journal['currency_id'] !== $primary->id && $primary->id === $journal['foreign_currency_id']) {
$field = 'foreign_amount';
}

View File

@@ -46,8 +46,8 @@ class PeriodController extends Controller
$start = $request->getStart();
$end = $request->getEnd();
$response = [];
$convertToNative = Amount::convertToPrimary();
$default = Amount::getPrimaryCurrency();
$convertToPrimary = Amount::convertToPrimary();
$primary = Amount::getPrimaryCurrency();
// collect all expenses in this period (regardless of type)
$collector = app(GroupCollectorInterface::class);
@@ -57,15 +57,15 @@ class PeriodController extends Controller
// currency
$currencyId = $journal['currency_id'];
$currencyCode = $journal['currency_code'];
$field = $convertToNative && $currencyId !== $default->id ? 'native_amount' : 'amount';
$field = $convertToPrimary && $currencyId !== $primary->id ? 'pc_amount' : 'amount';
// perhaps use default currency instead?
if ($convertToNative && $journal['currency_id'] !== $default->id) {
$currencyId = $default->id;
$currencyCode = $default->code;
if ($convertToPrimary && $journal['currency_id'] !== $primary->id) {
$currencyId = $primary->id;
$currencyCode = $primary->code;
}
// use foreign amount when the foreign currency IS the default currency.
if ($convertToNative && $journal['currency_id'] !== $default->id && $default->id === $journal['foreign_currency_id']) {
if ($convertToPrimary && $journal['currency_id'] !== $primary->id && $primary->id === $journal['foreign_currency_id']) {
$field = 'foreign_amount';
}

View File

@@ -66,8 +66,8 @@ class TagController extends Controller
$start = $request->getStart();
$end = $request->getEnd();
$response = [];
$convertToNative = Amount::convertToPrimary();
$default = Amount::getPrimaryCurrency();
$convertToPrimary = Amount::convertToPrimary();
$primary = Amount::getPrimaryCurrency();
// collect all expenses in this period (regardless of type) by the given bills and accounts.
@@ -81,15 +81,15 @@ class TagController extends Controller
// currency
$currencyId = $journal['currency_id'];
$currencyCode = $journal['currency_code'];
$field = $convertToNative && $currencyId !== $default->id ? 'native_amount' : 'amount';
$field = $convertToPrimary && $currencyId !== $primary->id ? 'pc_amount' : 'amount';
// perhaps use default currency instead?
if ($convertToNative && $journal['currency_id'] !== $default->id) {
$currencyId = $default->id;
$currencyCode = $default->code;
if ($convertToPrimary && $journal['currency_id'] !== $primary->id) {
$currencyId = $primary->id;
$currencyCode = $primary->code;
}
// use foreign amount when the foreign currency IS the default currency.
if ($convertToNative && $journal['currency_id'] !== $default->id && $default->id === $journal['foreign_currency_id']) {
if ($convertToPrimary && $journal['currency_id'] !== $primary->id && $primary->id === $journal['foreign_currency_id']) {
$field = 'foreign_amount';
}

View File

@@ -97,7 +97,7 @@ class ShowController extends Controller
$admin = auth()->user();
$enrichment = new AccountEnrichment();
$enrichment->setUser($admin);
$enrichment->setNative($this->primaryCurrency);
$enrichment->setPrimary($this->primaryCurrency);
$accounts = $enrichment->enrich($accounts);
// make paginator:
@@ -132,7 +132,7 @@ class ShowController extends Controller
$admin = auth()->user();
$enrichment = new AccountEnrichment();
$enrichment->setUser($admin);
$enrichment->setNative($this->primaryCurrency);
$enrichment->setPrimary($this->primaryCurrency);
$account = $enrichment->enrichSingle($account);

View File

@@ -76,7 +76,7 @@ class StoreController extends Controller
$admin = auth()->user();
$enrichment = new AccountEnrichment();
$enrichment->setUser($admin);
$enrichment->setNative($this->primaryCurrency);
$enrichment->setPrimary($this->primaryCurrency);
$account = $enrichment->enrichSingle($account);
/** @var AccountTransformer $transformer */

View File

@@ -81,7 +81,7 @@ class UpdateController extends Controller
$admin = auth()->user();
$enrichment = new AccountEnrichment();
$enrichment->setUser($admin);
$enrichment->setNative($this->primaryCurrency);
$enrichment->setPrimary($this->primaryCurrency);
$account = $enrichment->enrichSingle($account);
/** @var AccountTransformer $transformer */

View File

@@ -83,8 +83,8 @@ class ShowController extends Controller
$admin = auth()->user();
$enrichment = new SubscriptionEnrichment();
$enrichment->setUser($admin);
$enrichment->setConvertToNative($this->convertToPrimary);
$enrichment->setNative($this->primaryCurrency);
$enrichment->setConvertToPrimary($this->convertToPrimary);
$enrichment->setPrimary($this->primaryCurrency);
$enrichment->setStart($this->parameters->get('start'));
$enrichment->setEnd($this->parameters->get('end'));
$bills = $enrichment->enrich($bills);
@@ -114,8 +114,8 @@ class ShowController extends Controller
$admin = auth()->user();
$enrichment = new SubscriptionEnrichment();
$enrichment->setUser($admin);
$enrichment->setConvertToNative($this->convertToPrimary);
$enrichment->setNative($this->primaryCurrency);
$enrichment->setConvertToPrimary($this->convertToPrimary);
$enrichment->setPrimary($this->primaryCurrency);
$enrichment->setStart($this->parameters->get('start'));
$enrichment->setEnd($this->parameters->get('end'));
$bill = $enrichment->enrichSingle($bill);

View File

@@ -79,8 +79,8 @@ class StoreController extends Controller
$admin = auth()->user();
$enrichment = new SubscriptionEnrichment();
$enrichment->setUser($admin);
$enrichment->setConvertToNative($this->convertToPrimary);
$enrichment->setNative($this->primaryCurrency);
$enrichment->setConvertToPrimary($this->convertToPrimary);
$enrichment->setPrimary($this->primaryCurrency);
$enrichment->setStart($this->parameters->get('start'));
$enrichment->setEnd($this->parameters->get('end'));
$bill = $enrichment->enrichSingle($bill);

View File

@@ -74,8 +74,8 @@ class UpdateController extends Controller
$admin = auth()->user();
$enrichment = new SubscriptionEnrichment();
$enrichment->setUser($admin);
$enrichment->setConvertToNative($this->convertToPrimary);
$enrichment->setNative($this->primaryCurrency);
$enrichment->setConvertToPrimary($this->convertToPrimary);
$enrichment->setPrimary($this->primaryCurrency);
$enrichment->setStart($this->parameters->get('start'));
$enrichment->setEnd($this->parameters->get('end'));
$bill = $enrichment->enrichSingle($bill);

View File

@@ -85,8 +85,8 @@ class ListController extends Controller
$admin = auth()->user();
$enrichment = new SubscriptionEnrichment();
$enrichment->setUser($admin);
$enrichment->setConvertToNative($this->convertToPrimary);
$enrichment->setNative($this->primaryCurrency);
$enrichment->setConvertToPrimary($this->convertToPrimary);
$enrichment->setPrimary($this->primaryCurrency);
$enrichment->setStart($this->parameters->get('start'));
$enrichment->setEnd($this->parameters->get('end'));
$bills = $enrichment->enrich($bills);

View File

@@ -84,7 +84,7 @@ class ListController extends Controller
$admin = auth()->user();
$enrichment = new AccountEnrichment();
$enrichment->setUser($admin);
$enrichment->setNative($this->primaryCurrency);
$enrichment->setPrimary($this->primaryCurrency);
$accounts = $enrichment->enrich($accounts);
// make paginator:

View File

@@ -108,7 +108,7 @@ class ListController extends Controller
$admin = auth()->user();
$enrichment = new AccountEnrichment();
$enrichment->setUser($admin);
$enrichment->setNative($this->primaryCurrency);
$enrichment->setPrimary($this->primaryCurrency);
$accounts = $enrichment->enrich($accounts);
// make paginator:
@@ -188,8 +188,8 @@ class ListController extends Controller
$admin = auth()->user();
$enrichment = new SubscriptionEnrichment();
$enrichment->setUser($admin);
$enrichment->setConvertToNative($this->convertToPrimary);
$enrichment->setNative($this->primaryCurrency);
$enrichment->setConvertToPrimary($this->convertToPrimary);
$enrichment->setPrimary($this->primaryCurrency);
$enrichment->setStart($this->parameters->get('start'));
$enrichment->setEnd($this->parameters->get('end'));
$bills = $enrichment->enrichSingle($bills);

View File

@@ -107,7 +107,7 @@ class ShowController extends Controller
/** @var User $user */
$user = auth()->user();
$manager = $this->getManager();
$this->parameters->set('nativeCurrency', $this->primaryCurrency);
$this->parameters->set('primaryCurrency', $this->primaryCurrency);
// update fields with user info.
$currency->refreshForUser($user);
@@ -122,9 +122,6 @@ class ShowController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/currencies/getNativeCurrency
*
* Show a currency.
*
* @throws FireflyException

View File

@@ -99,11 +99,6 @@ class UpdateController extends Controller
}
/**
* This endpoint is documented at:
* https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/currencies/nativeCurrency
*
* Make the currency a default currency.
*
* @throws FireflyException
*/
public function makeDefault(TransactionCurrency $currency): JsonResponse

View File

@@ -89,7 +89,7 @@ class AccountController extends Controller
$admin = auth()->user();
$enrichment = new AccountEnrichment();
$enrichment->setUser($admin);
$enrichment->setNative($this->primaryCurrency);
$enrichment->setPrimary($this->primaryCurrency);
$accounts = $enrichment->enrich($accounts);
/** @var AccountTransformer $transformer */

View File

@@ -127,13 +127,13 @@ class BasicController extends Controller
{
Log::debug('getBalanceInformation');
// some config settings
$convertToNative = Amount::convertToPrimary();
$default = Amount::getPrimaryCurrency();
$convertToPrimary = Amount::convertToPrimary();
$primary = Amount::getPrimaryCurrency();
// prep some arrays:
$sums = [];
$return = [];
$currencies = [
$default->id => $default,
$primary->id => $primary,
];
// collect income of user using the new group collector.
@@ -151,32 +151,32 @@ class BasicController extends Controller
$set = $collector->setRange($start, $end)->setPage($this->parameters->get('page'))->setTypes([TransactionTypeEnum::WITHDRAWAL->value])->getExtractedJournals();
$expenses = $summarizer->groupByCurrencyId($set, 'negative', false);
// if convert to native, do so right now.
if ($convertToNative) {
// if convert to primary, do so right now.
if ($convertToPrimary) {
$newExpenses = [
$default->id => [
'currency_id' => $default->id,
'currency_code' => $default->code,
'currency_symbol' => $default->symbol,
'currency_decimal_places' => $default->decimal_places,
$primary->id => [
'currency_id' => $primary->id,
'currency_code' => $primary->code,
'currency_symbol' => $primary->symbol,
'currency_decimal_places' => $primary->decimal_places,
'sum' => '0',
],
];
$newIncomes = [
$default->id => [
'currency_id' => $default->id,
'currency_code' => $default->code,
'currency_symbol' => $default->symbol,
'currency_decimal_places' => $default->decimal_places,
$primary->id => [
'currency_id' => $primary->id,
'currency_code' => $primary->code,
'currency_symbol' => $primary->symbol,
'currency_decimal_places' => $primary->decimal_places,
'sum' => '0',
],
];
$sums = [
$default->id => [
'currency_id' => $default->id,
'currency_code' => $default->code,
'currency_symbol' => $default->symbol,
'currency_decimal_places' => $default->decimal_places,
$primary->id => [
'currency_id' => $primary->id,
'currency_code' => $primary->code,
'currency_symbol' => $primary->symbol,
'currency_decimal_places' => $primary->decimal_places,
'sum' => '0',
],
];
@@ -188,36 +188,36 @@ class BasicController extends Controller
// loop over either one.
foreach ($array as $entry) {
// if it is the native currency already.
if ($entry['currency_id'] === $default->id) {
$sums[$default->id]['sum'] = bcadd((string) $entry['sum'], $sums[$default->id]['sum']);
// if it is the primary currency already.
if ($entry['currency_id'] === $primary->id) {
$sums[$primary->id]['sum'] = bcadd((string) $entry['sum'], $sums[$primary->id]['sum']);
// don't forget to add it to newExpenses and newIncome
if (0 === $index) {
$newExpenses[$default->id]['sum'] = bcadd($newExpenses[$default->id]['sum'], (string) $entry['sum']);
$newExpenses[$primary->id]['sum'] = bcadd($newExpenses[$primary->id]['sum'], (string) $entry['sum']);
}
if (1 === $index) {
$newIncomes[$default->id]['sum'] = bcadd($newIncomes[$default->id]['sum'], (string) $entry['sum']);
$newIncomes[$primary->id]['sum'] = bcadd($newIncomes[$primary->id]['sum'], (string) $entry['sum']);
}
continue;
}
$currencies[$entry['currency_id']] ??= $this->currencyRepos->find($entry['currency_id']);
$convertedSum = $converter->convert($currencies[$entry['currency_id']], $default, $start, $entry['sum']);
$sums[$default->id]['sum'] = bcadd($sums[$default->id]['sum'], $convertedSum);
$convertedSum = $converter->convert($currencies[$entry['currency_id']], $primary, $start, $entry['sum']);
$sums[$primary->id]['sum'] = bcadd($sums[$primary->id]['sum'], $convertedSum);
if (0 === $index) {
$newExpenses[$default->id]['sum'] = bcadd($newExpenses[$default->id]['sum'], $convertedSum);
$newExpenses[$primary->id]['sum'] = bcadd($newExpenses[$primary->id]['sum'], $convertedSum);
}
if (1 === $index) {
$newIncomes[$default->id]['sum'] = bcadd($newIncomes[$default->id]['sum'], $convertedSum);
$newIncomes[$primary->id]['sum'] = bcadd($newIncomes[$primary->id]['sum'], $convertedSum);
}
}
}
$incomes = $newIncomes;
$expenses = $newExpenses;
}
if (!$convertToNative) {
if (!$convertToPrimary) {
foreach ([$expenses, $incomes] as $array) {
foreach ($array as $entry) {
$currencyId = $entry['currency_id'];
@@ -626,7 +626,7 @@ class BasicController extends Controller
$netWorthSet = $netWorthHelper->byAccounts($filtered, $end);
$return = [];
foreach ($netWorthSet as $key => $data) {
if ('native' === $key) {
if ('pc' === $key) {
continue;
}
$amount = $data['balance'];

View File

@@ -85,7 +85,7 @@ class PreferencesController extends Controller
$manager = $this->getManager();
if ('currencyPreference' === $preference->name) {
throw new FireflyException('Please use api/v1/currencies/native instead.');
throw new FireflyException('Please use api/v1/currencies/primary instead.');
}
/** @var PreferenceTransformer $transformer */
@@ -132,7 +132,7 @@ class PreferencesController extends Controller
public function update(PreferenceUpdateRequest $request, Preference $preference): JsonResponse
{
if ('currencyPreference' === $preference->name) {
throw new FireflyException('Please use api/v1/currencies/native instead.');
throw new FireflyException('Please use api/v1/currencies/primary instead.');
}
$manager = $this->getManager();