Signed-off-by: James Cole <thegrumpydictator@gmail.com>
This commit is contained in:
James Cole 2016-09-15 19:14:22 +02:00
parent 46e5aae8bb
commit 7d5bb72b0c
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E

View File

@ -108,13 +108,12 @@ class CategoryController extends Controller
}
/**
* Show this month's category overview.
* @param CRI $repository
* @param AccountCrudInterface $crud
*
* @param CRI $repository
*
* @return \Symfony\Component\HttpFoundation\Response
* @return \Illuminate\Http\JsonResponse
*/
public function frontpage(CRI $repository)
public function frontpage(CRI $repository, AccountCrudInterface $crud)
{
$start = session('start', Carbon::now()->startOfMonth());
$end = session('end', Carbon::now()->endOfMonth());
@ -128,10 +127,11 @@ class CategoryController extends Controller
return Response::json($cache->get());
}
$categories = $repository->getCategories();
$accounts = $crud->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT]);
$set = new Collection;
/** @var Category $category */
foreach ($categories as $category) {
$spent = $repository->spentInPeriod(new Collection([$category]), new Collection, $start, $end);
$spent = $repository->spentInPeriod(new Collection([$category]), $accounts, $start, $end);
if (bccomp($spent, '0') === -1) {
$category->spent = $spent;
$set->push($category);