diff --git a/app/Helpers/Report/ReportQuery.php b/app/Helpers/Report/ReportQuery.php index 5a2acda6a5..57ae219053 100644 --- a/app/Helpers/Report/ReportQuery.php +++ b/app/Helpers/Report/ReportQuery.php @@ -227,6 +227,7 @@ class ReportQuery implements ReportQueryInterface $object->name = intval($object->account_encrypted) == 1 ? Crypt::decrypt($object->name) : $object->name; } ); + $data->sortByDesc('queryAmount'); return $data; } diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index b16b177c4c..f13dfcfaa6 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -30,6 +30,7 @@ class ReportController extends Controller */ public function __construct(ReportHelperInterface $helper, ReportQueryInterface $query) { + parent::__construct(); $this->query = $query; $this->helper = $helper; @@ -246,7 +247,7 @@ class ReportController extends Controller return view( 'reports.month', compact( - 'income', 'expenses', 'budgets', 'accounts', 'categories','shared', + 'income', 'expenses', 'budgets', 'accounts', 'categories', 'shared', 'date', 'subTitle', 'displaySum', 'subTitleIcon' ) ); @@ -259,25 +260,76 @@ class ReportController extends Controller */ public function year($year, $shared = false) { - - $subTitle = trans('firefly.reportForYear',['year' => $year]); + $date = new Carbon('01-01-' . $year); + $end = clone $date; + $subTitle = trans('firefly.reportForYear', ['year' => $year]); + $subTitleIcon = 'fa-bar-chart'; + $totalExpense = 0; + $totalIncome = 0; if ($shared == 'shared') { - $shared = true; - $subTitle = trans('firefly.reportForYearShared',['year' => $year]); + $shared = true; + $subTitle = trans('firefly.reportForYearShared', ['year' => $year]); } - $date = new Carbon('01-01-' . $year); - $end = clone $date; $end->endOfYear(); - $subTitleIcon = 'fa-bar-chart'; - $mainTitleIcon = 'fa-line-chart'; - $balances = $this->helper->yearBalanceReport($date, $shared); - $groupedIncomes = $this->query->journalsByRevenueAccount($date, $end, $shared); - $groupedExpenses = $this->query->journalsByExpenseAccount($date, $end, $shared); + /** + * ALL ACCOUNTS + * Summarized as well. + */ + $accounts = $this->query->getAllAccounts($date, $end, $shared); + $accountsSums = ['start' => 0, 'end' => 0, 'diff' => 0]; + // summarize: + foreach ($accounts as $account) { + $accountsSums['start'] += $account->startBalance; + $accountsSums['end'] += $account->endBalance; + $accountsSums['diff'] += ($account->endBalance - $account->startBalance); + } + + + /** + * ALL INCOMES. + * Grouped, sorted and summarized. + */ + $set = $this->query->incomeInPeriod($date, $end, $shared); + // group, sort and sum: + $incomes = []; + foreach ($set as $entry) { + $id = $entry->account_id; + $totalIncome += floatval($entry->queryAmount); + if (isset($incomes[$id])) { + $incomes[$id]['amount'] += floatval($entry->queryAmount); + $incomes[$id]['count']++; + } else { + $incomes[$id] = [ + 'amount' => floatval($entry->queryAmount), + 'name' => $entry->name, + 'count' => 1, + ]; + } + } + unset($set, $id); + + /** + * GET ALL EXPENSES + * Summarized. + */ + $expenses = $this->query->journalsByExpenseAccount($date, $end, $shared); + foreach ($expenses as $expense) { + $totalExpense += floatval($expense->queryAmount); + } return view( - 'reports.year', compact('date','shared', 'groupedIncomes', 'groupedExpenses', 'year', 'balances', 'subTitle', 'subTitleIcon', 'mainTitleIcon') + 'reports.year', + compact( + 'date', // the date for this report. + 'shared', // is a shared report? + 'totalExpense', 'totalIncome', // total income and expense. + 'accounts', // all accounts + 'accountsSums', // sums for all accounts + 'incomes', 'expenses', // expenses and incomes. + 'subTitle', 'subTitleIcon' // subtitle and subtitle icon. + ) ); } diff --git a/resources/lang/en/firefly.php b/resources/lang/en/firefly.php index 3038d0ae97..d100346cca 100644 --- a/resources/lang/en/firefly.php +++ b/resources/lang/en/firefly.php @@ -88,6 +88,13 @@ return [ 'reportForYear' => 'Yearly report for :year', 'reportForYearShared' => 'Yearly report for :year (including shared accounts)', + 'incomeVsExpenses' => 'Income vs. expenses', + 'accountBalances' => 'Account balances', + 'balanceStartOfYear' => 'Balance at start of year', + 'balanceEndOfYear' => 'Balance at end of year', + 'difference' => 'Difference', + 'in' => 'In', + 'out' => 'Out', // charts: 'dayOfMonth' => 'Day of the month', diff --git a/resources/lang/nl/firefly.php b/resources/lang/nl/firefly.php index b7dacd5c82..c743d00d1a 100644 --- a/resources/lang/nl/firefly.php +++ b/resources/lang/nl/firefly.php @@ -88,6 +88,13 @@ return [ 'reportForYear' => 'Jaaroverzicht :year', 'reportForYearShared' => 'Jaaroverzicht :year (inclusief gedeelde rekeningen)', + 'incomeVsExpenses' => 'Inkomsten tegenover uitgaven', + 'accountBalances' => 'Rekeningsaldi', + 'balanceStartOfYear' => 'Saldo aan het begin van het jaar', + 'balanceEndOfYear' => 'Saldo aan het einde van het jaar', + 'difference' => 'Verschil', + 'in' => 'In', + 'out' => 'Uit', // charts: 'dayOfMonth' => 'Dag vd maand', diff --git a/resources/twig/reports/year.twig b/resources/twig/reports/year.twig index 149c62bc83..edf4514bfd 100644 --- a/resources/twig/reports/year.twig +++ b/resources/twig/reports/year.twig @@ -2,177 +2,163 @@ {% block content %} {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, date, shared) }} -
-
-
-
- - Income vs. expenses -
-
-
-
-
-
-
-
-
- - Income vs. expenses -
-
-
-
-
-
-
- -
-
-
-
- - Account balance +
+
+
+
+ + {{ 'incomeVsExpenses'|_ }} +
+
+
+
- - - - - - - - {% set start = 0 %} - {% set end = 0 %} - {% set diff = 0 %} - {% for balance in balances %} - {% set start = start + balance.start %} - {% set end = end + balance.end %} - {% set diff = diff + (balance.end - balance.start) %} - {% if not balance.hide %} + +
+
+
+ + {{ 'incomeVsExpenses'|_ }} +
+
+
+
+
+
+ + +
+
+
+
+ + {{ 'accountBalances'|_ }} +
+
NameBalance at start of yearBalance at end of yearDifference
+ + + + + + + {% for account in accounts %} - - - + + + - {% endif %} - {% endfor %} - - - - - - -
{{ 'name'|_ }}{{ 'balanceStartOfYear'|_ }}{{ 'balanceStartOfYear'|_ }}{{ 'difference'|_ }}
- {{ balance.account.name }} - {% if balance.shared %} - shared - {% endif %} + {{ account.name }} {{ balance.start|formatAmount }}{{ balance.end|formatAmount }}{{ (balance.end - balance.start)|formatAmount }}{{ account.startBalance|formatAmount }}{{ account.endBalance|formatAmount }}{{ (account.endBalance - account.startBalance)|formatAmount }}
Sum of sums{{ start|formatAmount }}{{ end|formatAmount }}{{ diff|formatAmount }}
-
- -
-
- - Income vs. expense + {% endfor %} + + Sum of sums + {{ accountsSums.start|formatAmount }} + {{ accountsSums.end|formatAmount }} + {{ accountsSums.diff|formatAmount }} + +
- {% set incomeSum = 0 %} - {% set expenseSum = 0 %} - {% for income in groupedIncomes %} - {% set incomeSum = incomeSum + (income.queryAmount*-1) %} - {% endfor %} - {% for expense in groupedExpenses %} - {% set expenseSum = expenseSum + expense.queryAmount %} - {% endfor %} +
+
+ + {{ 'incomeVsExpenses'|_ }} +
+ - - + + - - + + - - + +
In{{ incomeSum|formatAmount }}{{ 'in'|_ }}{{ totalIncome|formatAmount }}
Out{{ expenseSum|formatAmountPlain }}{{ 'out'|_ }}{{ totalExpense|formatAmountPlain }}
Difference{{ (incomeSum - expenseSum)|formatAmount }}{{ 'difference'|_ }}{{ (totalIncome - totalExpense)|formatAmount }}
-
-
-
-
-
- - Income
- - {% set sum = 0 %} - {% for income in groupedIncomes %} - {% set sum = sum + (income.queryAmount * -1) %} + +
+
+
+ + {{ 'income'|_ }} +
+
+ {% for id,row in incomes %} + + + + + {% endfor %} + - - + + - {% endfor %} - - - - -
+ {{ row.name }} + {% if row.count > 1 %} +
{{ row.count }} {{ 'transactions'|_|lower }} + {% endif %} +
{{ row.amount|formatAmount }}
{{ income.name }}{{ (income.queryAmount * -1)|formatAmount }}{{ 'sum'|_ }}{{ totalIncome|formatAmount }}
Sum{{ sum|formatAmount }}
-
-
-
-
-
- - Expenses +
- - {% set sum =0 %} - {% for expense in groupedExpenses %} - - - - - {% set sum = sum + (expense.queryAmount * -1) %} - {% endfor %} - - - - -
{{ expense.name }}{{ expense.queryAmount|formatAmountPlain }}
Sum{{ sum|formatAmount }}
-
-
-
-
-
-
- - Budgets -
-
-
+
+
+
+ + {{ 'expenses'|_ }} +
+ + {% set sum =0 %} + {% for expense in expenses %} + + + + + {% set sum = sum + (expense.queryAmount * -1) %} + {% endfor %} + + + + +
{{ expense.name }}{{ expense.queryAmount|formatAmountPlain }}
{{ 'sum'|_ }}{{ sum|formatAmount }}
+
+
+
+
+
+
+
+ + {{ 'budgets'|_ }} +
+
+
+
-
{% endblock %} {% block scripts %} - - - - + + + + - + - + {% endblock %}