Changed a lot of parameters.

This commit is contained in:
James Cole
2016-02-05 09:25:15 +01:00
parent 554640c345
commit 78bcd3e1bb
64 changed files with 539 additions and 572 deletions

View File

@@ -43,7 +43,7 @@ class AccountController extends Controller
*
* @return \Illuminate\Http\JsonResponse
*/
public function report($reportType, Carbon $start, Carbon $end, Collection $accounts)
public function report(string $reportType, Carbon $start, Carbon $end, Collection $accounts)
{
// chart properties for cache:
$cache = new CacheProperties();

View File

@@ -35,87 +35,6 @@ class BudgetController extends Controller
$this->generator = app('FireflyIII\Generator\Chart\Budget\BudgetChartGeneratorInterface');
}
/**
*
* @param BudgetRepositoryInterface $repository
* @param $reportType
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
* @param Collection $budgets
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList) // need all parameters
*
* @return \Illuminate\Http\JsonResponse
*/
public function multiYear(BudgetRepositoryInterface $repository, $reportType, Carbon $start, Carbon $end, Collection $accounts, Collection $budgets)
{
// chart properties for cache:
$cache = new CacheProperties();
$cache->addProperty($reportType);
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($accounts);
$cache->addProperty($budgets);
$cache->addProperty('multiYearBudget');
if ($cache->has()) {
return Response::json($cache->get()); // @codeCoverageIgnore
}
/*
* Get the budgeted amounts for each budgets in each year.
*/
$budgetedSet = $repository->getBudgetedPerYear($budgets, $start, $end);
$budgetedArray = [];
/** @var Budget $entry */
foreach ($budgetedSet as $entry) {
$budgetedArray[$entry->id][$entry->dateFormatted] = $entry->budgeted;
}
$set = $repository->getBudgetsAndExpensesPerYear($budgets, $accounts, $start, $end);
$entries = new Collection;
// go by budget, not by year.
/** @var Budget $budget */
foreach ($budgets as $budget) {
$entry = ['name' => '', 'spent' => [], 'budgeted' => []];
$id = $budget->id;
$currentStart = clone $start;
while ($currentStart < $end) {
// fix the date:
$currentEnd = clone $currentStart;
$currentEnd->endOfYear();
// save to array:
$year = $currentStart->year;
$entry['name'] = $budget->name;
$spent = 0;
$budgeted = 0;
if (isset($set[$id]['entries'][$year])) {
$spent = $set[$id]['entries'][$year] * -1;
}
if (isset($budgetedArray[$id][$year])) {
$budgeted = round($budgetedArray[$id][$year], 2);
}
$entry['spent'][$year] = $spent;
$entry['budgeted'][$year] = $budgeted;
// jump to next year.
$currentStart = clone $currentEnd;
$currentStart->addDay();
}
$entries->push($entry);
}
// generate chart with data:
$data = $this->generator->multiYear($entries);
$cache->store($data);
return Response::json($data);
}
/**
* @param BudgetRepositoryInterface $repository
* @param Budget $budget
@@ -298,10 +217,91 @@ class BudgetController extends Controller
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
* @param Collection $budgets
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList) // need all parameters
*
* @return \Illuminate\Http\JsonResponse
*/
public function year(BudgetRepositoryInterface $repository, $reportType, Carbon $start, Carbon $end, Collection $accounts)
public function multiYear(BudgetRepositoryInterface $repository, string $reportType, Carbon $start, Carbon $end, Collection $accounts, Collection $budgets)
{
// chart properties for cache:
$cache = new CacheProperties();
$cache->addProperty($reportType);
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($accounts);
$cache->addProperty($budgets);
$cache->addProperty('multiYearBudget');
if ($cache->has()) {
return Response::json($cache->get()); // @codeCoverageIgnore
}
/*
* Get the budgeted amounts for each budgets in each year.
*/
$budgetedSet = $repository->getBudgetedPerYear($budgets, $start, $end);
$budgetedArray = [];
/** @var Budget $entry */
foreach ($budgetedSet as $entry) {
$budgetedArray[$entry->id][$entry->dateFormatted] = $entry->budgeted;
}
$set = $repository->getBudgetsAndExpensesPerYear($budgets, $accounts, $start, $end);
$entries = new Collection;
// go by budget, not by year.
/** @var Budget $budget */
foreach ($budgets as $budget) {
$entry = ['name' => '', 'spent' => [], 'budgeted' => []];
$id = $budget->id;
$currentStart = clone $start;
while ($currentStart < $end) {
// fix the date:
$currentEnd = clone $currentStart;
$currentEnd->endOfYear();
// save to array:
$year = $currentStart->year;
$entry['name'] = $budget->name;
$spent = 0;
$budgeted = 0;
if (isset($set[$id]['entries'][$year])) {
$spent = $set[$id]['entries'][$year] * -1;
}
if (isset($budgetedArray[$id][$year])) {
$budgeted = round($budgetedArray[$id][$year], 2);
}
$entry['spent'][$year] = $spent;
$entry['budgeted'][$year] = $budgeted;
// jump to next year.
$currentStart = clone $currentEnd;
$currentStart->addDay();
}
$entries->push($entry);
}
// generate chart with data:
$data = $this->generator->multiYear($entries);
$cache->store($data);
return Response::json($data);
}
/**
*
* @param BudgetRepositoryInterface $repository
* @param $reportType
* @param Carbon $start
* @param Carbon $end
* @param Collection $accounts
*
* @return \Illuminate\Http\JsonResponse
*/
public function year(BudgetRepositoryInterface $repository, string $reportType, Carbon $start, Carbon $end, Collection $accounts)
{
// chart properties for cache:
$cache = new CacheProperties();

View File

@@ -114,7 +114,7 @@ class CategoryController extends Controller
*
* @return \Illuminate\Http\JsonResponse
*/
public function earnedInPeriod(CRI $repository, $reportType, Carbon $start, Carbon $end, Collection $accounts)
public function earnedInPeriod(CRI $repository, string $reportType, Carbon $start, Carbon $end, Collection $accounts)
{
$cache = new CacheProperties; // chart properties for cache:
$cache->addProperty($start);
@@ -215,7 +215,7 @@ class CategoryController extends Controller
*
* @return \Illuminate\Http\JsonResponse
*/
public function multiYear($reportType, Carbon $start, Carbon $end, Collection $accounts, Collection $categories)
public function multiYear(string $reportType, Carbon $start, Carbon $end, Collection $accounts, Collection $categories)
{
/** @var CRI $repository */
$repository = app('FireflyIII\Repositories\Category\CategoryRepositoryInterface');

View File

@@ -45,7 +45,7 @@ class ReportController extends Controller
*
* @return \Illuminate\Http\JsonResponse
*/
public function yearInOut(ReportQueryInterface $query, $reportType, Carbon $start, Carbon $end, Collection $accounts)
public function yearInOut(ReportQueryInterface $query, string $reportType, Carbon $start, Carbon $end, Collection $accounts)
{
// chart properties for cache:
$cache = new CacheProperties;
@@ -88,7 +88,7 @@ class ReportController extends Controller
*
* @return \Illuminate\Http\JsonResponse
*/
public function yearInOutSummarized(ReportQueryInterface $query, $reportType, Carbon $start, Carbon $end, Collection $accounts)
public function yearInOutSummarized(ReportQueryInterface $query, string $reportType, Carbon $start, Carbon $end, Collection $accounts)
{
// chart properties for cache: