mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Fixed tests
This commit is contained in:
@@ -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);
|
||||
|
@@ -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();
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user