mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-19 13:03:05 -06:00
Various code cleanup
This commit is contained in:
parent
4804257fd1
commit
7405138489
@ -49,33 +49,8 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
|||||||
/** @var Account $account */
|
/** @var Account $account */
|
||||||
foreach ($this->accounts as $account) {
|
foreach ($this->accounts as $account) {
|
||||||
// balance the day before:
|
// balance the day before:
|
||||||
$id = $account->id;
|
$id = $account->id;
|
||||||
$dayBeforeBalance = Steam::balance($account, $dayBefore);
|
$auditData[$id] = $this->getAuditReport($account, $dayBefore);
|
||||||
$collector = new JournalCollector(auth()->user());
|
|
||||||
$collector->setAccounts(new Collection([$account]))->setRange($this->start, $this->end);
|
|
||||||
$journals = $collector->getJournals();
|
|
||||||
$journals = $journals->reverse();
|
|
||||||
$startBalance = $dayBeforeBalance;
|
|
||||||
|
|
||||||
|
|
||||||
/** @var Transaction $journal */
|
|
||||||
foreach ($journals as $transaction) {
|
|
||||||
$transaction->before = $startBalance;
|
|
||||||
$transactionAmount = $transaction->transaction_amount;
|
|
||||||
$newBalance = bcadd($startBalance, $transactionAmount);
|
|
||||||
$transaction->after = $newBalance;
|
|
||||||
$startBalance = $newBalance;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Reverse set again.
|
|
||||||
*/
|
|
||||||
$auditData[$id]['journals'] = $journals->reverse();
|
|
||||||
$auditData[$id]['exists'] = $journals->count() > 0;
|
|
||||||
$auditData[$id]['end'] = $this->end->formatLocalized(strval(trans('config.month_and_day')));
|
|
||||||
$auditData[$id]['endBalance'] = Steam::balance($account, $this->end);
|
|
||||||
$auditData[$id]['dayBefore'] = $dayBefore->formatLocalized(strval(trans('config.month_and_day')));
|
|
||||||
$auditData[$id]['dayBeforeBalance'] = $dayBeforeBalance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$defaultShow = ['icon', 'description', 'balance_before', 'amount', 'balance_after', 'date', 'to'];
|
$defaultShow = ['icon', 'description', 'balance_before', 'amount', 'balance_after', 'date', 'to'];
|
||||||
@ -153,4 +128,44 @@ class MonthReportGenerator implements ReportGeneratorInterface
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Account $account
|
||||||
|
* @param Carbon $date
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getAuditReport(Account $account, Carbon $date): array
|
||||||
|
{
|
||||||
|
$dayBeforeBalance = Steam::balance($account, $date);
|
||||||
|
$collector = new JournalCollector(auth()->user());
|
||||||
|
$collector->setAccounts(new Collection([$account]))->setRange($this->start, $this->end);
|
||||||
|
$journals = $collector->getJournals();
|
||||||
|
$journals = $journals->reverse();
|
||||||
|
$startBalance = $dayBeforeBalance;
|
||||||
|
|
||||||
|
|
||||||
|
/** @var Transaction $journal */
|
||||||
|
foreach ($journals as $transaction) {
|
||||||
|
$transaction->before = $startBalance;
|
||||||
|
$transactionAmount = $transaction->transaction_amount;
|
||||||
|
$newBalance = bcadd($startBalance, $transactionAmount);
|
||||||
|
$transaction->after = $newBalance;
|
||||||
|
$startBalance = $newBalance;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reverse set again.
|
||||||
|
*/
|
||||||
|
$return = [
|
||||||
|
'journals' => $journals->reverse(),
|
||||||
|
'exists' => $journals->count() > 0,
|
||||||
|
'end' => $this->end->formatLocalized(strval(trans('config.month_and_day'))),
|
||||||
|
'endBalance' => Steam::balance($account, $this->end),
|
||||||
|
'dayBefore' => $date->formatLocalized(strval(trans('config.month_and_day'))),
|
||||||
|
'dayBeforeBalance' => $dayBeforeBalance,
|
||||||
|
];
|
||||||
|
|
||||||
|
return $return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -229,6 +229,7 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's exactly five.
|
||||||
* @param array $spent
|
* @param array $spent
|
||||||
* @param array $earned
|
* @param array $earned
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user