mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Code cleanup.
This commit is contained in:
@@ -50,7 +50,7 @@ class NetWorth implements NetWorthInterface
|
||||
|
||||
private CurrencyRepositoryInterface $currencyRepos;
|
||||
private User $user;
|
||||
private null | UserGroup $userGroup;
|
||||
private null|UserGroup $userGroup;
|
||||
|
||||
/**
|
||||
* This method collects the user's net worth in ALL the user's currencies
|
||||
@@ -58,10 +58,6 @@ class NetWorth implements NetWorthInterface
|
||||
*
|
||||
* The set of accounts has to be fed to it.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return array
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function byAccounts(Collection $accounts, Carbon $date): array
|
||||
@@ -146,23 +142,9 @@ class NetWorth implements NetWorthInterface
|
||||
return $netWorth;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AdminAccountRepositoryInterface|AccountRepositoryInterface
|
||||
*/
|
||||
private function getRepository(): AdminAccountRepositoryInterface | AccountRepositoryInterface
|
||||
public function setUser(null|Authenticatable|User $user): void
|
||||
{
|
||||
if (null === $this->userGroup) {
|
||||
return $this->accountRepository;
|
||||
}
|
||||
return $this->adminAccountRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void
|
||||
{
|
||||
if (!($user instanceof User)) {
|
||||
if (!$user instanceof User) {
|
||||
return;
|
||||
}
|
||||
$this->user = $user;
|
||||
@@ -176,9 +158,6 @@ class NetWorth implements NetWorthInterface
|
||||
$this->currencyRepos->setUser($this->user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function setUserGroup(UserGroup $userGroup): void
|
||||
{
|
||||
$this->userGroup = $userGroup;
|
||||
@@ -187,7 +166,6 @@ class NetWorth implements NetWorthInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @deprecated
|
||||
*/
|
||||
public function sumNetWorthByCurrency(Carbon $date): array
|
||||
@@ -222,21 +200,29 @@ class NetWorth implements NetWorthInterface
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
private function getRepository(): AccountRepositoryInterface|AdminAccountRepositoryInterface
|
||||
{
|
||||
if (null === $this->userGroup) {
|
||||
return $this->accountRepository;
|
||||
}
|
||||
|
||||
return $this->adminAccountRepository;
|
||||
}
|
||||
|
||||
private function getAccounts(): Collection
|
||||
{
|
||||
$accounts = $this->getRepository()->getAccountsByType(
|
||||
[AccountType::ASSET, AccountType::DEFAULT, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]
|
||||
);
|
||||
$filtered = new Collection();
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
if (1 === (int)$this->getRepository()->getMetaValue($account, 'include_net_worth')) {
|
||||
$filtered->push($account);
|
||||
}
|
||||
}
|
||||
|
||||
return $filtered;
|
||||
}
|
||||
}
|
||||
|
@@ -31,7 +31,6 @@ use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Interface NetWorthInterface
|
||||
*
|
||||
*/
|
||||
interface NetWorthInterface
|
||||
{
|
||||
@@ -42,22 +41,11 @@ interface NetWorthInterface
|
||||
* of that amount in the native currency.
|
||||
*
|
||||
* Includes extra array with the total(!) net worth in the native currency.
|
||||
*
|
||||
* @param Collection $accounts
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function byAccounts(Collection $accounts, Carbon $date): array;
|
||||
|
||||
/**
|
||||
* @param User|Authenticatable|null $user
|
||||
*/
|
||||
public function setUser(User | Authenticatable | null $user): void;
|
||||
public function setUser(null|Authenticatable|User $user): void;
|
||||
|
||||
/**
|
||||
* @param UserGroup $userGroup
|
||||
*/
|
||||
public function setUserGroup(UserGroup $userGroup): void;
|
||||
|
||||
/**
|
||||
@@ -65,9 +53,6 @@ interface NetWorthInterface
|
||||
*
|
||||
* Same as above but cleaner function with less dependencies.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return array
|
||||
* @deprecated
|
||||
*/
|
||||
public function sumNetWorthByCurrency(Carbon $date): array;
|
||||
|
@@ -35,40 +35,28 @@ use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class PopupReport.
|
||||
*
|
||||
|
||||
*/
|
||||
class PopupReport implements PopupReportInterface
|
||||
{
|
||||
/**
|
||||
* Collect the transactions for one account and one budget.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param Account $account
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function balanceForBudget(Budget $budget, Account $account, array $attributes): array
|
||||
{
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts(new Collection([$account]))
|
||||
->withAccountInformation()
|
||||
->withBudgetInformation()
|
||||
->withCategoryInformation()
|
||||
->setRange($attributes['startDate'], $attributes['endDate'])->setBudget($budget);
|
||||
->withAccountInformation()
|
||||
->withBudgetInformation()
|
||||
->withCategoryInformation()
|
||||
->setRange($attributes['startDate'], $attributes['endDate'])->setBudget($budget)
|
||||
;
|
||||
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect the transactions for one account and no budget.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function balanceForNoBudget(Account $account, array $attributes): array
|
||||
{
|
||||
@@ -80,6 +68,7 @@ class PopupReport implements PopupReportInterface
|
||||
$repos = app(CurrencyRepositoryInterface::class);
|
||||
$currency = $repos->find((int)$currencyId);
|
||||
}
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector
|
||||
@@ -88,7 +77,8 @@ class PopupReport implements PopupReportInterface
|
||||
->withAccountInformation()
|
||||
->withCategoryInformation()
|
||||
->setRange($attributes['startDate'], $attributes['endDate'])
|
||||
->withoutBudget();
|
||||
->withoutBudget()
|
||||
;
|
||||
|
||||
if (null !== $currency) {
|
||||
$collector->setCurrency($currency);
|
||||
@@ -99,11 +89,6 @@ class PopupReport implements PopupReportInterface
|
||||
|
||||
/**
|
||||
* Collect the transactions for a budget.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function byBudget(Budget $budget, array $attributes): array
|
||||
{
|
||||
@@ -115,13 +100,15 @@ class PopupReport implements PopupReportInterface
|
||||
$repos = app(CurrencyRepositoryInterface::class);
|
||||
$currency = $repos->find((int)$currencyId);
|
||||
}
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector->setAccounts($attributes['accounts'])
|
||||
->withAccountInformation()
|
||||
->withBudgetInformation()
|
||||
->withCategoryInformation()
|
||||
->setRange($attributes['startDate'], $attributes['endDate']);
|
||||
->withAccountInformation()
|
||||
->withBudgetInformation()
|
||||
->withCategoryInformation()
|
||||
->setRange($attributes['startDate'], $attributes['endDate'])
|
||||
;
|
||||
|
||||
if (null !== $currency) {
|
||||
$collector->setCurrency($currency);
|
||||
@@ -139,11 +126,6 @@ class PopupReport implements PopupReportInterface
|
||||
|
||||
/**
|
||||
* Collect journals by a category.
|
||||
*
|
||||
* @param Category|null $category
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function byCategory(?Category $category, array $attributes): array
|
||||
{
|
||||
@@ -160,11 +142,12 @@ class PopupReport implements PopupReportInterface
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
$collector->setAccounts($attributes['accounts'])
|
||||
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER, TransactionType::DEPOSIT])
|
||||
->withAccountInformation()
|
||||
->withBudgetInformation()
|
||||
->withCategoryInformation()
|
||||
->setRange($attributes['startDate'], $attributes['endDate'])->withAccountInformation();
|
||||
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER, TransactionType::DEPOSIT])
|
||||
->withAccountInformation()
|
||||
->withBudgetInformation()
|
||||
->withCategoryInformation()
|
||||
->setRange($attributes['startDate'], $attributes['endDate'])->withAccountInformation()
|
||||
;
|
||||
|
||||
if (null !== $category) {
|
||||
$collector->setCategory($category);
|
||||
@@ -182,11 +165,6 @@ class PopupReport implements PopupReportInterface
|
||||
|
||||
/**
|
||||
* Group transactions by expense.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function byExpenses(Account $account, array $attributes): array
|
||||
{
|
||||
@@ -210,35 +188,33 @@ class PopupReport implements PopupReportInterface
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
|
||||
// set report accounts + the request accounts:
|
||||
//$set = $attributes['accounts'] ?? new Collection;
|
||||
//$set->push($account);
|
||||
// $set = $attributes['accounts'] ?? new Collection;
|
||||
// $set->push($account);
|
||||
|
||||
$collector->setDestinationAccounts(new Collection([$account]))
|
||||
->setRange($attributes['startDate'], $attributes['endDate'])
|
||||
->withAccountInformation()
|
||||
->withBudgetInformation()
|
||||
->withCategoryInformation()
|
||||
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER]);
|
||||
->setRange($attributes['startDate'], $attributes['endDate'])
|
||||
->withAccountInformation()
|
||||
->withBudgetInformation()
|
||||
->withCategoryInformation()
|
||||
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||
;
|
||||
|
||||
if (null !== $currency) {
|
||||
$collector->setCurrency($currency);
|
||||
}
|
||||
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect transactions by income.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function byIncome(Account $account, array $attributes): array
|
||||
{
|
||||
/** @var JournalRepositoryInterface $repository */
|
||||
$repository = app(JournalRepositoryInterface::class);
|
||||
$repository->setUser($account->user);
|
||||
|
||||
/** @var GroupCollectorInterface $collector */
|
||||
$collector = app(GroupCollectorInterface::class);
|
||||
$collector
|
||||
@@ -249,7 +225,8 @@ class PopupReport implements PopupReportInterface
|
||||
->withAccountInformation()
|
||||
->withBudgetInformation()
|
||||
->withCategoryInformation()
|
||||
->withAccountInformation();
|
||||
->withAccountInformation()
|
||||
;
|
||||
|
||||
return $collector->getExtractedJournals();
|
||||
}
|
||||
|
@@ -34,62 +34,31 @@ interface PopupReportInterface
|
||||
{
|
||||
/**
|
||||
* Get balances for budget.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param Account $account
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function balanceForBudget(Budget $budget, Account $account, array $attributes): array;
|
||||
|
||||
/**
|
||||
* Get balances for transactions without a budget.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function balanceForNoBudget(Account $account, array $attributes): array;
|
||||
|
||||
/**
|
||||
* Group by budget.
|
||||
*
|
||||
* @param Budget $budget
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function byBudget(Budget $budget, array $attributes): array;
|
||||
|
||||
/**
|
||||
* Group by category.
|
||||
*
|
||||
* @param Category|null $category
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function byCategory(?Category $category, array $attributes): array;
|
||||
|
||||
/**
|
||||
* Do something with expense. Sorry, I am not very inspirational here.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function byExpenses(Account $account, array $attributes): array;
|
||||
|
||||
/**
|
||||
* Do something with income. Sorry, I am not very inspirational here.
|
||||
*
|
||||
* @param Account $account
|
||||
* @param array $attributes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function byIncome(Account $account, array $attributes): array;
|
||||
}
|
||||
|
@@ -33,8 +33,6 @@ use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class ReportHelper.
|
||||
*
|
||||
|
||||
*/
|
||||
class ReportHelper implements ReportHelperInterface
|
||||
{
|
||||
@@ -43,8 +41,6 @@ class ReportHelper implements ReportHelperInterface
|
||||
|
||||
/**
|
||||
* ReportHelper constructor.
|
||||
*
|
||||
* @param BudgetRepositoryInterface $budgetRepository
|
||||
*/
|
||||
public function __construct(BudgetRepositoryInterface $budgetRepository)
|
||||
{
|
||||
@@ -56,12 +52,6 @@ class ReportHelper implements ReportHelperInterface
|
||||
* the users bills and their payments.
|
||||
*
|
||||
* Excludes bills which have not had a payment on the mentioned accounts.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBillReport(Collection $accounts, Carbon $start, Carbon $end): array
|
||||
{
|
||||
@@ -112,10 +102,6 @@ class ReportHelper implements ReportHelperInterface
|
||||
|
||||
/**
|
||||
* Generate a list of months for the report.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listOfMonths(Carbon $date): array
|
||||
{
|
||||
|
@@ -36,21 +36,11 @@ interface ReportHelperInterface
|
||||
* the users bills and their payments.
|
||||
*
|
||||
* Excludes bills which have not had a payment on the mentioned accounts.
|
||||
*
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
* @param Collection $accounts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getBillReport(Collection $accounts, Carbon $start, Carbon $end): array;
|
||||
|
||||
/**
|
||||
* Generate a list of months.
|
||||
*
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function listOfMonths(Carbon $date): array;
|
||||
}
|
||||
|
Reference in New Issue
Block a user