mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Rename "native" to "primary".
This commit is contained in:
@@ -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] ??= [
|
||||
|
@@ -40,9 +40,9 @@ interface NetWorthInterface
|
||||
* Collect net worth based on the given set of accounts.
|
||||
*
|
||||
* Returns X arrays with the net worth in each given currency, and the net worth in
|
||||
* of that amount in the native currency.
|
||||
* of that amount in the primary currency.
|
||||
*
|
||||
* Includes extra array with the total(!) net worth in the native currency.
|
||||
* Includes extra array with the total(!) net worth in the primary currency.
|
||||
*/
|
||||
public function byAccounts(Collection $accounts, Carbon $date): array;
|
||||
|
||||
|
Reference in New Issue
Block a user