Remove references to user group specific repositories and instead use the normal ones.

This commit is contained in:
James Cole
2025-03-08 15:10:24 +01:00
parent 113eb84461
commit 8eb0313841
39 changed files with 202 additions and 221 deletions

View File

@@ -30,7 +30,6 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account;
use FireflyIII\Models\UserGroup;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\UserGroups\Account\AccountRepositoryInterface as AdminAccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Support\CacheProperties;
use FireflyIII\Support\Facades\Amount;
@@ -49,8 +48,6 @@ use Illuminate\Support\Facades\Log;
class NetWorth implements NetWorthInterface
{
private AccountRepositoryInterface $accountRepository;
private AdminAccountRepositoryInterface $adminAccountRepository;
private CurrencyRepositoryInterface $currencyRepos;
private User $user;
private ?UserGroup $userGroup;
@@ -85,7 +82,7 @@ class NetWorth implements NetWorthInterface
/** @var Account $account */
foreach ($accounts as $account) {
Log::debug(sprintf('Now at account #%d ("%s")', $account->id, $account->name));
$currency = $this->getRepository()->getAccountCurrency($account) ?? $default;
$currency = $this->accountRepository->getAccountCurrency($account) ?? $default;
$useNative = $convertToNative && $default->id !== $currency->id;
$currency = $useNative ? $default : $currency;
$currencyCode = $currency->code;
@@ -118,15 +115,6 @@ class NetWorth implements NetWorthInterface
return $netWorth;
}
private function getRepository(): AccountRepositoryInterface|AdminAccountRepositoryInterface
{
if (null === $this->userGroup) {
return $this->accountRepository;
}
return $this->adminAccountRepository;
}
public function setUser(null|Authenticatable|User $user): void
{
if (!$user instanceof User) {
@@ -146,8 +134,8 @@ class NetWorth implements NetWorthInterface
public function setUserGroup(UserGroup $userGroup): void
{
$this->userGroup = $userGroup;
$this->adminAccountRepository = app(AdminAccountRepositoryInterface::class);
$this->adminAccountRepository->setUserGroup($userGroup);
$this->accountRepository = app(AccountRepositoryInterface::class);
$this->accountRepository->setUserGroup($userGroup);
}
/**
@@ -163,7 +151,7 @@ class NetWorth implements NetWorthInterface
Log::debug(sprintf('SumNetWorth: finalAccountsBalance("%s")', $date->format('Y-m-d H:i:s')));
$balances = Steam::finalAccountsBalance($accounts, $date);
foreach ($accounts as $account) {
$currency = $this->getRepository()->getAccountCurrency($account);
$currency = $this->accountRepository->getAccountCurrency($account);
$balance = $balances[$account->id]['balance'] ?? '0';
// always subtract virtual balance.
@@ -188,14 +176,14 @@ class NetWorth implements NetWorthInterface
private function getAccounts(): Collection
{
$accounts = $this->getRepository()->getAccountsByType(
$accounts = $this->accountRepository->getAccountsByType(
[AccountTypeEnum::ASSET->value, AccountTypeEnum::DEFAULT->value, AccountTypeEnum::LOAN->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::MORTGAGE->value]
);
$filtered = new Collection();
/** @var Account $account */
foreach ($accounts as $account) {
if (1 === (int) $this->getRepository()->getMetaValue($account, 'include_net_worth')) {
if (1 === (int) $this->accountRepository->getMetaValue($account, 'include_net_worth')) {
$filtered->push($account);
}
}