Skip to content

Firefly III: a personal finances manager

Fix sorting.

James Cole3833a41acb0a
diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php
index 8fbadc3bd4..6d4a660db1 100644
--- a/app/Helpers/Report/ReportHelper.php
+++ b/app/Helpers/Report/ReportHelper.php
@@ -102,6 +102,38 @@ class ReportHelper implements ReportHelperInterface
return $collection;
}
+ /**
+ * @param Carbon $start
+ * @param Carbon $end
+ * @param Collection $accounts
+ *
+ * @return Collection
+ */
+ public function getCategoriesWithExpenses(Carbon $start, Carbon $end, Collection $accounts): Collection
+ {
+ /** @var \FireflyIII\Repositories\Category\CategoryRepositoryInterface $repository */
+ $repository = app('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
+ $collection = $repository->earnedForAccountsPerMonth($accounts, $start, $end);
+ $second = $repository->spentForAccountsPerMonth($accounts, $start, $end);
+ $collection = $collection->merge($second);
+ $array = [];
+ /** @var Category $category */
+ foreach ($collection as $category) {
+ $id = $category->id;
+ $array[$id] = $category;
+
+ }
+ $set = new Collection($array);
+
+ $set = $set->sort(
+ function (Category $category) {
+ return $category->name;
+ }
+ );
+
+ return $set;
+ }
+
/**
* @param Carbon $start
* @param Carbon $end
@@ -312,30 +344,4 @@ class ReportHelper implements ReportHelperInterface
return $sum;
}
-
- /**
- * @param Carbon $start
- * @param Carbon $end
- * @param Collection $accounts
- *
- * @return Collection
- */
- public function getCategoriesWithExpenses(Carbon $start, Carbon $end, Collection $accounts): Collection
- {
- /** @var \FireflyIII\Repositories\Category\CategoryRepositoryInterface $repository */
- $repository = app('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
- $collection = $repository->earnedForAccountsPerMonth($accounts, $start, $end);
- $second = $repository->spentForAccountsPerMonth($accounts, $start, $end);
- $collection = $collection->merge($second);
- $array = [];
- /** @var Category $category */
- foreach ($collection as $category) {
- $id = $category->id;
- $array[$id] = $category;
-
- }
- $set = new Collection($array);
-
- return $set;
- }
}