make sure reports work as expected.

This commit is contained in:
James Cole
2019-05-30 06:23:25 +02:00
parent bdf48227bb
commit 10a6ff9bf8
13 changed files with 446 additions and 391 deletions

View File

@@ -74,7 +74,7 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
$reportType = 'category';
$expenses = $this->getExpenses();
$income = $this->getIncome();
$accountSummary = $this->getObjectSummary($this->summarizeByAccount($expenses), $this->summarizeByAccount($income));
$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);

View File

@@ -24,7 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Generator\Report;
use Illuminate\Support\Collection;
use FireflyIII\Models\TransactionType;
/**
* Class Support.
@@ -146,6 +146,7 @@ class Support
* @var string $entry
*/
foreach ($earned as $objectId => $entry) {
$entry = bcmul($entry, '-1');
if (!isset($return[$objectId])) {
$return[$objectId] = ['spent' => '0', 'earned' => '0'];
}
@@ -176,4 +177,36 @@ class Support
return $result;
}
/**
* Summarize the data by the asset account or liability, depending on the type.
*
* In case of transfers, it will choose the source account.
*
* @param array $array
*
* @return array
*/
protected function summarizeByAssetAccount(array $array): array
{
$result = [];
/** @var array $journal */
foreach ($array as $journal) {
$accountId = 0;
switch ($journal['transaction_type_type']) {
case TransactionType::WITHDRAWAL:
case TransactionType::TRANSFER:
$accountId = $journal['source_account_id'] ?? 0;
break;
case TransactionType::DEPOSIT:
$accountId = $journal['destination_account_id'] ?? 0;
break;
}
$result[$accountId] = $result[$accountId] ?? '0';
$result[$accountId] = bcadd($journal['amount'], $result[$accountId]);
}
return $result;
}
}