Migrated all code to group collector.

This commit is contained in:
James Cole
2019-05-31 13:35:33 +02:00
parent eb6329e556
commit e15c35de64
31 changed files with 1540 additions and 1671 deletions

View File

@@ -71,8 +71,8 @@ class ExpenseReportController extends Controller
*
* @param Collection $accounts
* @param Collection $expense
* @param Carbon $start
* @param Carbon $end
* @param Carbon $start
* @param Carbon $end
*
* @return JsonResponse
*
@@ -89,7 +89,7 @@ class ExpenseReportController extends Controller
$cache->addProperty($start);
$cache->addProperty($end);
if ($cache->has()) {
return response()->json($cache->get()); // @codeCoverageIgnore
// return response()->json($cache->get()); // @codeCoverageIgnore
}
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
@@ -97,44 +97,43 @@ class ExpenseReportController extends Controller
$chartData = [];
$currentStart = clone $start;
$combined = $this->combineAccounts($expense);
// make "all" set:
$all = new Collection;
foreach ($combined as $name => $combi) {
$all = $all->merge($combi);
foreach ($combined as $name => $combination) {
$all = $all->merge($combination);
}
// prep chart data:
/**
* @var string $name
* @var Collection $combi
* @var string $name
* @var Collection $combination
*/
foreach ($combined as $name => $combi) {
foreach ($combined as $name => $combination) {
// first is always expense account:
/** @var Account $exp */
$exp = $combi->first();
$exp = $combination->first();
$chartData[$exp->id . '-in'] = [
'label' => $name . ' (' . strtolower((string)trans('firefly.income')) . ')',
'label' => sprintf('%s (%s)', $name, strtolower((string)trans('firefly.income'))),
'type' => 'bar',
'yAxisID' => 'y-axis-0',
'entries' => [],
];
$chartData[$exp->id . '-out'] = [
'label' => $name . ' (' . strtolower((string)trans('firefly.expenses')) . ')',
'label' => sprintf('%s (%s)', $name, strtolower((string)trans('firefly.expenses'))),
'type' => 'bar',
'yAxisID' => 'y-axis-0',
'entries' => [],
];
// total in, total out:
$chartData[$exp->id . '-total-in'] = [
'label' => $name . ' (' . strtolower((string)trans('firefly.sum_of_income')) . ')',
'label' => sprintf('%s (%s)', $name, strtolower((string)trans('firefly.sum_of_income'))),
'type' => 'line',
'fill' => false,
'yAxisID' => 'y-axis-1',
'entries' => [],
];
$chartData[$exp->id . '-total-out'] = [
'label' => $name . ' (' . strtolower((string)trans('firefly.sum_of_expenses')) . ')',
'label' => sprintf('%s (%s)', $name, strtolower((string)trans('firefly.sum_of_expenses'))),
'type' => 'line',
'fill' => false,
'yAxisID' => 'y-axis-1',
@@ -154,15 +153,15 @@ class ExpenseReportController extends Controller
$income = $this->groupByName($this->getIncomeForOpposing($accounts, $all, $currentStart, $currentEnd));
$label = $currentStart->formatLocalized($format);
foreach ($combined as $name => $combi) {
foreach ($combined as $name => $combination) {
// first is always expense account:
/** @var Account $exp */
$exp = $combi->first();
$exp = $combination->first();
$labelIn = $exp->id . '-in';
$labelOut = $exp->id . '-out';
$labelSumIn = $exp->id . '-total-in';
$labelSumOut = $exp->id . '-total-out';
$currentIncome = $income[$name] ?? '0';
$currentIncome = bcmul($income[$name] ?? '0', '-1');
$currentExpense = $expenses[$name] ?? '0';
// add to sum:
@@ -180,6 +179,7 @@ class ExpenseReportController extends Controller
/** @var Carbon $currentStart */
$currentStart = clone $currentEnd;
$currentStart->addDay();
$currentStart->startOfDay();
}
// remove all empty entries to prevent cluttering:
$newSet = [];