Skip to content

Firefly III: a personal finances manager

Organized some category charts. Still needs some translating

James Cole7e1064146125
diff --git a/app/Generator/Chart/Category/CategoryChartGenerator.php b/app/Generator/Chart/Category/CategoryChartGenerator.php
index 3c2698c5b7..60f8c42f01 100644
--- a/app/Generator/Chart/Category/CategoryChartGenerator.php
+++ b/app/Generator/Chart/Category/CategoryChartGenerator.php
@@ -31,7 +31,7 @@ interface CategoryChartGenerator
*
* @return array
*/
- public function month(Collection $entries);
+ public function period(Collection $entries);
/**
diff --git a/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php b/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php
index c5ff681ca1..81db52d41b 100644
--- a/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php
+++ b/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php
@@ -17,17 +17,12 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
/**
* @param Collection $entries
- * @param string $dateFormat
*
* @return array
*/
- public function all(Collection $entries, $dateFormat = 'month')
+ public function all(Collection $entries)
{
- // language:
- //$language = Preferences::get('language', 'en')->data;
-
- //$format = Config::get('firefly.' . $dateFormat . '.' . $language);
$data = [
'count' => 2,
@@ -45,7 +40,7 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
];
foreach ($entries as $entry) {
- $data['labels'][] = $entry[1];//$entry[0]->formatLocalized($format);
+ $data['labels'][] = $entry[1];
$spent = round($entry[2], 2);
$earned = round($entry[3], 2);
@@ -90,9 +85,9 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
*
* @return array
*/
- public function month(Collection $entries)
+ public function period(Collection $entries)
{
- return $this->all($entries, 'monthAndDay');
+ return $this->all($entries);
}
diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php
index f5088208fa..0c9ae93f15 100644
--- a/app/Http/Controllers/CategoryController.php
+++ b/app/Http/Controllers/CategoryController.php
@@ -164,7 +164,7 @@ class CategoryController extends Controller
$journals = new LengthAwarePaginator($set, $count, 50, $page);
$journals->setPath('categories/show/' . $category->id . '/' . $date);
- return view('categories.show_with_date', compact('category', 'journals', 'hideCategory', 'subTitle','carbon'));
+ return view('categories.show_with_date', compact('category', 'journals', 'hideCategory', 'subTitle', 'carbon'));
}
/**
@@ -179,8 +179,6 @@ class CategoryController extends Controller
$page = intval(Input::get('page'));
$set = $repository->getJournals($category, $page);
$count = $repository->countJournals($category);
- $totalSum = $repository->journalsSum($category);
- $periodSum = $repository->journalsSum($category, Session::get('start'), Session::get('end'));
$subTitle = $category->name;
$journals = new LengthAwarePaginator($set, $count, 50, $page);
$journals->setPath('categories/show/' . $category->id);
@@ -221,7 +219,7 @@ class CategoryController extends Controller
$cache->store($entries);
}
- return view('categories.show', compact('category', 'journals', 'entries', 'hideCategory', 'totalSum', 'periodSum', 'subTitle'));
+ return view('categories.show', compact('category', 'journals', 'entries', 'hideCategory', 'subTitle'));
}
/**
diff --git a/app/Http/Controllers/Chart/CategoryController.php b/app/Http/Controllers/Chart/CategoryController.php
index efe4419f85..da90d9ee4e 100644
--- a/app/Http/Controllers/Chart/CategoryController.php
+++ b/app/Http/Controllers/Chart/CategoryController.php
@@ -132,7 +132,7 @@ class CategoryController extends Controller
*
* @return \Symfony\Component\HttpFoundation\Response
*/
- public function month(CategoryRepositoryInterface $repository, Category $category)
+ public function currentPeriod(CategoryRepositoryInterface $repository, Category $category)
{
$start = clone Session::get('start', Carbon::now()->startOfMonth());
$end = Session::get('end', Carbon::now()->endOfMonth());
@@ -143,7 +143,7 @@ class CategoryController extends Controller
$cache->addProperty($end);
$cache->addProperty($category->id);
$cache->addProperty('category');
- $cache->addProperty('month');
+ $cache->addProperty('currentPeriod');
if ($cache->has()) {
return Response::json($cache->get()); // @codeCoverageIgnore
}
@@ -153,12 +153,55 @@ class CategoryController extends Controller
while ($start <= $end) {
$spent = $repository->spentOnDaySumCorrected($category, $start);
$earned = $repository->earnedOnDaySumCorrected($category, $start);
- $date = Navigation::periodShow($start, '1D');
+ $date = Navigation::periodShow($start, '1D');
$entries->push([clone $start, $date, $spent, $earned]);
$start->addDay();
}
- $data = $this->generator->month($entries);
+ $data = $this->generator->period($entries);
+ $cache->store($data);
+
+ return Response::json($data);
+
+
+ }
+
+ /**
+ * @param CategoryRepositoryInterface $repository
+ * @param Category $category
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ */
+ public function specificPeriod(CategoryRepositoryInterface $repository, Category $category, $date)
+ {
+ $carbon = new Carbon($date);
+ $range = Preferences::get('viewRange', '1M')->data;
+ $start = Navigation::startOfPeriod($carbon, $range);
+ $end = Navigation::endOfPeriod($carbon, $range);
+
+ // chart properties for cache:
+ $cache = new CacheProperties;
+ $cache->addProperty($start);
+ $cache->addProperty($end);
+ $cache->addProperty($category->id);
+ $cache->addProperty('category');
+ $cache->addProperty('specificPeriod');
+ $cache->addProperty($date);
+ if ($cache->has()) {
+ return Response::json($cache->get()); // @codeCoverageIgnore
+ }
+ $entries = new Collection;
+
+
+ while ($start <= $end) {
+ $spent = $repository->spentOnDaySumCorrected($category, $start);
+ $earned = $repository->earnedOnDaySumCorrected($category, $start);
+ $theDate = Navigation::periodShow($start, '1D');
+ $entries->push([clone $start, $theDate, $spent, $earned]);
+ $start->addDay();
+ }
+
+ $data = $this->generator->period($entries);
$cache->store($data);
return Response::json($data);
diff --git a/app/Http/routes.php b/app/Http/routes.php
index cd1a57bd18..8032412afd 100644
--- a/app/Http/routes.php
+++ b/app/Http/routes.php
@@ -303,12 +303,13 @@ Route::group(
// 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']
+['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']
);
- Route::get('/chart/category/{category}/month', ['uses' => 'Chart\CategoryController@month']); // should be period.
+ 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']);
// piggy banks:
diff --git a/app/Models/TransactionJournal.php b/app/Models/TransactionJournal.php
index 3248980fb3..52e026805c 100644
--- a/app/Models/TransactionJournal.php
+++ b/app/Models/TransactionJournal.php
@@ -254,6 +254,7 @@ class TransactionJournal extends Model
return $amount;
}
+
/**
* @codeCoverageIgnore
* @return \Illuminate\Database\Eloquent\Relations\HasMany
diff --git a/public/js/categories.js b/public/js/categories.js
index c39e840354..8bf673924b 100644
--- a/public/js/categories.js
+++ b/public/js/categories.js
@@ -1,11 +1,19 @@
-/* globals $, categoryID, columnChart */
+/* globals $, categoryID, columnChart, categoryDate */
$(function () {
"use strict";
if (typeof categoryID !== 'undefined') {
- columnChart('chart/category/' + categoryID + '/all', 'all');
- columnChart('chart/category/' + categoryID + '/month', 'month');
- }
+ // more splits:
+ if ($('#all').length > 0) {
+ columnChart('chart/category/' + categoryID + '/all', 'all');
+ }
+ if ($('#period').length > 0) {
+ columnChart('chart/category/' + categoryID + '/period', 'period');
+ }
+ }
+ if (typeof categoryID !== 'undefined' && typeof categoryDate !== undefined) {
+ columnChart('chart/category/' + categoryID + '/period/' + categoryDate, 'period-specific-period');
+ }
});
\ No newline at end of file
diff --git a/resources/twig/categories/show.twig b/resources/twig/categories/show.twig
index ca4f09bfe8..91e8cec723 100644
--- a/resources/twig/categories/show.twig
+++ b/resources/twig/categories/show.twig
@@ -13,10 +13,10 @@
</div>
<div class="box-body">
{% if Config.get('firefly.chart') == 'google' %}
- <div id="month"></div>
+ <div id="period"></div>
{% endif %}
{% if Config.get('firefly.chart') == 'chartjs' %}
- <canvas id="month" style="width:100%;height:350px;"></canvas>
+ <canvas id="period" style="width:100%;height:350px;"></canvas>
{% endif %}
</div>
</div>
@@ -45,7 +45,7 @@
<h3 class="box-title">{{ 'transactions'|_ }}</h3>
</div>
<div class="box-body no-padding">
- {% include 'list/journals' with {showPageSum: true, showTotalSum: true, showPeriodSum: true} %}
+ {% include 'list/journals' %}
</div>
</div>
</div>
diff --git a/resources/twig/categories/show_with_date.twig b/resources/twig/categories/show_with_date.twig
index 0d136db2e2..62b861b8f1 100644
--- a/resources/twig/categories/show_with_date.twig
+++ b/resources/twig/categories/show_with_date.twig
@@ -7,32 +7,17 @@
{% block content %}
<div class="row">
- <div class="col-lg-6 col-md-6 col-sm-12">
+ <div class="col-lg-12 col-md-12 col-sm-12">
<div class="box">
<div class="box-header with-border">
- <h3 class="box-title">{{ 'overview'|_ }} (month)</h3>
+ <h3 class="box-title">{{ 'overview'|_ }} (period)</h3>
</div>
<div class="box-body">
{% if Config.get('firefly.chart') == 'google' %}
- <div id="month"></div>
+ <div id="period-specific-period"></div>
{% endif %}
{% if Config.get('firefly.chart') == 'chartjs' %}
- <canvas id="month" style="width:100%;height:350px;"></canvas>
- {% endif %}
- </div>
- </div>
- </div>
- <div class="col-lg-6 col-md-6 col-sm-12">
- <div class="box">
- <div class="box-header with-border">
- <h3 class="box-title">{{ 'overview'|_ }} (all)</h3>
- </div>
- <div class="box-body">
- {% if Config.get('firefly.chart') == 'google' %}
- <div id="all"></div>
- {% endif %}
- {% if Config.get('firefly.chart') == 'chartjs' %}
- <canvas id="all" style="width:100%;height:350px;"></canvas>
+ <canvas id="period-specific-period" style="width:100%;height:350px;"></canvas>
{% endif %}
</div>
</div>
@@ -61,6 +46,7 @@
{% block scripts %}
<script type="text/javascript">
var categoryID = {{ category.id }};
+ var categoryDate = "{{ carbon.format('Y-m-d') }}";
</script>
<!-- load the libraries and scripts necessary for Google Charts: -->
{% if Config.get('firefly.chart') == 'google' %}