mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Code reordering and reformatting. I should really start employing style CI.
This commit is contained in:
@@ -40,8 +40,8 @@ class CreditRecalculateService
|
||||
{
|
||||
private ?Account $account;
|
||||
private ?TransactionGroup $group;
|
||||
private array $work;
|
||||
private AccountRepositoryInterface $repository;
|
||||
private array $work;
|
||||
|
||||
/**
|
||||
* CreditRecalculateService constructor.
|
||||
@@ -79,50 +79,6 @@ class CreditRecalculateService
|
||||
$this->processWork();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function processWork(): void
|
||||
{
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
foreach ($this->work as $account) {
|
||||
$this->processWorkAccount($account);
|
||||
}
|
||||
Log::debug(sprintf('Done with %s', __METHOD__));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*/
|
||||
private function processWorkAccount(Account $account): void
|
||||
{
|
||||
Log::debug(sprintf('Now in %s(#%d)', __METHOD__, $account->id));
|
||||
|
||||
// get opening balance (if present)
|
||||
$this->repository->setUser($account->user);
|
||||
$startOfDebt = $this->repository->getOpeningBalanceAmount($account) ?? '0';
|
||||
$leftOfDebt = app('steam')->positive($startOfDebt);
|
||||
|
||||
/** @var AccountMetaFactory $factory */
|
||||
$factory = app(AccountMetaFactory::class);
|
||||
$factory->crud($account, 'start_of_debt', $startOfDebt);
|
||||
|
||||
// get direction of liability:
|
||||
$direction = (string)$this->repository->getMetaValue($account, 'liability_direction');
|
||||
|
||||
// now loop all transactions (except opening balance and credit thing)
|
||||
$transactions = $account->transactions()->get();
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$leftOfDebt = $this->processTransaction($account, $direction, $transaction, $leftOfDebt);
|
||||
}
|
||||
$factory->crud($account, 'current_debt', $leftOfDebt);
|
||||
|
||||
|
||||
Log::debug(sprintf('Done with %s(#%d)', __METHOD__, $account->id));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -221,19 +177,46 @@ class CreditRecalculateService
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account|null $account
|
||||
*
|
||||
*/
|
||||
public function setAccount(?Account $account): void
|
||||
private function processWork(): void
|
||||
{
|
||||
$this->account = $account;
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
foreach ($this->work as $account) {
|
||||
$this->processWorkAccount($account);
|
||||
}
|
||||
Log::debug(sprintf('Done with %s', __METHOD__));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionGroup $group
|
||||
* @param Account $account
|
||||
*/
|
||||
public function setGroup(TransactionGroup $group): void
|
||||
private function processWorkAccount(Account $account): void
|
||||
{
|
||||
$this->group = $group;
|
||||
Log::debug(sprintf('Now in %s(#%d)', __METHOD__, $account->id));
|
||||
|
||||
// get opening balance (if present)
|
||||
$this->repository->setUser($account->user);
|
||||
$startOfDebt = $this->repository->getOpeningBalanceAmount($account) ?? '0';
|
||||
$leftOfDebt = app('steam')->positive($startOfDebt);
|
||||
|
||||
/** @var AccountMetaFactory $factory */
|
||||
$factory = app(AccountMetaFactory::class);
|
||||
$factory->crud($account, 'start_of_debt', $startOfDebt);
|
||||
|
||||
// get direction of liability:
|
||||
$direction = (string)$this->repository->getMetaValue($account, 'liability_direction');
|
||||
|
||||
// now loop all transactions (except opening balance and credit thing)
|
||||
$transactions = $account->transactions()->get();
|
||||
/** @var Transaction $transaction */
|
||||
foreach ($transactions as $transaction) {
|
||||
$leftOfDebt = $this->processTransaction($account, $direction, $transaction, $leftOfDebt);
|
||||
}
|
||||
$factory->crud($account, 'current_debt', $leftOfDebt);
|
||||
|
||||
|
||||
Log::debug(sprintf('Done with %s(#%d)', __METHOD__, $account->id));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -292,5 +275,21 @@ class CreditRecalculateService
|
||||
return $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Account|null $account
|
||||
*/
|
||||
public function setAccount(?Account $account): void
|
||||
{
|
||||
$this->account = $account;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransactionGroup $group
|
||||
*/
|
||||
public function setGroup(TransactionGroup $group): void
|
||||
{
|
||||
$this->group = $group;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user