New chart.

This commit is contained in:
James Cole
2015-08-01 07:04:41 +02:00
parent c04f08dfd8
commit 16b95ea78a
6 changed files with 120 additions and 27 deletions

View File

@@ -79,6 +79,36 @@ class AccountController extends Controller
return Response::json($data);
}
/**
* Shows the balances for all the user's expense accounts.
*
* @param AccountRepositoryInterface $repository
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function expenseAccounts(AccountRepositoryInterface $repository)
{
$start = clone Session::get('start', Carbon::now()->startOfMonth());
$end = clone Session::get('end', Carbon::now()->endOfMonth());
$accounts = $repository->getAccounts(['Expense account', 'Beneficiary account']);
// chart properties for cache:
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('expenseAccounts');
$cache->addProperty('accounts');
if ($cache->has()) {
return Response::json($cache->get()); // @codeCoverageIgnore
}
$data = $this->generator->expenseAccounts($accounts, $start, $end);
$cache->store($data);
return Response::json($data);
}
/**
* Shows the balances for all the user's frontpage accounts.
*

View File

@@ -186,15 +186,16 @@ class CategoryController extends Controller
$shared = $shared == 'shared' ? true : false;
$allCategories = $repository->getCategories();
$entries = new Collection;
$categories = new Collection;
$categories = $allCategories->filter(
function (Category $category) use ($repository, $start, $end, $shared) {
$spent = $repository->spentInPeriodCorrected($category, $start, $end, $shared);
if ($spent < 0) {
return $category;
}
// filter by checking the entire year first:
foreach ($allCategories as $category) {
$spent = $repository->spentInPeriodCorrected($category, $start, $end, $shared);
if ($spent < 0) {
$categories->push($category);
return null;
}
}
);
while ($start < $end) {
$month = clone $start; // month is the current end of the period
@@ -204,18 +205,14 @@ class CategoryController extends Controller
foreach ($categories as $category) { // each budget, fill the row
$spent = $repository->spentInPeriodCorrected($category, $start, $month, $shared);
if ($spent < 0) {
$spent = $spent * -1;
$row[] = $spent;
$row[] = $spent * -1;
} else {
$row[] = 0;
}
}
$entries->push($row);
$start->addMonth();
}
$data = $this->generator->spentInYear($categories, $entries);
$cache->store($data);
@@ -248,16 +245,16 @@ class CategoryController extends Controller
$shared = $shared == 'shared' ? true : false;
$allCategories = $repository->getCategories();
$allEntries = new Collection;
$categories = new Collection;
$categories = $allCategories->filter(
function (Category $category) use ($repository, $start, $end, $shared) {
$spent = $repository->spentInPeriodCorrected($category, $start, $end, $shared);
if ($spent > 0) {
return $category;
}
// filter by checking the entire year first:
foreach ($allCategories as $category) {
$spent = $repository->spentInPeriodCorrected($category, $start, $end, $shared);
if ($spent > 0) {
$categories->push($category);
return null;
}
}
);
while ($start < $end) {
$month = clone $start; // month is the current end of the period
@@ -271,14 +268,10 @@ class CategoryController extends Controller
} else {
$row[] = 0;
}
}
$allEntries->push($row);
$start->addMonth();
}
$data = $this->generator->earnedInYear($categories, $allEntries);
$cache->store($data);