Skip to content

Firefly III: a personal finances manager

Removed everything pointless from multi year report.

James Cole33c0c1bea668
diff --git a/app/Generator/Chart/Budget/BudgetChartGeneratorInterface.php b/app/Generator/Chart/Budget/BudgetChartGeneratorInterface.php
index fc466aa418..4983d9635a 100644
--- a/app/Generator/Chart/Budget/BudgetChartGeneratorInterface.php
+++ b/app/Generator/Chart/Budget/BudgetChartGeneratorInterface.php
@@ -38,13 +38,6 @@ interface BudgetChartGeneratorInterface
*/
public function frontpage(Collection $entries): array;
- /**
- * @param Collection $entries
- *
- * @return array
- */
- public function multiYear(Collection $entries): array;
-
/**
* @param Collection $entries
* @param string $viewRange
diff --git a/app/Generator/Chart/Budget/ChartJsBudgetChartGenerator.php b/app/Generator/Chart/Budget/ChartJsBudgetChartGenerator.php
index f82fb807c5..cf78936c4d 100644
--- a/app/Generator/Chart/Budget/ChartJsBudgetChartGenerator.php
+++ b/app/Generator/Chart/Budget/ChartJsBudgetChartGenerator.php
@@ -100,40 +100,6 @@ class ChartJsBudgetChartGenerator implements BudgetChartGeneratorInterface
return $data;
}
- /**
- * @param Collection $entries
- *
- * @return array
- */
- public function multiYear(Collection $entries): array
- {
- // dataset:
- $data = [
- 'count' => 0,
- 'labels' => [],
- 'datasets' => [],
- ];
- // get labels from one of the budgets (assuming there's at least one):
- $first = $entries->first();
- $keys = array_keys($first['budgeted']);
- foreach ($keys as $year) {
- $data['labels'][] = strval($year);
- }
-
- // then, loop all entries and create datasets:
- foreach ($entries as $entry) {
- $name = $entry['name'];
- $spent = $entry['spent'];
- $budgeted = $entry['budgeted'];
- $data['datasets'][] = ['label' => 'Spent on ' . $name, 'data' => array_values($spent)];
- $data['datasets'][] = ['label' => 'Budgeted for ' . $name, 'data' => array_values($budgeted)];
- }
- $data['count'] = count($data['datasets']);
-
- return $data;
-
- }
-
/**
* @param Collection $entries
* @param string $viewRange
diff --git a/app/Generator/Chart/Category/CategoryChartGeneratorInterface.php b/app/Generator/Chart/Category/CategoryChartGeneratorInterface.php
index 56d57f6966..e17022d9b6 100644
--- a/app/Generator/Chart/Category/CategoryChartGeneratorInterface.php
+++ b/app/Generator/Chart/Category/CategoryChartGeneratorInterface.php
@@ -45,13 +45,6 @@ interface CategoryChartGeneratorInterface
*/
public function frontpage(Collection $entries): array;
- /**
- * @param Collection $entries
- *
- * @return array
- */
- public function multiYear(Collection $entries): array;
-
/**
* @param Collection $entries
*
diff --git a/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php b/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php
index 631b867cd1..560b4f95bb 100644
--- a/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php
+++ b/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php
@@ -117,34 +117,6 @@ class ChartJsCategoryChartGenerator implements CategoryChartGeneratorInterface
return $data;
}
- /**
- * @param Collection $entries
- *
- * @return array
- */
- public function multiYear(Collection $entries): array
- {
- // get labels from one of the categories (assuming there's at least one):
- $first = $entries->first();
- $data = ['count' => 0, 'labels' => array_keys($first['spent']), 'datasets' => [],];
-
- // then, loop all entries and create datasets:
- foreach ($entries as $entry) {
- $name = $entry['name'];
- $spent = $entry['spent'];
- $earned = $entry['earned'];
- if (array_sum(array_values($spent)) != 0) {
- $data['datasets'][] = ['label' => 'Spent in category ' . $name, 'data' => array_values($spent)];
- }
- if (array_sum(array_values($earned)) != 0) {
- $data['datasets'][] = ['label' => 'Earned in category ' . $name, 'data' => array_values($earned)];
- }
- }
- $data['count'] = count($data['datasets']);
-
- return $data;
- }
-
/**
*
* @param Collection $entries
diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php
index 56eeb966ef..3e6c5f1c83 100644
--- a/app/Http/Controllers/Chart/BudgetController.php
+++ b/app/Http/Controllers/Chart/BudgetController.php
@@ -183,80 +183,6 @@ class BudgetController extends Controller
return Response::json($data);
}
- /**
- *
- * @param BudgetRepositoryInterface $repository
- * @param Carbon $start
- * @param Carbon $end
- * @param Collection $accounts
- * @param Collection $budgets
- *
- *
- * @return \Illuminate\Http\JsonResponse
- */
- public function multiYear(BudgetRepositoryInterface $repository, Carbon $start, Carbon $end, Collection $accounts, Collection $budgets)
- {
-
- $cache = new CacheProperties();
- $cache->addProperty($start);
- $cache->addProperty($end);
- $cache->addProperty($accounts);
- $cache->addProperty($budgets);
- $cache->addProperty('multiYearBudget');
-
- if ($cache->has()) {
- return Response::json($cache->get());
- }
- $budgetIds = $budgets->pluck('id')->toArray();
- $repetitions = $repository->getAllBudgetLimitRepetitions($start, $end);
- $budgeted = [];
- $entries = new Collection;
- // filter budgets once:
- $repetitions = $repetitions->filter(
- function (LimitRepetition $repetition) use ($budgetIds) {
- if (in_array(strval($repetition->budget_id), $budgetIds)) {
- return true;
- }
-
- return false;
- }
- );
- /** @var LimitRepetition $repetition */
- foreach ($repetitions as $repetition) {
- $year = $repetition->startdate->year;
- if (isset($budgeted[$repetition->budget_id][$year])) {
- $budgeted[$repetition->budget_id][$year] = bcadd($budgeted[$repetition->budget_id][$year], $repetition->amount);
- continue;
- }
- $budgeted[$repetition->budget_id][$year] = $repetition->amount;
- }
-
- foreach ($budgets as $budget) {
- $currentStart = clone $start;
- $entry = ['name' => $budget->name, 'spent' => [], 'budgeted' => []];
- while ($currentStart < $end) {
- // fix the date:
- $currentEnd = clone $currentStart;
- $year = $currentStart->year;
- $currentEnd->endOfYear();
-
- $spent = $repository->spentInPeriod(new Collection([$budget]), $accounts, $currentStart, $currentEnd);
-
- // jump to next year.
- $currentStart = clone $currentEnd;
- $currentStart->addDay();
-
- $entry['spent'][$year] = round($spent * -1, 2);
- $entry['budgeted'][$year] = isset($budgeted[$budget->id][$year]) ? round($budgeted[$budget->id][$year], 2) : 0;
- }
- $entries->push($entry);
- }
- $data = $this->generator->multiYear($entries);
- $cache->store($data);
-
- return Response::json($data);
- }
-
/**
* @param BudgetRepositoryInterface $repository
* @param Budget $budget
diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php
index 98a8392ca4..f8d9882e28 100644
--- a/app/Http/Controllers/Chart/CategoryController.php
+++ b/app/Http/Controllers/Chart/CategoryController.php
@@ -153,78 +153,6 @@ class CategoryController extends Controller
}
- /**
- * @param Carbon $start
- * @param Carbon $end
- * @param Collection $accounts
- * @param Collection $categories
- *
- * @return \Illuminate\Http\JsonResponse
- */
- public function multiYear(Carbon $start, Carbon $end, Collection $accounts, Collection $categories)
- {
-
- /** @var CRI $repository */
- $repository = app(CRI::class);
-
- // chart properties for cache:
- $cache = new CacheProperties();
- $cache->addProperty($start);
- $cache->addProperty($end);
- $cache->addProperty($accounts);
- $cache->addProperty($categories);
- $cache->addProperty('multiYearCategory');
-
- if ($cache->has()) {
- return Response::json($cache->get());
- }
-
- $entries = new Collection;
-
- /** @var Category $category */
- foreach ($categories as $category) {
- $entry = ['name' => '', 'spent' => [], 'earned' => []];
-
- $currentStart = clone $start;
- while ($currentStart < $end) {
- // fix the date:
- $year = $currentStart->year;
- $currentEnd = clone $currentStart;
- $currentEnd->endOfYear();
-
- // get data:
- if (is_null($category->id)) {
- $entry['name'] = trans('firefly.noCategory');
- $entry['spent'][$year] = ($repository->spentInPeriodWithoutCategory($accounts, $currentStart, $currentEnd) * -1);
- $entry['earned'][$year] = $repository->earnedInPeriodWithoutCategory($accounts, $currentStart, $currentEnd);
-
- // jump to next year.
- $currentStart = clone $currentEnd;
- $currentStart->addDay();
- continue;
-
- }
- // alternative is a normal category:
- $entry['name'] = $category->name;
- $entry['spent'][$year] = ($repository->spentInPeriod(new Collection([$category]), $accounts, $currentStart, $currentEnd) * -1);
- $entry['earned'][$year] = $repository->earnedInPeriod(new Collection([$category]), $accounts, $currentStart, $currentEnd);
-
- // 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 CRI $repository
* @param Category $category
diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php
index 77a50d7218..9c0d213260 100644
--- a/app/Http/Controllers/ReportController.php
+++ b/app/Http/Controllers/ReportController.php
@@ -245,10 +245,6 @@ class ReportController extends Controller
private function defaultMultiYear(string $reportType, Carbon $start, Carbon $end, Collection $accounts)
{
- $budgets = app(BudgetRepositoryInterface::class)->getActiveBudgets();
- $categories = app(CategoryRepositoryInterface::class)->getCategories();
- $tags = $this->helper->tagReport($start, $end, $accounts);
-
// and some id's, joined:
$accountIds = [];
/** @var Account $account */
@@ -260,7 +256,7 @@ class ReportController extends Controller
return view(
'reports.default.multi-year',
compact(
- 'budgets', 'accounts', 'categories', 'start', 'end', 'accountIds', 'reportType', 'tags'
+ 'accounts', 'start', 'end', 'accountIds', 'reportType'
)
);
}
@@ -275,8 +271,6 @@ class ReportController extends Controller
*/
private function defaultYear(string $reportType, Carbon $start, Carbon $end, Collection $accounts)
{
- $tags = $this->helper->tagReport($start, $end, $accounts);
-
Session::flash('gaEventCategory', 'report');
Session::flash('gaEventAction', 'year');
Session::flash('gaEventLabel', $start->format('Y'));
@@ -293,7 +287,7 @@ class ReportController extends Controller
'reports.default.year',
compact(
'start', 'reportType',
- 'accountIds', 'end', 'tags'
+ 'accountIds', 'end'
)
);
}
diff --git a/public/js/ff/reports/default/multi-year.js b/public/js/ff/reports/default/multi-year.js
index 78845f5100..04b9ab3ddb 100644
--- a/public/js/ff/reports/default/multi-year.js
+++ b/public/js/ff/reports/default/multi-year.js
@@ -15,142 +15,4 @@ function drawChart() {
lineChart('chart/report/net-worth/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds, 'net-worth');
columnChart('chart/report/in-out/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds, 'income-expenses-chart');
columnChart('chart/report/in-out-sum/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds, 'income-expenses-sum-chart');
-
-
- $.each($('.account-chart'), function (i, v) {
- var holder = $(v);
- console.log('Will draw chart for account #' + holder.data('id'));
- });
-
- // draw budget chart based on selected budgets:
- $('.budget-checkbox').on('change', updateBudgetChart);
- selectBudgetsByCookie();
- updateBudgetChart();
-
- // draw category chart based on selected budgets:
- $('.category-checkbox').on('change', updateCategoryChart);
- selectCategoriesByCookie();
- updateCategoryChart();
-}
-
-function selectBudgetsByCookie() {
- "use strict";
- var cookie = readCookie('multi-year-budgets');
- if (cookie !== null) {
- var cookieArray = cookie.split(',');
- for (var x in cookieArray) {
- var budgetId = cookieArray[x];
- $('.budget-checkbox[value="' + budgetId + '"').prop('checked', true);
- }
- }
-}
-
-function selectCategoriesByCookie() {
- "use strict";
- var cookie = readCookie('multi-year-categories');
- if (cookie !== null) {
- var cookieArray = cookie.split(',');
- for (var x in cookieArray) {
- var categoryId = cookieArray[x];
- $('.category-checkbox[value="' + categoryId + '"').prop('checked', true);
- }
- }
-}
-
-function updateBudgetChart() {
- "use strict";
- console.log('will update budget chart.');
- // get all budget ids:
- var budgets = [];
- $.each($('.budget-checkbox'), function (i, v) {
- var current = $(v);
- if (current.prop('checked')) {
- budgets.push(current.val());
- }
- });
-
- if (budgets.length > 0) {
-
- var budgetIds = budgets.join(',');
-
- // remove old chart:
- $('#budgets-chart').replaceWith('<canvas id="budgets-chart" class="budgets-chart" style="width:100%;height:400px;"></canvas>');
-
- // hide message:
- $('#budgets-chart-message').hide();
-
- // draw chart. Redraw when exists? Not sure if we support that.
- columnChart('chart/budget/multi-year/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds + '/' + budgetIds, 'budgets-chart');
- createCookie('multi-year-budgets', budgets, 365);
- } else {
- // hide canvas, show message:
- $('#budgets-chart-message').show();
- $('#budgets-chart').hide();
-
- }
-
-}
-
-function updateCategoryChart() {
- "use strict";
- console.log('will update category chart.');
- // get all category ids:
- var categories = [];
- $.each($('.category-checkbox'), function (i, v) {
- var current = $(v);
- if (current.prop('checked')) {
- categories.push(current.val());
- }
- });
-
- if (categories.length > 0) {
-
- var categoryIds = categories.join(',');
-
- // remove old chart:
- $('#categories-chart').replaceWith('<canvas id="categories-chart" class="budgets-chart" style="width:100%;height:400px;"></canvas>');
-
- // hide message:
- $('#categories-chart-message').hide();
-
- // draw chart. Redraw when exists? Not sure if we support that.
- columnChart('chart/category/multi-year/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds + '/' + categoryIds, 'categories-chart');
- createCookie('multi-year-categories', categories, 365);
- } else {
- // hide canvas, show message:
- $('#categories-chart-message').show();
- $('#categories-chart').hide();
-
- }
}
-
-
-function createCookie(name, value, days) {
- "use strict";
- var expires;
-
- if (days) {
- var date = new Date();
- date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
- expires = "; expires=" + date.toGMTString();
- } else {
- expires = "";
- }
- document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=/";
-}
-
-function readCookie(name) {
- "use strict";
- var nameEQ = encodeURIComponent(name) + "=";
- var ca = document.cookie.split(';');
- for (var i = 0; i < ca.length; i++) {
- var c = ca[i];
- while (c.charAt(0) === ' ') c = c.substring(1, c.length);
- if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length));
- }
- return null;
-}
-
-function eraseCookie(name) {
- createCookie(name, "", -1);
-}
\ No newline at end of file
diff --git a/resources/views/reports/default/multi-year.twig b/resources/views/reports/default/multi-year.twig
index 9eeff7cafe..121784617c 100644
--- a/resources/views/reports/default/multi-year.twig
+++ b/resources/views/reports/default/multi-year.twig
@@ -74,23 +74,6 @@
</div>
</div>
-
- {% for account in accounts %}
- <div class="row" style="display:none;">
- <div class="col-lg-12 col-md-12 col-sm-12">
- <div class="box">
- <div class="box-header with-border">
- <h3 class="box-title">{{ 'Asset account'|_ }}: {{ account.name }}</h3>
- </div>
- <div class="box-body">
- <canvas id="account-chart-{{ account.id }}" class="account-chart" data-id="{{ account.id }}" style="width:100%;height:400px;"
- height="400"></canvas>
- </div>
- </div>
- </div>
- </div>
- {% endfor %}
-
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="box">
@@ -104,71 +87,6 @@
</div>
</div>
- <div class="row">
- <div class="col-lg-12 col-md-12 col-sm-12">
- <div class="box">
- <div class="box-header with-border">
- <h3 class="box-title">Selected budgets</h3>
- </div>
- <div class="box-body">
- <div class="row">
- <div class="col-lg-12">
- <p class="well" id="budgets-chart-message" style="display:none;">
- Select one or more budgets to generate this chart. Insofar possible, your selection will be saved.
- </p>
- <canvas id="budgets-chart" class="budgets-chart" style="width:100%;height:400px;" height="400"></canvas>
- </div>
- </div>
- <div class="row">
- <div class="col-lg-12">
- <label class="checkbox-inline">
- <input type="checkbox" class="budget-checkbox" name="budgets[]" value="0"> {{ 'no_budget'|_ }}
- </label>
- {% for budget in budgets %}
- <label class="checkbox-inline">
- <input type="checkbox" class="budget-checkbox" name="budgets[]" value="{{ budget.id }}"> {{ budget.name }}
- </label>
- {% endfor %}
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
-
- <div class="row">
- <div class="col-lg-12 col-md-12 col-sm-12">
- <div class="box">
- <div class="box-header with-border">
- <h3 class="box-title">Selected categories</h3>
- </div>
- <div class="box-body">
- <div class="row">
- <div class="col-lg-12">
- <p class="well" id="categories-chart-message" style="display:none;">
- Select one or more categories to generate this chart. Insofar possible, your selection will be saved.
- </p>
- <canvas id="categories-chart" class="categories-chart" style="width:100%;height:400px;" height="400"></canvas>
- </div>
- </div>
- <div class="row">
- <div class="col-lg-12">
- <label class="checkbox-inline">
- <input type="checkbox" class="category-checkbox" name="categories[]" value="0"> {{ 'noCategory'|_ }}
- </label>
- {% for category in categories %}
- <label class="checkbox-inline">
- <input type="checkbox" name="categories[]" class="category-checkbox" value="{{ category.id }}"> {{ category.name }}
- </label>
- {% endfor %}
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
-
-
{% endblock %}
{% block styles %}
<link rel="stylesheet" href="css/bootstrap-sortable.css" type="text/css" media="all"/>
diff --git a/routes/web.php b/routes/web.php
index 69fd01df55..7a5072cf29 100755
--- a/routes/web.php
+++ b/routes/web.php
@@ -198,17 +198,12 @@ Route::group(
Route::get('/chart/budget/frontpage', ['uses' => 'Chart\BudgetController@frontpage']);
// this chart is used in reports:
- Route::get('/chart/budget/multi-year/default/{start_date}/{end_date}/{accountList}/{budgetList}', ['uses' => 'Chart\BudgetController@multiYear']);
- Route::get('/chart/budget/period/{budget}/default/{start_date}/{end_date}/{accountList}', ['uses' => 'Chart\BudgetController@period']);
Route::get('/chart/budget/{budget}/{limitrepetition}', ['uses' => 'Chart\BudgetController@budgetLimit']);
Route::get('/chart/budget/{budget}', ['uses' => 'Chart\BudgetController@budget']);
// categories:
Route::get('/chart/category/frontpage', ['uses' => 'Chart\CategoryController@frontpage']);
- // these three charts are for reports:
- Route::get('/chart/category/multi-year/default/{start_date}/{end_date}/{accountList}/{categoryList}', ['uses' => 'Chart\CategoryController@multiYear']);
-
Route::get('/chart/category/{category}/period', ['uses' => 'Chart\CategoryController@currentPeriod']);
Route::get('/chart/category/{category}/period/{date}', ['uses' => 'Chart\CategoryController@specificPeriod']);
Route::get('/chart/category/{category}/all', ['uses' => 'Chart\CategoryController@all']);