This commit is contained in:
James Cole
2017-10-15 14:05:31 +02:00
parent 7ff19a8419
commit 5c0bb34d77
2 changed files with 15 additions and 14 deletions

View File

@@ -74,17 +74,17 @@ class BudgetController extends Controller
*/ */
public function budget(Budget $budget) public function budget(Budget $budget)
{ {
$first = $this->repository->firstUseDate($budget); $first = $this->repository->firstUseDate($budget);
$range = Preferences::get('viewRange', '1M')->data; $range = Preferences::get('viewRange', '1M')->data;
$last = session('end', new Carbon); $currentStart = Navigation::startOfPeriod($first, $range);
$last = session('end', new Carbon);
$cache = new CacheProperties(); $cache = new CacheProperties();
$cache->addProperty($first); $cache->addProperty($first);
$cache->addProperty($last); $cache->addProperty($last);
$cache->addProperty('chart.budget.budget'); $cache->addProperty('chart.budget.budget');
if ($cache->has()) { if ($cache->has()) {
return Response::json($cache->get()); // @codeCoverageIgnore return Response::json($cache->get()); // @codeCoverageIgnore
} }
$final = clone $last; $final = clone $last;
@@ -92,17 +92,16 @@ class BudgetController extends Controller
$budgetCollection = new Collection([$budget]); $budgetCollection = new Collection([$budget]);
$last = Navigation::endOfX($last, $range, $final); // not to overshoot. $last = Navigation::endOfX($last, $range, $final); // not to overshoot.
$entries = []; $entries = [];
while ($first < $last) { while ($currentStart < $last) {
// periodspecific dates: // periodspecific dates:
$currentStart = Navigation::startOfPeriod($first, $range); $currentEnd = Navigation::endOfPeriod($currentStart, $range);
$currentEnd = Navigation::endOfPeriod($first, $range);
// sub another day because reasons. // sub another day because reasons.
$currentEnd->subDay(); $currentEnd->subDay();
$spent = $this->repository->spentInPeriod($budgetCollection, new Collection, $currentStart, $currentEnd); $spent = $this->repository->spentInPeriod($budgetCollection, new Collection, $currentStart, $currentEnd);
$format = Navigation::periodShow($first, $range); $format = Navigation::periodShow($currentStart, $range);
$entries[$format] = bcmul($spent, '-1'); $entries[$format] = bcmul($spent, '-1');
$first = Navigation::addPeriod($first, $range, 0); $currentStart = clone $currentEnd;
$currentStart->addDays(2);
} }
$data = $this->generator->singleSet(strval(trans('firefly.spent')), $entries); $data = $this->generator->singleSet(strval(trans('firefly.spent')), $entries);
@@ -244,6 +243,7 @@ class BudgetController extends Controller
$data = $this->generator->pieChart($chartData); $data = $this->generator->pieChart($chartData);
$cache->store($data); $cache->store($data);
return Response::json($data); return Response::json($data);
} }

View File

@@ -215,14 +215,15 @@ class Navigation
} }
/** /**
* @param \Carbon\Carbon $date * @param \Carbon\Carbon $theDate
* @param $repeatFrequency * @param $repeatFrequency
* *
* @return string * @return string
* @throws FireflyException * @throws FireflyException
*/ */
public function periodShow(Carbon $date, string $repeatFrequency): string public function periodShow(Carbon $theDate, string $repeatFrequency): string
{ {
$date = clone $theDate;
$formatMap = [ $formatMap = [
'1D' => trans('config.specific_day'), '1D' => trans('config.specific_day'),
'daily' => trans('config.specific_day'), 'daily' => trans('config.specific_day'),