From 98fd5b885899f9cbc9202fedccc8f4da8e577b77 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 17 Feb 2016 22:35:57 +0100 Subject: [PATCH] Invert stuff so chart works again. --- .../Controllers/Chart/CategoryController.php | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php index a11b148809..84cf3c1fed 100644 --- a/app/Http/Controllers/Chart/CategoryController.php +++ b/app/Http/Controllers/Chart/CategoryController.php @@ -327,9 +327,9 @@ class CategoryController extends Controller return $category->name; } ); - - $entries = $this->filterCollection($start, $end, $set, $categories); - $data = $this->generator->spentInPeriod($categories, $entries); + $entries = $this->filterCollection($start, $end, $set, $categories); + $entries = $this->invertSelection($entries); + $data = $this->generator->spentInPeriod($categories, $entries); $cache->store($data); return $data; @@ -362,7 +362,7 @@ class CategoryController extends Controller } )->first(); if (!is_null($entry)) { - $row[] = round($entry->earned, 2); + $row[] = $entry->earned ? round($entry->earned, 2) : round($entry->spent, 2); } else { $row[] = 0; } @@ -374,6 +374,27 @@ class CategoryController extends Controller return $entries; } + /** + * @param Collection $entries + * + * @return Collection + */ + private function invertSelection(Collection $entries): Collection + { + $result = new Collection; + foreach ($entries as $entry) { + $new = [$entry[0]]; + $count = count($entry); + for ($i = 1; $i < $count; $i++) { + $new[$i] = ($entry[$i] * -1); + } + $result->push($new); + } + + return $result; + + } + /** * @param SCRI $repository * @param Category $category