Expanded report for categories.

This commit is contained in:
James Cole 2015-12-11 18:03:13 +01:00
parent d4690ce580
commit 18eba02026
5 changed files with 77 additions and 13 deletions

View File

@ -325,6 +325,33 @@ class ReportHelper implements ReportHelperInterface
return $object;
}
/**
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return CategoryCollection
*/
public function getCategoryReportForList(Carbon $start, Carbon $end, Collection $accounts)
{
$object = new CategoryCollection;
/**
* GET CATEGORIES:
*/
/** @var \FireflyIII\Repositories\Category\CategoryRepositoryInterface $repository */
$repository = app('FireflyIII\Repositories\Category\CategoryRepositoryInterface');
$set = $repository->getCategories();
foreach ($set as $category) {
$spent = $repository->balanceInPeriodForList($category, $start, $end, $accounts);
$category->spent = $spent;
$object->addCategory($category);
$object->addTotal($spent);
}
return $object;
}
/**
* Get a full report on the users expenses during the period.
*

View File

@ -91,6 +91,15 @@ interface ReportHelperInterface
*/
public function getCategoryReport(Carbon $start, Carbon $end, $shared);
/**
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return CategoryCollection
*/
public function getCategoryReportForList(Carbon $start, Carbon $end, Collection $accounts);
/**
* Get a full report on the users expenses during the period.
*

View File

@ -241,11 +241,11 @@ class ReportController extends Controller
$expenseTopLength = 8;
// get report stuff!
$accounts = $this->helper->getAccountReportForList($start, $end, $list);
$incomes = $this->helper->getIncomeReportForList($start, $end, $list);
$expenses = $this->helper->getExpenseReportForList($start, $end, $list);
$budgets = $this->helper->getBudgetReportForList($start, $end, $list);
// $categories = $this->helper->getCategoryReportForList($start, $end, $list);
$accounts = $this->helper->getAccountReportForList($start, $end, $list);
$incomes = $this->helper->getIncomeReportForList($start, $end, $list);
$expenses = $this->helper->getExpenseReportForList($start, $end, $list);
$budgets = $this->helper->getBudgetReportForList($start, $end, $list);
$categories = $this->helper->getCategoryReportForList($start, $end, $list);
// $balance = $this->helper->getBalanceReportForList($start, $end, $list);
// $bills = $this->helper->getBillReportForList($start, $end);

View File

@ -191,6 +191,19 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
return $this->commonBalanceInPeriod($category, $start, $end, $shared);
}
/**
* @param Category $category
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return string
*/
public function balanceInPeriodForList(Category $category, Carbon $start, Carbon $end, Collection $accounts)
{
return $this->commonBalanceInPeriodForList($category, $start, $end, $accounts);
}
/**
* Corrected for tags
*
@ -286,9 +299,10 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
return $cache->get(); // @codeCoverageIgnore
}
$sum = $category->transactionjournals()->transactionTypes([TransactionType::WITHDRAWAL])->before($end)->after($start)->get(['transaction_journals.*'])->sum(
'amount'
);
$sum = $category->transactionjournals()->transactionTypes([TransactionType::WITHDRAWAL])->before($end)->after($start)->get(['transaction_journals.*'])
->sum(
'amount'
);
$cache->store($sum);
@ -316,9 +330,10 @@ class CategoryRepository extends ComponentRepository implements CategoryReposito
return $cache->get(); // @codeCoverageIgnore
}
$sum = $category->transactionjournals()->transactionTypes([TransactionType::DEPOSIT])->before($end)->after($start)->get(['transaction_journals.*'])->sum(
'amount'
);
$sum = $category->transactionjournals()->transactionTypes([TransactionType::DEPOSIT])->before($end)->after($start)->get(['transaction_journals.*'])
->sum(
'amount'
);
$cache->store($sum);

View File

@ -77,8 +77,8 @@ interface CategoryRepositoryInterface
* limited by a start or end date.
*
* @param Category $category
* @param Carbon $start
* @param Carbon $end
* @param Carbon $start
* @param Carbon $end
*
* @return string
*/
@ -112,6 +112,19 @@ interface CategoryRepositoryInterface
*/
public function balanceInPeriod(Category $category, Carbon $start, Carbon $end, $shared = false);
/**
* Corrected for tags.
*
* @param Category $category
* @param \Carbon\Carbon $start
* @param \Carbon\Carbon $end
* @param Collection $accounts
*
* @return string
*/
public function balanceInPeriodForList(Category $category, Carbon $start, Carbon $end, Collection $accounts);
/**
* @param Category $category
* @param \Carbon\Carbon $start