From 2a87add74552fce9b97ddb6acc7cc30561aab542 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 10 Dec 2017 08:56:20 +0100 Subject: [PATCH] New stuff for report. --- .../Report/Account/MonthReportGenerator.php | 17 +- .../Account/MultiYearReportGenerator.php | 7 + .../Report/Account/YearReportGenerator.php | 7 + .../Controllers/Report/ExpenseController.php | 15 + public/js/ff/reports/account/all.js | 8 + public/js/ff/reports/account/month.js | 21 ++ resources/views/reports/account/report.twig | 320 +----------------- routes/web.php | 51 ++- 8 files changed, 127 insertions(+), 319 deletions(-) create mode 100644 app/Http/Controllers/Report/ExpenseController.php create mode 100644 public/js/ff/reports/account/all.js create mode 100644 public/js/ff/reports/account/month.js diff --git a/app/Generator/Report/Account/MonthReportGenerator.php b/app/Generator/Report/Account/MonthReportGenerator.php index 9e0e54a504..12d5e8dc15 100644 --- a/app/Generator/Report/Account/MonthReportGenerator.php +++ b/app/Generator/Report/Account/MonthReportGenerator.php @@ -47,13 +47,14 @@ class MonthReportGenerator implements ReportGeneratorInterface */ public function generate(): string { - $accountIds = join(',', $this->accounts->pluck('id')->toArray()); - $expenseIds = join(',', $this->expense->pluck('id')->toArray()); - $reportType = 'account'; + $accountIds = join(',', $this->accounts->pluck('id')->toArray()); + $expenseIds = join(',', $this->expense->pluck('id')->toArray()); + $reportType = 'account'; + $preferredPeriod = $this->preferredPeriod(); return view( 'reports.account.report', - compact('accountIds', 'reportType','expenseIds') + compact('accountIds', 'reportType', 'expenseIds', 'preferredPeriod') )->with('start', $this->start)->with('end', $this->end)->render(); } @@ -134,4 +135,12 @@ class MonthReportGenerator implements ReportGeneratorInterface { return $this; } + + /** + * @return string + */ + protected function preferredPeriod(): string + { + return 'day'; + } } diff --git a/app/Generator/Report/Account/MultiYearReportGenerator.php b/app/Generator/Report/Account/MultiYearReportGenerator.php index cd88b4ea75..16fd8e2767 100644 --- a/app/Generator/Report/Account/MultiYearReportGenerator.php +++ b/app/Generator/Report/Account/MultiYearReportGenerator.php @@ -28,4 +28,11 @@ namespace FireflyIII\Generator\Report\Account; class MultiYearReportGenerator extends MonthReportGenerator { // Doesn't do anything different. + + /** + * @return string + */ + protected function preferredPeriod(): string { + return 'year'; + } } diff --git a/app/Generator/Report/Account/YearReportGenerator.php b/app/Generator/Report/Account/YearReportGenerator.php index 3debf38d0c..cd4854710b 100644 --- a/app/Generator/Report/Account/YearReportGenerator.php +++ b/app/Generator/Report/Account/YearReportGenerator.php @@ -28,4 +28,11 @@ namespace FireflyIII\Generator\Report\Account; class YearReportGenerator extends MonthReportGenerator { // Doesn't do anything different. + + /** + * @return string + */ + protected function preferredPeriod(): string { + return 'month'; + } } diff --git a/app/Http/Controllers/Report/ExpenseController.php b/app/Http/Controllers/Report/ExpenseController.php new file mode 100644 index 0000000000..1c4d2372fb --- /dev/null +++ b/app/Http/Controllers/Report/ExpenseController.php @@ -0,0 +1,15 @@ + -
+
-

{{ 'in_out_accounts_period'|_ }}

+

{{ ('in_out_accounts_period_'~preferredPeriod)|_ }}

-
+
{# loading indicator #}
@@ -89,7 +89,7 @@

{{ 'expenses'|_ }} ({{ trans('firefly.topX', {number: listLength}) }})

-
+
{# loading indicator #}
@@ -112,297 +112,6 @@
- {# -
- {% if categories.count > 1 %} -
-
-
-

{{ 'income_per_category'|_ }}

-
-
- - -
-
-
-
-
-
-

{{ 'expense_per_category'|_ }}

-
-
- - -
-
-
- {% endif %} -
-
-
-

{{ 'income_per_account'|_ }}

-
-
- - -
-
-
-
-
-
-

{{ 'expense_per_account'|_ }}

-
-
- - -
-
-
-
- -
-
-
-
-

{{ 'income_and_expenses'|_ }}

-
-
- -
-
-
-
-
- {% if averageExpenses|length > 0 %} -
-
-
-

{{ 'average_spending_per_account'|_ }}

-
-
- - - - - - - - - - - {% for row in averageExpenses %} - {% if loop.index > listLength %} - - {% else %} - - {% endif %} - - - - - - {% endfor %} - - - {% if averageExpenses|length > listLength %} - - - - {% endif %} - -
{{ 'account'|_ }}{{ 'spent_average'|_ }}{{ 'total'|_ }}{{ 'transaction_count'|_ }}
- {{ row.name }} - - {{ row.average|formatAmount }} - - {{ row.sum|formatAmount }} - - {{ row.count }} -
- {{ trans('firefly.show_full_list',{number:incomeTopLength}) }} -
-
-
-
- {% endif %} - {% if topExpenses.count > 0 %} -
- -
-
-

{{ 'expenses'|_ }} ({{ trans('firefly.topX', {number: listLength}) }})

-
-
- - - - - - - - - - - {% for row in topExpenses %} - {% if loop.index > listLength %} - - {% else %} - - {% endif %} - - - - - - {% endfor %} - - - {% if topExpenses|length > listLength %} - - - - {% endif %} - -
{{ 'description'|_ }}{{ 'date'|_ }}{{ 'account'|_ }}{{ 'amount'|_ }}
- - {% if row.transaction_description|length > 0 %} - {{ row.transaction_description }} ({{ row.description }}) - {% else %} - {{ row.description }} - {% endif %} - - - {{ row.date.formatLocalized(monthAndDayFormat) }} - - - {{ row.opposing_account_name }} - - - {{ row.transaction_amount|formatAmount }} -
- {{ trans('firefly.show_full_list',{number:incomeTopLength}) }} -
-
-
-
- {% endif %} -
-
- {% if averageIncome|length > 0 %} -
-
-
-

{{ 'average_income_per_account'|_ }}

-
-
- - - - - - - - - - - {% for row in averageIncome %} - - - - - - - {% endfor %} - -
{{ 'account'|_ }}{{ 'income_average'|_ }}{{ 'total'|_ }}{{ 'transaction_count'|_ }}
- {{ row.name }} - - {{ row.average|formatAmount }} - - {{ row.sum|formatAmount }} - - {{ row.count }} -
-
-
-
- {% endif %} -
- {% if topIncome.count > 0 %} -
-
-

{{ 'income'|_ }} ({{ trans('firefly.topX', {number: listLength}) }})

-
-
- - - - - - - - - - - {% for row in topIncome %} - {% if loop.index > listLength %} - - {% else %} - - {% endif %} - - - - - - {% endfor %} - - - {% if topIncome.count > listLength %} - - - - {% endif %} - -
{{ 'description'|_ }}{{ 'date'|_ }}{{ 'account'|_ }}{{ 'amount'|_ }}
- - {% if row.transaction_description|length > 0 %} - {{ row.transaction_description }} ({{ row.description }}) - {% else %} - {{ row.description }} - {% endif %} - - - {{ row.date.formatLocalized(monthAndDayFormat) }} - - - {{ row.opposing_account_name }} - - - {{ row.transaction_amount|formatAmount }} -
- {{ trans('firefly.show_full_list',{number:incomeTopLength}) }} -
-
-
- {% endif %} -
-
- #} {% endblock %} @@ -417,19 +126,24 @@ var startDate = '{{ start.format('Ymd') }}'; var endDate = '{{ end.format('Ymd') }}'; var accountIds = '{{ accountIds }}'; - var categoryIds = '{{ categoryIds }}'; + var expenseIds = '{{ expenseIds }}'; // chart uri's - var categoryIncomeUri = '{{ route('chart.category.category-income', [accountIds, categoryIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}'; - var categoryExpenseUri = '{{ route('chart.category.category-expense', [accountIds, categoryIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}'; - var accountIncomeUri = '{{ route('chart.category.account-income', [accountIds, categoryIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}'; - var accountExpenseUri = '{{ route('chart.category.account-expense', [accountIds, categoryIds, start.format('Ymd'), end.format('Ymd'),'OTHERS']) }}'; - var mainUri = '{{ route('chart.category.main', [accountIds, categoryIds, start.format('Ymd'), end.format('Ymd')]) }}'; + var mainUri = '{{ route('chart.expense.main', [accountIds, expenseIds, start.format('Ymd'), end.format('Ymd')]) }}'; + + // boxes with stuff: + var spentUri = '{{ route('report-data.expense.spent', [accountIds, expenseIds, start.format('Ymd'), end.format('Ymd')]) }}'; + var groupedUri = '{{ route('report-data.expense.spent-grouped', [accountIds, expenseIds, start.format('Ymd'), end.format('Ymd')]) }}'; + var categoryUri = '{{ route('report-data.expense.category', [accountIds, expenseIds, start.format('Ymd'), end.format('Ymd')]) }}'; + var budgetUri = '{{ route('report-data.expense.budget', [accountIds, expenseIds, start.format('Ymd'), end.format('Ymd')]) }}'; + var expenseUri = '{{ route('report-data.expense.expenses', [accountIds, expenseIds, start.format('Ymd'), end.format('Ymd')]) }}'; + var incomeUri = '{{ route('report-data.expense.income', [accountIds, expenseIds, start.format('Ymd'), end.format('Ymd')]) }}'; + - - + + {% endblock %} diff --git a/routes/web.php b/routes/web.php index 099baa9b65..59ca359b92 100755 --- a/routes/web.php +++ b/routes/web.php @@ -1,14 +1,4 @@ 'Account\ReconcileController@reconcile', 'as' => 'reconcile']); - Route::get('reconcile/{account}/transactions/{start_date?}/{end_date?}', ['uses' => 'Account\ReconcileController@transactions', 'as' => 'reconcile.transactions']); + Route::get( + 'reconcile/{account}/transactions/{start_date?}/{end_date?}', ['uses' => 'Account\ReconcileController@transactions', 'as' => 'reconcile.transactions'] + ); Route::get('reconcile/{account}/overview/{start_date?}/{end_date?}', ['uses' => 'Account\ReconcileController@overview', 'as' => 'reconcile.overview']); Route::post('reconcile/{account}/submit/{start_date?}/{end_date?}', ['uses' => 'Account\ReconcileController@submit', 'as' => 'reconcile.submit']); @@ -224,7 +216,7 @@ Route::group( ); /** - * Chart\Account Controller + * Chart\Account Controller (default report) */ Route::group( ['middleware' => 'user-full-auth', 'namespace' => 'Chart', 'prefix' => 'chart/account', 'as' => 'chart.account.'], function () { @@ -246,6 +238,7 @@ Route::group( } ); + /** * Chart\Bill Controller */ @@ -374,6 +367,19 @@ Route::group( } ); +/** + * Chart\Expense Controller (for expense/revenue report). + */ +Route::group( + ['middleware' => 'user-full-auth', 'namespace' => 'Chart', 'prefix' => 'chart/expense', 'as' => 'chart.expense.'], function () { + Route::get( + 'operations/{accountList}/{expenseList}/{start_date}/{end_date}', + ['uses' => 'ExpenseReportController@mainChart', 'as' => 'main'] + ); +} +); + + /** * Chart\PiggyBank Controller */ @@ -582,6 +588,27 @@ Route::group( } ); +/** + * Report Data Expense / Revenue Account Controller + */ +Route::group( + ['middleware' => 'user-full-auth', 'namespace' => 'Report', 'prefix' => 'report-data/expense', 'as' => 'report-data.expense.'], function () { + + // spent per period / spent grouped + Route::get('spent/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@spent', 'as' => 'spent']); + Route::get('spent-grouped/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@spentGrouped', 'as' => 'spent-grouped']); + + // per category && per budget + Route::get('category/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@category', 'as' => 'category']); + Route::get('budget/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@budget', 'as' => 'budget']); + + //expense earned top X + Route::get('expenses/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@topX', 'as' => 'expenses']); + Route::get('income/{accountList}/{expenseList}/{start_date}/{end_date}', ['uses' => 'ExpenseController@topXPeriod', 'as' => 'income']); + +} +); + /** * Report Data Income/Expenses Controller (called financial operations) */