diff --git a/app/Http/Controllers/Report/BalanceController.php b/app/Http/Controllers/Report/BalanceController.php new file mode 100644 index 0000000000..74c1d393fb --- /dev/null +++ b/app/Http/Controllers/Report/BalanceController.php @@ -0,0 +1,60 @@ +addProperty($start); + $cache->addProperty($end); + $cache->addProperty('balance-report'); + $cache->addProperty($accounts->pluck('id')->toArray()); + if ($cache->has()) { + return $cache->get(); + } + + $balance = $helper->getBalanceReport($start, $end, $accounts); + + $result = view('reports.partials.balance', compact('balance'))->render(); + $cache->store($result); + + return $result; + } +} \ No newline at end of file diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index 352713e7fa..3bdeaf7f44 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -15,7 +15,6 @@ namespace FireflyIII\Http\Controllers; use Carbon\Carbon; use FireflyIII\Exceptions\FireflyException; -use FireflyIII\Helpers\Report\BalanceReportHelperInterface; use FireflyIII\Helpers\Report\BudgetReportHelperInterface; use FireflyIII\Helpers\Report\ReportHelperInterface; use FireflyIII\Models\Account; @@ -38,10 +37,6 @@ use View; */ class ReportController extends Controller { - - /** @var BalanceReportHelperInterface */ - protected $balanceHelper; - /** @var BudgetReportHelperInterface */ protected $budgetHelper; /** @var ReportHelperInterface */ @@ -210,9 +205,8 @@ class ReportController extends Controller */ private function createRepositories() { - $this->helper = app(ReportHelperInterface::class); - $this->budgetHelper = app(BudgetReportHelperInterface::class); - $this->balanceHelper = app(BalanceReportHelperInterface::class); + $this->helper = app(ReportHelperInterface::class); + $this->budgetHelper = app(BudgetReportHelperInterface::class); } /** @@ -226,10 +220,9 @@ class ReportController extends Controller private function defaultMonth(string $reportType, Carbon $start, Carbon $end, Collection $accounts) { // get report stuff! - $budgets = $this->budgetHelper->getBudgetReport($start, $end, $accounts); - $balance = $this->balanceHelper->getBalanceReport($start, $end, $accounts); - $bills = $this->helper->getBillReport($start, $end, $accounts); - $tags = $this->helper->tagReport($start, $end, $accounts); + $budgets = $this->budgetHelper->getBudgetReport($start, $end, $accounts); + $bills = $this->helper->getBillReport($start, $end, $accounts); + $tags = $this->helper->tagReport($start, $end, $accounts); // and some id's, joined: $accountIds = join(',', $accounts->pluck('id')->toArray()); @@ -238,10 +231,9 @@ class ReportController extends Controller return view( 'reports.default.month', compact( - 'start', 'end', 'reportType', + 'start', 'end', 'tags', - 'incomes', - 'budgets', 'balance', + 'budgets', 'bills', 'accountIds', 'reportType' ) @@ -289,8 +281,8 @@ class ReportController extends Controller */ private function defaultYear(string $reportType, Carbon $start, Carbon $end, Collection $accounts) { - $tags = $this->helper->tagReport($start, $end, $accounts); - $budgets = $this->budgetHelper->budgetYearOverview($start, $end, $accounts); + $tags = $this->helper->tagReport($start, $end, $accounts); + $budgets = $this->budgetHelper->budgetYearOverview($start, $end, $accounts); Session::flash('gaEventCategory', 'report'); Session::flash('gaEventAction', 'year'); diff --git a/public/js/ff/reports/default/month.js b/public/js/ff/reports/default/month.js index 8f5be8a671..d9f30b1f8c 100644 --- a/public/js/ff/reports/default/month.js +++ b/public/js/ff/reports/default/month.js @@ -1,4 +1,4 @@ -/* globals google, startDate ,reportURL, endDate , reportType ,accountIds, lineChart, categoryReportUrl */ +/* globals google, startDate ,reportURL, endDate , reportType ,accountIds, lineChart, categoryReportUrl, balanceReportUrl */ $(function () { @@ -6,6 +6,7 @@ $(function () { drawChart(); loadCategoryReport(); + loadBalanceReport(); }); function loadCategoryReport() { @@ -14,6 +15,19 @@ function loadCategoryReport() { $.get(categoryReportUrl).done(placeCategoryReport).fail(failCategoryReport); } +function loadBalanceReport() { + "use strict"; + console.log('Going to grab ' + categoryReportUrl); + $.get(balanceReportUrl).done(placeBalanceReport).fail(failBalanceReport); +} + +function placeBalanceReport(data) { + "use strict"; + $('#balanceReport').removeClass('loading').html(data); + listLengthInitial(); + triggerInfoClick(); +} + function placeCategoryReport(data) { "use strict"; $('#categoryReport').removeClass('loading').html(data); @@ -21,6 +35,12 @@ function placeCategoryReport(data) { triggerInfoClick(); } +function failBalanceReport() { + "use strict"; + console.log('Fail balance report data!'); + $('#balanceReport').removeClass('loading').addClass('general-chart-error'); +} + function failCategoryReport() { "use strict"; console.log('Fail category report data!'); diff --git a/resources/views/reports/default/month.twig b/resources/views/reports/default/month.twig index 19fdea02c3..6e27d82518 100644 --- a/resources/views/reports/default/month.twig +++ b/resources/views/reports/default/month.twig @@ -87,7 +87,14 @@
- {% include 'reports/partials/balance.twig' %} +
+
+

{{ 'budgets'|_ }} ({{ 'splitByAccount'|_|lower }})

+
+
+
+
+
@@ -119,6 +126,7 @@ var accountReportUrl = '{{ route('reports.data.accountReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}'; var inOutReportUrl = '{{ route('reports.data.inOutReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}'; var categoryReportUrl = '{{ route('reports.data.categoryReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}'; + var balanceReportUrl = '{{ route('reports.data.balanceReport', [start.format('Ymd'), end.format('Ymd'), accountIds]) }}'; diff --git a/resources/views/reports/partials/balance.twig b/resources/views/reports/partials/balance.twig index 2ccf769746..b88029ac69 100644 --- a/resources/views/reports/partials/balance.twig +++ b/resources/views/reports/partials/balance.twig @@ -1,70 +1,62 @@ -
-
-

{{ 'budgets'|_ }} ({{ 'splitByAccount'|_|lower }})

-
-
- - - - - - {% for account in balance.getBalanceHeader.getAccounts %} - - {% endfor %} - - - - +
{{ 'budgets'|_ }}{{ account.name }} - {{ 'leftInBudget'|_ }} -
+ + + + + {% for account in balance.getBalanceHeader.getAccounts %} + + {% endfor %} + + + + - - {% for balanceLine in balance.getBalanceLines %} - + + {% for balanceLine in balance.getBalanceLines %} + - {% if balanceLine.getBudget.id %} - - - {% else %} - {% endif %} + + + {% else %} + + {% endif %} - {% for balanceEntry in balanceLine.getBalanceEntries %} - - {% endfor %} - - + {% endif %} + {% if balanceEntry.getLeft != 0 %} + {{ (balanceEntry.getLeft)|formatAmountPlain }} + {% endif %} + {% endfor %} - -
{{ 'budgets'|_ }}{{ account.name }} + {{ 'leftInBudget'|_ }} +
- {{ balanceLine.getTitle }} - {% if balanceLine.getStartdate and balanceLine.getEnddate %} -
- {{ balanceLine.getStartdate.formatLocalized(monthAndDayFormat) }} - — - {{ balanceLine.getEnddate.formatLocalized(monthAndDayFormat) }} + {% if balanceLine.getBudget.id %} +
+ {{ balanceLine.getTitle }} + {% if balanceLine.getStartdate and balanceLine.getEnddate %} +
+ {{ balanceLine.getStartdate.formatLocalized(monthAndDayFormat) }} + — + {{ balanceLine.getEnddate.formatLocalized(monthAndDayFormat) }}
- {% endif %} -
- {% if(balanceLine.getBudget.amount) %} - {{ balanceLine.getBudget.amount|formatAmount }} - {% else %} - {{ '0'|formatAmount }} - {% endif %} - {{ balanceLine.getTitle }} + {% if(balanceLine.getBudget.amount) %} + {{ balanceLine.getBudget.amount|formatAmount }} + {% else %} + {{ '0'|formatAmount }} + {% endif %} + {{ balanceLine.getTitle }} - {% if balanceEntry.getSpent != 0 %} - {{ (balanceEntry.getSpent)|formatAmountPlain }} - + {% for balanceEntry in balanceLine.getBalanceEntries %} + + {% if balanceEntry.getSpent != 0 %} + {{ (balanceEntry.getSpent)|formatAmountPlain }} + - {% endif %} - {% if balanceEntry.getLeft != 0 %} - {{ (balanceEntry.getLeft)|formatAmountPlain }} - {% endif %} - - {{ balanceLine.leftOfRepetition|formatAmount }} -
-
- -
+ + {{ balanceLine.leftOfRepetition|formatAmount }} + + + {% endfor %} + + diff --git a/routes/web.php b/routes/web.php index dd4bd057f1..e53e81ccde 100755 --- a/routes/web.php +++ b/routes/web.php @@ -335,6 +335,12 @@ Route::group( ['uses' => 'Report\CategoryController@categoryReport', 'as' => 'reports.data.categoryReport'] ); + // balance report: + Route::get( + '/reports/data/balance-report/{start_date}/{end_date}/{accountList}', + ['uses' => 'Report\BalanceController@balanceReport', 'as' => 'reports.data.balanceReport'] + ); + /** * Rules Controller */