Various code cleanup and fixed alignments.

This commit is contained in:
James Cole
2024-01-01 14:43:56 +01:00
parent 1368aafe5f
commit f963ac63f1
443 changed files with 3668 additions and 3672 deletions

View File

@@ -64,8 +64,8 @@ class NetWorth implements NetWorthInterface
public function byAccounts(Collection $accounts, Carbon $date): array
{
// start in the past, end in the future? use $date
$ids = implode(',', $accounts->pluck('id')->toArray());
$cache = new CacheProperties();
$ids = implode(',', $accounts->pluck('id')->toArray());
$cache = new CacheProperties();
$cache->addProperty($date);
$cache->addProperty('net-worth-by-accounts');
$cache->addProperty($ids);
@@ -78,7 +78,7 @@ class NetWorth implements NetWorthInterface
$converter = new ExchangeRateConverter();
// default "native" currency has everything twice, for consistency.
$netWorth = [
$netWorth = [
'native' => [
'balance' => '0',
'native_balance' => '0',
@@ -94,25 +94,25 @@ class NetWorth implements NetWorthInterface
'native_currency_decimal_places' => $default->decimal_places,
],
];
$balances = app('steam')->balancesByAccountsConverted($accounts, $date);
$balances = app('steam')->balancesByAccountsConverted($accounts, $date);
/** @var Account $account */
foreach ($accounts as $account) {
app('log')->debug(sprintf('Now at account #%d ("%s")', $account->id, $account->name));
$currency = $this->getRepository()->getAccountCurrency($account);
$currency = $this->getRepository()->getAccountCurrency($account);
if (null === $currency) {
$currency = app('amount')->getDefaultCurrency();
}
$currencyCode = $currency->code;
$balance = '0';
$nativeBalance = '0';
$currencyCode = $currency->code;
$balance = '0';
$nativeBalance = '0';
if (array_key_exists($account->id, $balances)) {
$balance = $balances[$account->id]['balance'] ?? '0';
$nativeBalance = $balances[$account->id]['native_balance'] ?? '0';
}
app('log')->debug(sprintf('Balance is %s, native balance is %s', $balance, $nativeBalance));
// always subtract virtual balance
$virtualBalance = $account->virtual_balance;
$virtualBalance = $account->virtual_balance;
if ('' !== $virtualBalance) {
$balance = bcsub($balance, $virtualBalance);
$nativeVirtualBalance = $converter->convert($default, $currency, $account->created_at, $virtualBalance);
@@ -149,14 +149,14 @@ class NetWorth implements NetWorthInterface
if (!$user instanceof User) {
return;
}
$this->user = $user;
$this->userGroup = null;
$this->user = $user;
$this->userGroup = null;
// make repository:
$this->accountRepository = app(AccountRepositoryInterface::class);
$this->accountRepository->setUser($this->user);
$this->currencyRepos = app(CurrencyRepositoryInterface::class);
$this->currencyRepos = app(CurrencyRepositoryInterface::class);
$this->currencyRepos->setUser($this->user);
}
@@ -179,16 +179,16 @@ class NetWorth implements NetWorthInterface
$return = [];
$balances = app('steam')->balancesByAccounts($accounts, $date);
foreach ($accounts as $account) {
$currency = $this->getRepository()->getAccountCurrency($account);
$balance = $balances[$account->id] ?? '0';
$currency = $this->getRepository()->getAccountCurrency($account);
$balance = $balances[$account->id] ?? '0';
// always subtract virtual balance.
$virtualBalance = $account->virtual_balance;
$virtualBalance = $account->virtual_balance;
if ('' !== $virtualBalance) {
$balance = bcsub($balance, $virtualBalance);
}
$return[$currency->id] ??= [
$return[$currency->id] ??= [
'id' => (string) $currency->id,
'name' => $currency->name,
'symbol' => $currency->symbol,

View File

@@ -70,7 +70,7 @@ class PopupReport implements PopupReportInterface
}
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector
->setAccounts(new Collection([$account]))
->setTypes([TransactionType::WITHDRAWAL])
@@ -102,7 +102,7 @@ class PopupReport implements PopupReportInterface
}
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts($attributes['accounts'])
->withAccountInformation()
->withBudgetInformation()
@@ -139,7 +139,7 @@ class PopupReport implements PopupReportInterface
}
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts($attributes['accounts'])
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER, TransactionType::DEPOSIT])
@@ -169,8 +169,8 @@ class PopupReport implements PopupReportInterface
public function byExpenses(Account $account, array $attributes): array
{
// filter by currency, if set.
$currencyId = $attributes['currencyId'] ?? null;
$currency = null;
$currencyId = $attributes['currencyId'] ?? null;
$currency = null;
if (null !== $currencyId) {
/** @var CurrencyRepositoryInterface $repos */
$repos = app(CurrencyRepositoryInterface::class);
@@ -178,14 +178,14 @@ class PopupReport implements PopupReportInterface
}
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
$repository = app(JournalRepositoryInterface::class);
$repository->setUser($account->user);
$accountRepository = app(AccountRepositoryInterface::class);
$accountRepository->setUser($account->user);
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
// set report accounts + the request accounts:
// $set = $attributes['accounts'] ?? new Collection;
@@ -216,7 +216,7 @@ class PopupReport implements PopupReportInterface
$repository->setUser($account->user);
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector
->setSourceAccounts(new Collection([$account]))
->setDestinationAccounts($attributes['accounts'])

View File

@@ -64,10 +64,10 @@ class ReportHelper implements ReportHelperInterface
/** @var Bill $bill */
foreach ($bills as $bill) {
$expectedDates = $repository->getPayDatesInRange($bill, $start, $end);
$billId = $bill->id;
$currency = $bill->transactionCurrency;
$current = [
$expectedDates = $repository->getPayDatesInRange($bill, $start, $end);
$billId = $bill->id;
$currency = $bill->transactionCurrency;
$current = [
'id' => $bill->id,
'name' => $bill->name,
'active' => $bill->active,
@@ -84,11 +84,11 @@ class ReportHelper implements ReportHelperInterface
/** @var Carbon $expectedStart */
foreach ($expectedDates as $expectedStart) {
$expectedEnd = app('navigation')->endOfX($expectedStart, $bill->repeat_freq, null);
$expectedEnd = app('navigation')->endOfX($expectedStart, $bill->repeat_freq, null);
// is paid in this period maybe?
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts($accounts)->setRange($expectedStart, $expectedEnd)->setBill($bill);
$current['paid_moments'][] = $collector->getExtractedJournals();
}
@@ -109,12 +109,12 @@ class ReportHelper implements ReportHelperInterface
$fiscalHelper = app(FiscalHelperInterface::class);
$start = clone $date;
$start->startOfMonth();
$end = today(config('app.timezone'));
$end = today(config('app.timezone'));
$end->endOfMonth();
$months = [];
$months = [];
while ($start <= $end) {
$year = $fiscalHelper->endOfFiscalYear($start)->year; // current year
$year = $fiscalHelper->endOfFiscalYear($start)->year; // current year
if (!array_key_exists($year, $months)) {
$months[$year] = [
'fiscal_start' => $fiscalHelper->startOfFiscalYear($start)->format('Y-m-d'),
@@ -125,7 +125,7 @@ class ReportHelper implements ReportHelperInterface
];
}
$currentEnd = clone $start;
$currentEnd = clone $start;
$currentEnd->endOfMonth();
$months[$year]['months'][] = [
'formatted' => $start->isoFormat((string)trans('config.month_js')),
@@ -135,7 +135,7 @@ class ReportHelper implements ReportHelperInterface
'year' => $year,
];
$start = clone $currentEnd; // to make the hop to the next month properly
$start = clone $currentEnd; // to make the hop to the next month properly
$start->addDay();
}