From 33c0c1bea668a09b48b989560388700312a8e482 Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 1 Nov 2016 19:06:35 +0100 Subject: [PATCH] Removed everything pointless from multi year report. Signed-off-by: James Cole --- .../Budget/BudgetChartGeneratorInterface.php | 7 - .../Budget/ChartJsBudgetChartGenerator.php | 34 ----- .../CategoryChartGeneratorInterface.php | 7 - .../ChartJsCategoryChartGenerator.php | 28 ---- .../Controllers/Chart/BudgetController.php | 74 ---------- .../Controllers/Chart/CategoryController.php | 72 --------- app/Http/Controllers/ReportController.php | 10 +- public/js/ff/reports/default/multi-year.js | 138 ------------------ .../views/reports/default/multi-year.twig | 82 ----------- routes/web.php | 5 - 10 files changed, 2 insertions(+), 455 deletions(-) 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(''); - - // 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(''); - - // 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 @@ - - {% for account in accounts %} - - {% endfor %} -
@@ -104,71 +87,6 @@
-
-
-
-
-

Selected budgets

-
-
-
-
- - -
-
-
-
- - {% for budget in budgets %} - - {% endfor %} -
-
-
-
-
-
- -
-
-
-
-

Selected categories

-
-
-
-
- - -
-
-
-
- - {% for category in categories %} - - {% endfor %} -
-
-
-
-
-
- - {% endblock %} {% block styles %} 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']);