This commit is contained in:
James Cole 2018-11-11 20:09:35 +01:00
parent 1fbf91c768
commit 74f8dceb38
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E

View File

@ -35,6 +35,7 @@ use FireflyIII\Support\CacheProperties;
use FireflyIII\Support\Http\Controllers\DateCalculation;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Collection;
use Log;
/**
* Class CategoryController.
@ -83,6 +84,9 @@ class CategoryController extends Controller
$start = app('navigation')->startOfPeriod($start, $range);
$end = new Carbon;
$accounts = $accountRepository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET]);
Log::debug(sprintf('Full range is %s to %s', $start->format('Y-m-d'), $end->format('Y-m-d')));
$chartData = [
[
'label' => (string)trans('firefly.spent'),
@ -101,9 +105,13 @@ class CategoryController extends Controller
];
$step = $this->calculateStep($start, $end);
$current = clone $start;
Log::debug(sprintf('abc Step is %s', $step));
switch ($step) {
case '1D':
while ($current <= $end) {
Log::debug(sprintf('Current day is %s', $current->format('Y-m-d')));
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $current, $current);
$earned = $repository->earnedInPeriod(new Collection([$category]), $accounts, $current, $current);
$sum = bcadd($spent, $earned);
@ -118,7 +126,9 @@ class CategoryController extends Controller
case '1M':
case '1Y':
while ($current <= $end) {
$currentEnd = app('navigation')->endOfPeriod($current, $range);
$currentEnd = app('navigation')->endOfPeriod($current, $step);
Log::debug(sprintf('abc Range is %s to %s', $current->format('Y-m-d'), $currentEnd->format('Y-m-d')));
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $current, $currentEnd);
$earned = $repository->earnedInPeriod(new Collection([$category]), $accounts, $current, $currentEnd);
$sum = bcadd($spent, $earned);
@ -431,17 +441,33 @@ class CategoryController extends Controller
],
];
$step = $this->calculateStep($start, $end);
while ($start <= $end) {
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $start);
$earned = $repository->earnedInPeriod(new Collection([$category]), $accounts, $start, $start);
$sum = bcadd($spent, $earned);
$label = trim(app('navigation')->periodShow($start, '1D'));
$label = trim(app('navigation')->periodShow($start, $step));
$chartData[0]['entries'][$label] = round(bcmul($spent, '-1'), 12);
$chartData[1]['entries'][$label] = round($earned, 12);
$chartData[2]['entries'][$label] = round($sum, 12);
switch ($step) {
default:
case '1D':
$start->addDay();
break;
case '1W':
$start->addDays(7);
break;
case '1M':
$start->addMonth();
break;
case '1Y':
$start->addYear();
break;
}
}
$data = $this->generator->multiSet($chartData);