diff --git a/app/Generator/Chart/Category/CategoryChartGenerator.php b/app/Generator/Chart/Category/CategoryChartGenerator.php index de6891b556..f249b320bb 100644 --- a/app/Generator/Chart/Category/CategoryChartGenerator.php +++ b/app/Generator/Chart/Category/CategoryChartGenerator.php @@ -27,6 +27,14 @@ interface CategoryChartGenerator */ public function earnedInYear(Collection $categories, Collection $entries); + /** + * @param Collection $categories + * @param Collection $entries + * + * @return array + */ + public function earnedInPeriod(Collection $categories, Collection $entries); + /** * @param Collection $entries * diff --git a/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php b/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php index 76c09790f2..88df36fd69 100644 --- a/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php +++ b/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php @@ -157,6 +157,39 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator } + /** + * @param Collection $categories + * @param Collection $entries + * + * @return array + */ + public function earnedInPeriod(Collection $categories, Collection $entries) + { + + // language: + $format = trans('config.month'); + + $data = [ + 'count' => 0, + 'labels' => [], + 'datasets' => [], + ]; + + foreach ($categories as $category) { + $data['labels'][] = $category->name; + } + + foreach ($entries as $entry) { + $date = $entry[0]->formatLocalized($format); + array_shift($entry); + $data['count']++; + $data['datasets'][] = ['label' => $date, 'data' => $entry]; + } + + return $data; + + } + /** * @param Collection $entries * diff --git a/app/Http/routes.php b/app/Http/routes.php index 4ff527f2f8..2f580fe108 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -414,8 +414,8 @@ Route::group( Route::get('/chart/category/frontpage', ['uses' => 'Chart\CategoryController@frontpage']); // these three charts are for reports: + Route::get('/chart/category/earned-in-period/{report_type}/{start_date}/{end_date}/{accountList}', ['uses' => 'Chart\CategoryController@earnedInPeriod']); Route::get('/chart/category/spent-in-year/{report_type}/{start_date}/{end_date}/{accountList}', ['uses' => 'Chart\CategoryController@spentInYear']); - Route::get('/chart/category/earned-in-year/{report_type}/{start_date}/{end_date}/{accountList}', ['uses' => 'Chart\CategoryController@earnedInYear']); Route::get( '/chart/category/multi-year/{report_type}/{start_date}/{end_date}/{accountList}/{categoryList}', ['uses' => 'Chart\CategoryController@multiYear'] );