Skip to content

Firefly III: a personal finances manager

Fixed some yearly charts.

James Cole8fdd0cb79521
diff --git a/app/Http/Controllers/Chart/BudgetController.php b/app/Http/Controllers/Chart/BudgetController.php
index 0e017fd380..c03885ef74 100644
--- a/app/Http/Controllers/Chart/BudgetController.php
+++ b/app/Http/Controllers/Chart/BudgetController.php
@@ -197,11 +197,8 @@ class BudgetController extends Controller
*
* @return \Symfony\Component\HttpFoundation\Response
*/
- public function year(BudgetRepositoryInterface $repository, $year, $shared = false)
+ public function year(BudgetRepositoryInterface $repository, $report_type, Carbon $start, Carbon $end, Collection $accounts)
{
- $start = new Carbon($year . '-01-01');
- $end = new Carbon($year . '-12-31');
- $shared = $shared == 'shared' ? true : false;
$allBudgets = $repository->getBudgets();
$budgets = new Collection;
@@ -218,7 +215,7 @@ class BudgetController extends Controller
// filter empty budgets:
foreach ($allBudgets as $budget) {
- $spent = $repository->balanceInPeriod($budget, $start, $end, $shared);
+ $spent = $repository->balanceInPeriodForList($budget, $start, $end, $accounts);
if ($spent != 0) {
$budgets->push($budget);
}
@@ -234,7 +231,7 @@ class BudgetController extends Controller
// each budget, fill the row:
foreach ($budgets as $budget) {
- $spent = $repository->balanceInPeriod($budget, $start, $month, $shared);
+ $spent = $repository->balanceInPeriodForList($budget, $start, $month, $accounts);
$row[] = $spent * -1;
}
$entries->push($row);
diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php
index bbc0e143fd..15dcbc14f7 100644
--- a/app/Http/Controllers/Chart/CategoryController.php
+++ b/app/Http/Controllers/Chart/CategoryController.php
@@ -213,15 +213,15 @@ class CategoryController extends Controller
* This chart will only show expenses.
*
* @param CategoryRepositoryInterface $repository
- * @param $year
- * @param bool $shared
+ * @param $report_type
+ * @param Carbon $start
+ * @param Carbon $end
+ * @param Collection $accounts
*
- * @return \Symfony\Component\HttpFoundation\Response
+ * @return \Illuminate\Http\JsonResponse
*/
- public function spentInYear(CategoryRepositoryInterface $repository, $year, $shared = false)
+ public function spentInYear(CategoryRepositoryInterface $repository, $report_type, Carbon $start, Carbon $end, Collection $accounts)
{
- $start = new Carbon($year . '-01-01');
- $end = new Carbon($year . '-12-31');
$cache = new CacheProperties; // chart properties for cache:
$cache->addProperty($start);
@@ -232,12 +232,11 @@ class CategoryController extends Controller
return Response::json($cache->get()); // @codeCoverageIgnore
}
- $shared = $shared == 'shared' ? true : false;
$allCategories = $repository->getCategories();
$entries = new Collection;
$categories = $allCategories->filter(
- function (Category $category) use ($repository, $start, $end, $shared) {
- $spent = $repository->balanceInPeriod($category, $start, $end, $shared);
+ function (Category $category) use ($repository, $start, $end, $accounts) {
+ $spent = $repository->balanceInPeriodForList($category, $start, $end, $accounts);
if ($spent < 0) {
return $category;
}
@@ -252,7 +251,7 @@ class CategoryController extends Controller
$row = [clone $start]; // make a row:
foreach ($categories as $category) { // each budget, fill the row
- $spent = $repository->balanceInPeriod($category, $start, $month, $shared);
+ $spent = $repository->balanceInPeriodForList($category, $start, $month, $accounts);
if ($spent < 0) {
$row[] = $spent * -1;
} else {
@@ -272,16 +271,15 @@ class CategoryController extends Controller
* This chart will only show income.
*
* @param CategoryRepositoryInterface $repository
- * @param $year
- * @param bool $shared
+ * @param $report_type
+ * @param Carbon $start
+ * @param Carbon $end
+ * @param Collection $accounts
*
- * @return \Symfony\Component\HttpFoundation\Response
+ * @return \Illuminate\Http\JsonResponse
*/
- public function earnedInYear(CategoryRepositoryInterface $repository, $year, $shared = false)
+ public function earnedInYear(CategoryRepositoryInterface $repository, $report_type, Carbon $start, Carbon $end, Collection $accounts)
{
- $start = new Carbon($year . '-01-01');
- $end = new Carbon($year . '-12-31');
-
$cache = new CacheProperties; // chart properties for cache:
$cache->addProperty($start);
$cache->addProperty($end);
@@ -291,12 +289,11 @@ class CategoryController extends Controller
return Response::json($cache->get()); // @codeCoverageIgnore
}
- $shared = $shared == 'shared' ? true : false;
$allCategories = $repository->getCategories();
$allEntries = new Collection;
$categories = $allCategories->filter(
- function (Category $category) use ($repository, $start, $end, $shared) {
- $spent = $repository->balanceInPeriod($category, $start, $end, $shared);
+ function (Category $category) use ($repository, $start, $end, $accounts) {
+ $spent = $repository->balanceInPeriodForList($category, $start, $end, $accounts);
if ($spent > 0) {
return $category;
}
@@ -311,7 +308,7 @@ class CategoryController extends Controller
$row = [clone $start]; // make a row:
foreach ($categories as $category) { // each budget, fill the row
- $spent = $repository->balanceInPeriod($category, $start, $month, $shared);
+ $spent = $repository->balanceInPeriodForList($category, $start, $month, $accounts);
if ($spent > 0) {
$row[] = $spent;
} else {
diff --git a/app/Http/routes.php b/app/Http/routes.php
index d280c50bbb..2ff48fa11b 100644
--- a/app/Http/routes.php
+++ b/app/Http/routes.php
@@ -355,18 +355,22 @@ Route::group(
// budgets:
Route::get('/chart/budget/frontpage', ['uses' => 'Chart\BudgetController@frontpage']);
- Route::get('/chart/budget/year/{year}/{shared?}', ['uses' => 'Chart\BudgetController@year'])->where(['year' => '[0-9]{4}', 'shared' => 'shared']);
+
+ // this chart is used in reports:
+ Route::get('/chart/budget/year/{report_type}/{start_date}/{end_date}/{accountList}', ['uses' => 'Chart\BudgetController@year'])->where(['year' => '[0-9]{4}', 'shared' => 'shared']);
+
+
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']);
- Route::get('/chart/category/spent-in-year/{year}/{shared?}', ['uses' => 'Chart\CategoryController@spentInYear'])->where(
- ['year' => '[0-9]{4}', 'shared' => 'shared']
- );
- Route::get('/chart/category/earned-in-year/{year}/{shared?}', ['uses' => 'Chart\CategoryController@earnedInYear'])->where(
- ['year' => '[0-9]{4}', 'shared' => 'shared']
- );
+
+ // both charts are for reports:
+ 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/{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']);
diff --git a/public/js/reports.js b/public/js/reports.js
index 578d79f92c..e0befb472e 100644
--- a/public/js/reports.js
+++ b/public/js/reports.js
@@ -109,18 +109,17 @@ function drawChart() {
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');
}
- //if (typeof stackedColumnChart !== 'undefined' && typeof year !== 'undefined' && typeof month === 'undefined') {
- // stackedColumnChart('chart/budget/year/' + year + shared, 'budgets');
- // stackedColumnChart('chart/category/spent-in-year/' + year + shared, 'categories-spent-in-year');
- // stackedColumnChart('chart/category/earned-in-year/' + year + shared, 'categories-earned-in-year');
- //}
+ if (typeof stackedColumnChart !== 'undefined' && typeof year !== 'undefined' && typeof month === 'undefined') {
+ stackedColumnChart('chart/budget/year/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds, 'budgets');
+ stackedColumnChart('chart/category/spent-in-year/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds, 'categories-spent-in-year');
+ stackedColumnChart('chart/category/earned-in-year/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds, 'categories-earned-in-year');
+ }
//if (typeof lineChart !== 'undefined' && typeof month !== 'undefined' && typeof reportURL === 'undefined') {
// lineChart('/chart/account/month/' + year + '/' + month + shared, 'account-balances-chart');
//}
if (typeof lineChart !== 'undefined' && typeof accountIds !== 'undefined') {
- //http://firefly.app/chart/account/report/default;20151101;20151130;2
lineChart('/chart/account/report/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds, 'account-balances-chart');
}
}