Skip to content

Firefly III: a personal finances manager

Invert stuff so chart works again.

James Cole98fd5b885899
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