Fixed tests

This commit is contained in:
James Cole
2015-05-16 09:25:14 +02:00
parent 0a372b0daf
commit e155d3311c
7 changed files with 41 additions and 10 deletions

View File

@@ -359,7 +359,7 @@ class GoogleChartController extends Controller
while ($start <= $end) {
$currentEnd = Navigation::endOfPeriod($start, $range->data);
$spent = $repository->spentInPeriodSum($category, $start, $currentEnd);
$spent = $repository->spentInPeriod($category, $start, $currentEnd);
$chart->addRow(clone $start, $spent);
$start = Navigation::addPeriod($start, $range->data, 0);

View File

@@ -5,6 +5,7 @@ namespace FireflyIII\Http\Controllers;
use Carbon\Carbon;
use FireflyIII\Helpers\Report\ReportQueryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use Grumpydictator\Gchart\GChart;
use Response;
@@ -52,11 +53,35 @@ class ReportChartController extends Controller
return Response::json($chart->getData());
}
public function yearCategories(GChart $chart, $year, $shared = false)
public function yearCategories(GChart $chart, CategoryRepositoryInterface $repository, $year, $shared = false)
{
$start = new Carbon($year . '-01-01');
$end = new Carbon($year . '-12-31');
$shared = $shared == 'shared' ? true : false;
$categories = $repository->getCategories();
// add columns:
$chart->addColumn(trans('firefly.month'), 'date');
foreach ($categories as $category) {
$chart->addColumn($category->name, 'number');
}
while ($start < $end) {
// month is the current end of the period:
$month = clone $start;
$month->endOfMonth();
// make a row:
$row = [clone $start];
// each budget, fill the row:
foreach ($categories as $category) {
$spent = $repository->spentInPeriod($category, $start, $month, $shared);
$row[] = $spent;
}
$chart->addRowArray($row);
$start->addMonth();
}
$chart->generate();

View File

@@ -170,9 +170,15 @@ class CategoryRepository implements CategoryRepositoryInterface
*
* @return float
*/
public function spentInPeriodSum(Category $category, Carbon $start, Carbon $end)
public function spentInPeriod(Category $category, Carbon $start, Carbon $end, $shared = false)
{
return floatval($category->transactionjournals()->before($end)->after($start)->lessThan(0)->sum('amount')) * -1;
if($shared === false) {
// do something else, SEE budgets.
$sum = floatval($category->transactionjournals()->before($end)->after($start)->lessThan(0)->sum('amount')) * -1;
} else {
$sum = floatval($category->transactionjournals()->before($end)->after($start)->lessThan(0)->sum('amount')) * -1;
}
return $sum;
}
/**

View File

@@ -77,7 +77,7 @@ interface CategoryRepositoryInterface
*
* @return float
*/
public function spentInPeriodSum(Category $category, Carbon $start, Carbon $end);
public function spentInPeriod(Category $category, Carbon $start, Carbon $end, $shared = false);
/**
* @param Category $category