mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-19 19:01:58 +00:00
Clean up and add some todo's
This commit is contained in:
@@ -35,6 +35,7 @@ use Throwable;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Class MonthReportGenerator.
|
* Class MonthReportGenerator.
|
||||||
|
* TODO include info about tags.
|
||||||
*
|
*
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
|
@@ -35,6 +35,7 @@ use Throwable;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Class MonthReportGenerator.
|
* Class MonthReportGenerator.
|
||||||
|
* TODO include info about tags.
|
||||||
*
|
*
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
@@ -72,23 +73,10 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
|||||||
$accountIds = implode(',', $this->accounts->pluck('id')->toArray());
|
$accountIds = implode(',', $this->accounts->pluck('id')->toArray());
|
||||||
$categoryIds = implode(',', $this->categories->pluck('id')->toArray());
|
$categoryIds = implode(',', $this->categories->pluck('id')->toArray());
|
||||||
$reportType = 'category';
|
$reportType = 'category';
|
||||||
$expenses = $this->getExpenses();
|
|
||||||
$income = $this->getIncome();
|
|
||||||
$accountSummary = $this->getObjectSummary($this->summarizeByAssetAccount($expenses), $this->summarizeByAssetAccount($income));
|
|
||||||
$categorySummary = $this->getObjectSummary($this->summarizeByCategory($expenses), $this->summarizeByCategory($income));
|
|
||||||
$averageExpenses = $this->getAverages($expenses, SORT_ASC);
|
|
||||||
$averageIncome = $this->getAverages($income, SORT_DESC);
|
|
||||||
$topExpenses = $this->getTopExpenses();
|
|
||||||
$topIncome = $this->getTopIncome();
|
|
||||||
|
|
||||||
// render!
|
// render!
|
||||||
try {
|
try {
|
||||||
return view(
|
return view('reports.category.month', compact('accountIds', 'categoryIds', 'reportType',))
|
||||||
'reports.category.month', compact(
|
|
||||||
'accountIds', 'categoryIds', 'topIncome', 'reportType', 'accountSummary', 'categorySummary', 'averageExpenses',
|
|
||||||
'averageIncome', 'topExpenses'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
->with('start', $this->start)->with('end', $this->end)
|
->with('start', $this->start)->with('end', $this->end)
|
||||||
->with('categories', $this->categories)
|
->with('categories', $this->categories)
|
||||||
->with('accounts', $this->accounts)
|
->with('accounts', $this->accounts)
|
||||||
@@ -101,75 +89,6 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the expenses for this report.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function getExpenses(): array
|
|
||||||
{
|
|
||||||
if (count($this->expenses) > 0) {
|
|
||||||
Log::debug('Return previous set of expenses.');
|
|
||||||
|
|
||||||
return $this->expenses;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var GroupCollectorInterface $collector */
|
|
||||||
$collector = app(GroupCollectorInterface::class);
|
|
||||||
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
|
|
||||||
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
|
||||||
->setCategories($this->categories)->withAccountInformation();
|
|
||||||
|
|
||||||
$transactions = $collector->getExtractedJournals();
|
|
||||||
$this->expenses = $transactions;
|
|
||||||
|
|
||||||
return $transactions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the income for this report.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function getIncome(): array
|
|
||||||
{
|
|
||||||
if (count($this->income) > 0) {
|
|
||||||
return $this->income;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var GroupCollectorInterface $collector */
|
|
||||||
$collector = app(GroupCollectorInterface::class);
|
|
||||||
|
|
||||||
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
|
|
||||||
->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
|
||||||
->setCategories($this->categories)->withAccountInformation();
|
|
||||||
|
|
||||||
$transactions = $collector->getExtractedJournals();
|
|
||||||
$this->income = $transactions;
|
|
||||||
|
|
||||||
return $transactions;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Summarize the category.
|
|
||||||
*
|
|
||||||
* @param array $array
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
private function summarizeByCategory(array $array): array
|
|
||||||
{
|
|
||||||
$result = [];
|
|
||||||
/** @var array $journal */
|
|
||||||
foreach ($array as $journal) {
|
|
||||||
$categoryId = (int)$journal['category_id'];
|
|
||||||
$result[$categoryId] = $result[$categoryId] ?? '0';
|
|
||||||
$result[$categoryId] = bcadd($journal['amount'], $result[$categoryId]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the involved accounts.
|
* Set the involved accounts.
|
||||||
*
|
*
|
||||||
@@ -261,4 +180,53 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
|
|||||||
{
|
{
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the expenses for this report.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getExpenses(): array
|
||||||
|
{
|
||||||
|
if (count($this->expenses) > 0) {
|
||||||
|
Log::debug('Return previous set of expenses.');
|
||||||
|
|
||||||
|
return $this->expenses;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var GroupCollectorInterface $collector */
|
||||||
|
$collector = app(GroupCollectorInterface::class);
|
||||||
|
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
|
||||||
|
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
|
||||||
|
->setCategories($this->categories)->withAccountInformation();
|
||||||
|
|
||||||
|
$transactions = $collector->getExtractedJournals();
|
||||||
|
$this->expenses = $transactions;
|
||||||
|
|
||||||
|
return $transactions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the income for this report.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getIncome(): array
|
||||||
|
{
|
||||||
|
if (count($this->income) > 0) {
|
||||||
|
return $this->income;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var GroupCollectorInterface $collector */
|
||||||
|
$collector = app(GroupCollectorInterface::class);
|
||||||
|
|
||||||
|
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
|
||||||
|
->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
|
||||||
|
->setCategories($this->categories)->withAccountInformation();
|
||||||
|
|
||||||
|
$transactions = $collector->getExtractedJournals();
|
||||||
|
$this->income = $transactions;
|
||||||
|
|
||||||
|
return $transactions;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user