Fix some report issues.

This commit is contained in:
James Cole 2019-08-17 07:47:39 +02:00
parent 3e242aaca6
commit 6f78735bc5
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
5 changed files with 21 additions and 24 deletions

View File

@ -46,8 +46,6 @@ use Log;
*/
class GroupCollector implements GroupCollectorInterface
{
/** @var array The accounts to filter on. Asset accounts or liabilities. */
private $accountIds;
/** @var array The standard fields to select. */
private $fields;
/** @var bool Will be set to true if query result contains account information. (see function withAccountInformation). */
@ -86,8 +84,6 @@ class GroupCollector implements GroupCollectorInterface
$this->hasJoinedTagTables = false;
$this->total = 0;
$this->limit = 50;
$this->page = 1;
$this->fields = [
# group
'transaction_groups.id as transaction_group_id',
@ -157,10 +153,14 @@ class GroupCollector implements GroupCollectorInterface
$collection = $this->parseArray($result);
$this->total = $collection->count();
// now filter the array according to the page and the
// now filter the array according to the page and the limit (if necessary)
if (null !== $this->limit && null !== $this->page) {
$offset = ($this->page-1) * $this->limit;
return $collection->slice($offset, $this->limit);
}
return $collection;
}
@ -182,7 +182,6 @@ class GroupCollector implements GroupCollectorInterface
}
);
app('log')->debug(sprintf('GroupCollector: setAccounts: %s', implode(', ', $accountIds)));
$this->accountIds = $accountIds;
}
return $this;
@ -202,7 +201,6 @@ class GroupCollector implements GroupCollectorInterface
$this->query->whereIn('source.account_id', $accountIds);
app('log')->debug(sprintf('GroupCollector: setSourceAccounts: %s', implode(', ', $accountIds)));
$this->accountIds = $accountIds;
}
return $this;
@ -222,7 +220,6 @@ class GroupCollector implements GroupCollectorInterface
$this->query->whereIn('destination.account_id', $accountIds);
app('log')->debug(sprintf('GroupCollector: setSourceAccounts: %s', implode(', ', $accountIds)));
$this->accountIds = $accountIds;
}
return $this;
@ -847,6 +844,7 @@ class GroupCollector implements GroupCollectorInterface
/** @var TransactionGroup $augmentedGroup */
foreach ($collection as $augmentedGroup) {
$groupId = $augmentedGroup->transaction_group_id;
if (!isset($groups[$groupId])) {
// make new array
$parsedGroup = $this->parseAugmentedGroup($augmentedGroup);
@ -877,7 +875,9 @@ class GroupCollector implements GroupCollectorInterface
$groups[$groupId]['transactions'][$journalId] = $this->parseAugmentedGroup($augmentedGroup);
}
}
$groups = $this->parseSums($groups);
return new Collection($groups);
@ -1065,7 +1065,6 @@ class GroupCollector implements GroupCollectorInterface
$this->query->whereNotIn('source.account_id', $accountIds);
app('log')->debug(sprintf('GroupCollector: excludeSourceAccounts: %s', implode(', ', $accountIds)));
$this->accountIds = $accountIds;
}
return $this;
@ -1085,7 +1084,6 @@ class GroupCollector implements GroupCollectorInterface
$this->query->whereNotIn('destination.account_id', $accountIds);
app('log')->debug(sprintf('GroupCollector: excludeDestinationAccounts: %s', implode(', ', $accountIds)));
$this->accountIds = $accountIds;
}
return $this;

View File

@ -224,7 +224,7 @@ class ReportController extends Controller
'count_spent' => 0,
];
foreach ($source['earned'] as $amount) {
$amount = bcmul($amount,'-1');
$amount = bcmul($amount, '-1');
$numbers['sum_earned'] = bcadd($amount, $numbers['sum_earned']);
++$numbers['count_earned'];
}

View File

@ -143,6 +143,7 @@ class AccountTasker implements AccountTaskerInterface
$collector->excludeDestinationAccounts($accounts);
$collector->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])->withAccountInformation();
$journals = $collector->getExtractedJournals();
$report = $this->groupExpenseByDestination($journals);
// TODO sorting
@ -220,9 +221,8 @@ class AccountTasker implements AccountTaskerInterface
$sourceId = (int)$journal['destination_account_id'];
$currencyId = (int)$journal['currency_id'];
$key = sprintf('%s-%s', $sourceId, $currencyId);
if (!isset($report['accounts'][$key])) {
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepos->findNull($currencyId);
$report['accounts'][$key] = [
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepos->findNull($currencyId);
$report['accounts'][$key] = $report['accounts'][$key] ?? [
'id' => $sourceId,
'name' => $journal['destination_account_name'],
'sum' => '0',
@ -234,8 +234,10 @@ class AccountTasker implements AccountTaskerInterface
'currency_code' => $currencies[$currencyId]->code,
'currency_decimal_places' => $currencies[$currencyId]->decimal_places,
];
}
$report['accounts'][$key]['sum'] = bcadd($report['accounts'][$key]['sum'], $journal['amount']);
Log::debug(sprintf('Sum for %s is now %s', $journal['destination_account_name'], $report['accounts'][$key]['sum']));
++$report['accounts'][$key]['count'];
}

View File

@ -113,8 +113,6 @@ trait ChartGeneration
* @param Carbon $end
*
* @return array
*
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function getChartData(Collection $accounts, Carbon $start, Carbon $end): array // chart helper function
{
@ -138,25 +136,24 @@ trait ChartGeneration
$currentEnd = app('navigation')->endOfPeriod($currentStart, '1M');
$earned = (string)array_sum(
array_map(
function ($item) {
static function ($item) {
return $item['sum'];
},
$tasker->getIncomeReport($currentStart, $currentEnd, $accounts)
$tasker->getIncomeReport($currentStart, $currentEnd, $accounts)['accounts']
)
);
$spent = (string)array_sum(
array_map(
function ($item) {
static function ($item) {
return $item['sum'];
},
$tasker->getExpenseReport($currentStart, $currentEnd, $accounts)
$tasker->getExpenseReport($currentStart, $currentEnd, $accounts)['accounts']
)
);
$label = $currentStart->format('Y-m') . '-01';
$spentArray[$label] = bcmul($spent, '-1');
$earnedArray[$label] = $earned;
$earnedArray[$label] = bcmul($earned, '-1');
$currentStart = app('navigation')->addPeriod($currentStart, '1M', 0);
}
$result = [

View File

@ -220,7 +220,7 @@
var budgetPeriodReportUri = '{{ route('report-data.budget.period', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}';
var categoryExpenseUri = '{{ route('report-data.category.expenses', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}';
var categoryIncomeUri = '{{ route('report-data.category.income', [accountIds, start.format('Ymd'), end.format('Ymd')]) }}';
var billReportUri = '';
</script>
<script type="text/javascript" src="v1/js/ff/reports/all.js?v={{ FF_VERSION }}"></script>