Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
New chart called "net worth".
James Cole2e7c26c5393b
diff --git a/app/Generator/Chart/Report/ChartJsReportChartGenerator.php b/app/Generator/Chart/Report/ChartJsReportChartGenerator.phpindex 4a4f063d72..334621abca 100644--- a/app/Generator/Chart/Report/ChartJsReportChartGenerator.php+++ b/app/Generator/Chart/Report/ChartJsReportChartGenerator.php@@ -76,6 +76,32 @@ class ChartJsReportChartGenerator implements ReportChartGeneratorInterfacereturn $data;}+ /**+ * @param Collection $entries+ *+ * @return array+ */+ public function netWorth(Collection $entries) : array+ {+ $format = (string)trans('config.month_and_day');+ $data = [+ 'count' => 1,+ 'labels' => [],+ 'datasets' => [+ [+ 'label' => trans('firefly.net-worth'),+ 'data' => [],+ ],+ ],+ ];+ foreach ($entries as $entry) {+ $data['labels'][] = trim($entry['date']->formatLocalized($format));+ $data['datasets'][0]['data'][] = floatval($entry['net-worth']);+ }++ return $data;+ }+/*** @param Collection $entries*diff --git a/app/Generator/Chart/Report/ReportChartGeneratorInterface.php b/app/Generator/Chart/Report/ReportChartGeneratorInterface.phpindex 333bff112b..c1999137dc 100644--- a/app/Generator/Chart/Report/ReportChartGeneratorInterface.php+++ b/app/Generator/Chart/Report/ReportChartGeneratorInterface.php@@ -36,6 +36,13 @@ interface ReportChartGeneratorInterface*/public function multiYearInOutSummarized(string $income, string $expense, int $count): array;+ /**+ * @param Collection $entries+ *+ * @return array+ */+ public function netWorth(Collection $entries) : array;+/*** @param Collection $entries*diff --git a/app/Http/Controllers/Chart/ReportController.php b/app/Http/Controllers/Chart/ReportController.phpindex c80467674a..288bda6cb9 100644--- a/app/Http/Controllers/Chart/ReportController.php+++ b/app/Http/Controllers/Chart/ReportController.php@@ -10,6 +10,7 @@ use FireflyIII\Http\Controllers\Controller;use FireflyIII\Support\CacheProperties;use Illuminate\Support\Collection;use Response;+use Steam;/*** Class ReportController@@ -32,6 +33,53 @@ class ReportController extends Controller$this->generator = app('FireflyIII\Generator\Chart\Report\ReportChartGeneratorInterface');}+ /**+ * This chart, by default, is shown on the multi-year and year report pages,+ * which means that giving it a 2 week "period" should be enough granularity.+ *+ * @param ReportQueryInterface $query+ * @param string $reportType+ * @param Carbon $start+ * @param Carbon $end+ * @param Collection $accounts+ *+ * @return \Illuminate\Http\JsonResponse+ */+ public function netWorth(ReportQueryInterface $query, string $reportType, Carbon $start, Carbon $end, Collection $accounts)+ {+ bcscale(2);+ // chart properties for cache:+ $cache = new CacheProperties;+ $cache->addProperty('netWorth');+ $cache->addProperty($start);+ $cache->addProperty($reportType);+ $cache->addProperty($accounts);+ $cache->addProperty($end);+ if ($cache->has()) {+ return Response::json($cache->get()); // @codeCoverageIgnore+ }+ $ids = $accounts->pluck('id')->toArray();+ $current = clone $start;+ $entries = new Collection;+ while ($current < $end) {+ $balances = Steam::balancesById($ids, $current);+ $sum = $this->array_sum($balances);+ $entries->push(+ [+ 'date' => clone $current,+ 'net-worth' => $sum,+ ]+ );++ $current->addDays(7);+ }+ $data = $this->generator->netWorth($entries);++ //$cache->store($data);++ return Response::json($data);+ }+/*** Summarizes all income and expenses, per month, for a given year.@@ -250,4 +298,20 @@ class ReportController extends Controllerreturn $data;}++ /**+ * @param $array+ *+ * @return string+ */+ private function array_sum($array) : string+ {+ bcscale(2);+ $sum = '0';+ foreach ($array as $entry) {+ $sum = bcadd($sum, $entry);+ }++ return $sum;+ }}diff --git a/app/Http/routes.php b/app/Http/routes.phpindex c930d03514..7e66a5a452 100644--- a/app/Http/routes.php+++ b/app/Http/routes.php@@ -190,6 +190,7 @@ Route::group(// reports:Route::get('/chart/report/in-out/{reportType}/{start_date}/{end_date}/{accountList}', ['uses' => 'Chart\ReportController@yearInOut']);Route::get('/chart/report/in-out-sum/{reportType}/{start_date}/{end_date}/{accountList}', ['uses' => 'Chart\ReportController@yearInOutSummarized']);+ Route::get('/chart/report/net-worth/{reportType}/{start_date}/{end_date}/{accountList}', ['uses' => 'Chart\ReportController@netWorth']);/**diff --git a/app/Support/Steam.php b/app/Support/Steam.phpindex 1d523b1356..8debb4ac6b 100644--- a/app/Support/Steam.php+++ b/app/Support/Steam.php@@ -103,6 +103,7 @@ class Steam}/**+ * This method always ignores the virtual balance.** @param array $ids* @param \Carbon\Carbon $datediff --git a/public/js/charts.js b/public/js/charts.jsindex 5b3ce5fcc3..7ebd3a8685 100644--- a/public/js/charts.js+++ b/public/js/charts.js@@ -92,7 +92,7 @@ var defaultLineOptions = {datasetFill: false,scaleFontSize: 10,responsive: false,- scaleLabel: "<%= '" + currencySymbol + " ' + Number(value).toFixed(0).replace('.', ',') %>",+ scaleLabel: " <%= accounting.formatMoney(value) %>",tooltipFillColor: "rgba(0,0,0,0.5)",tooltipTemplate: "<%if (label){%><%=label%>: <%}%>" + currencySymbol + " <%= value %>",multiTooltipTemplate: "<%=datasetLabel%>: <%= '" + currencySymbol + " ' + Number(value).toFixed(2).replace('.', ',') %>"diff --git a/public/js/reports/default/multi-year.js b/public/js/reports/default/multi-year.jsindex 61931c1d78..984d0e4a72 100644--- a/public/js/reports/default/multi-year.js+++ b/public/js/reports/default/multi-year.js@@ -17,6 +17,7 @@ function drawChart() {"use strict";// income and expense over multi year:+ 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');diff --git a/public/js/reports/default/year.js b/public/js/reports/default/year.jsindex 12fbfe7e13..8a39be3ef3 100644--- a/public/js/reports/default/year.js+++ b/public/js/reports/default/year.js@@ -15,6 +15,7 @@ $(function () {function drawChart() {"use strict";+ 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');stackedColumnChart('chart/budget/year/' + reportType + '/' + startDate + '/' + endDate + '/' + accountIds, 'budgets');diff --git a/resources/views/reports/default/multi-year.twig b/resources/views/reports/default/multi-year.twigindex bb18c3abb4..c44eabd91c 100644--- a/resources/views/reports/default/multi-year.twig+++ b/resources/views/reports/default/multi-year.twig@@ -60,6 +60,19 @@</div>{% endfor %}+ <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">{{ 'net_worth'|_ }}</h3>+ </div>+ <div class="box-body">+ <canvas id="net-worth" style="width:100%;height:400px;"></canvas>+ </div>+ </div>+ </div>+ </div>+<div class="row"><div class="col-lg-12 col-md-12 col-sm-12"><div class="box">diff --git a/resources/views/reports/default/year.twig b/resources/views/reports/default/year.twigindex b54a71131d..c7551a3c56 100644--- a/resources/views/reports/default/year.twig+++ b/resources/views/reports/default/year.twig@@ -42,6 +42,20 @@{% include 'reports/partials/expenses.twig' %}</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">{{ 'net_worth'|_ }}</h3>+ </div>+ <div class="box-body">+ <canvas id="net-worth" style="width:100%;height:400px;"></canvas>+ </div>+ </div>+ </div>+ </div>+<div class="row"><div class="col-lg-12 col-md-12 col-sm-12"><div class="box">