Fix sorting.

This commit is contained in:
James Cole 2016-04-27 06:19:13 +02:00
parent b5a5a216cd
commit 3833a41acb

View File

@ -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;
}
}