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

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