diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php index 800caca03b..05dff96994 100644 --- a/app/Helpers/Report/ReportHelper.php +++ b/app/Helpers/Report/ReportHelper.php @@ -19,6 +19,7 @@ use FireflyIII\Models\Account; use FireflyIII\Models\Bill; use FireflyIII\Models\Budget as BudgetModel; use FireflyIII\Models\LimitRepetition; +use Illuminate\Support\Collection; /** * Class ReportHelper @@ -59,11 +60,6 @@ class ReportHelper implements ReportHelperInterface $accounts = $this->query->getAllAccounts($date, $end, $shared); - $start = '0'; - $end = '0'; - $diff = '0'; - bcscale(2); - // remove cash account, if any: $accounts = $accounts->filter( function (Account $account) { @@ -74,21 +70,7 @@ class ReportHelper implements ReportHelperInterface return null; } ); - - // summarize: - foreach ($accounts as $account) { - $start = bcadd($start, $account->startBalance); - $end = bcadd($end, $account->endBalance); - $diff = bcadd($diff, bcsub($account->endBalance, $account->startBalance)); - } - - $object = new AccountCollection; - $object->setStart($start); - $object->setEnd($end); - $object->setDifference($diff); - $object->setAccounts($accounts); - - return $object; + return $this->getAccountReportForList($date, $end, $accounts); } /** @@ -418,4 +400,37 @@ class ReportHelper implements ReportHelperInterface return $months; } + + /** + * This method generates a full report for the given period on all + * given accounts + * + * @param Carbon $date + * @param Carbon $end + * @param Collection $accounts + * + * @return AccountCollection + */ + public function getAccountReportForList(Carbon $date, Carbon $end, Collection $accounts) + { + $start = '0'; + $end = '0'; + $diff = '0'; + bcscale(2); + + // summarize: + foreach ($accounts as $account) { + $start = bcadd($start, $account->startBalance); + $end = bcadd($end, $account->endBalance); + $diff = bcadd($diff, bcsub($account->endBalance, $account->startBalance)); + } + + $object = new AccountCollection; + $object->setStart($start); + $object->setEnd($end); + $object->setDifference($diff); + $object->setAccounts($accounts); + + return $object; + } } diff --git a/app/Helpers/Report/ReportHelperInterface.php b/app/Helpers/Report/ReportHelperInterface.php index 91f9c8d0f5..6194093236 100644 --- a/app/Helpers/Report/ReportHelperInterface.php +++ b/app/Helpers/Report/ReportHelperInterface.php @@ -10,6 +10,7 @@ use FireflyIII\Helpers\Collection\Budget as BudgetCollection; use FireflyIII\Helpers\Collection\Category as CategoryCollection; use FireflyIII\Helpers\Collection\Expense; use FireflyIII\Helpers\Collection\Income; +use Illuminate\Support\Collection; /** * Interface ReportHelperInterface @@ -31,6 +32,18 @@ interface ReportHelperInterface */ public function getAccountReport(Carbon $date, Carbon $end, $shared); + /** + * This method generates a full report for the given period on all + * given accounts + * + * @param Carbon $date + * @param Carbon $end + * @param Collection $accounts + * + * @return AccountCollection + */ + public function getAccountReportForList(Carbon $date, Carbon $end, Collection $accounts); + /** * This method generates a full report for the given period on all * the users bills and their payments. diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index af025677ca..a89efd2dd5 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -1,10 +1,14 @@ id); + abort(404); + } + if ($end < $start) { + abort(404); + } + + // accounts: + $c = count($parts); + $list = new Collection(); + for ($i = 3; $i < $c; $i++) { + $account = $repository->find($parts[$i]); + if ($account) { + $list->push($account); + } + } + + // some fields: + $subTitle = trans('firefly.reportForMonth', ['month' => $start->formatLocalized($this->monthFormat)]); + $subTitleIcon = 'fa-calendar'; + $incomeTopLength = 8; + $expenseTopLength = 8; + + // get report stuff! + $accounts = $this->helper->getAccountReportForList($start, $end, $list); +// $incomes = $this->helper->getIncomeReportForList($start, $end, $list); +// $expenses = $this->helper->getExpenseReportForList($start, $end, $list); +// $budgets = $this->helper->getBudgetReportForList($start, $end, $list); +// $categories = $this->helper->getCategoryReportForList($start, $end, $list); +// $balance = $this->helper->getBalanceReportForList($start, $end, $list); +// $bills = $this->helper->getBillReportForList($start, $end); + + // continue! + return view( + 'reports.default', + compact( + 'start', + 'subTitle', 'subTitleIcon', + 'accounts', + 'incomes', 'incomeTopLength', + 'expenses', 'expenseTopLength', + 'budgets', 'balance', + 'categories', + 'bills' + ) + ); + + } + } diff --git a/resources/twig/reports/default.twig b/resources/twig/reports/default.twig new file mode 100644 index 0000000000..0b9111669b --- /dev/null +++ b/resources/twig/reports/default.twig @@ -0,0 +1,100 @@ +{% extends "./layout/default.twig" %} + +{% block breadcrumbs %} + {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, start, shared) }} +{% endblock %} + +{% block content %} + +
+
+
+
+

{{ 'accountBalances'|_ }}

+
+
+ {% if Config.get('firefly.chart') == 'google' %} +
+ {% endif %} + {% if Config.get('firefly.chart') == 'chartjs' %} + + {% endif %} +
+
+
+
+ +
+
+ {% include 'partials/reports/accounts.twig' %} + {% include 'partials/reports/income-vs-expenses.twig' %} +
+
+ + {% include 'partials/reports/income.twig' %} +
+
+ + {% include 'partials/reports/expenses.twig' %} +
+
+
+
+ + {% include 'partials/reports/budgets.twig' %} +
+
+ + {% include 'partials/reports/categories.twig' %} +
+
+
+
+ +
+
+
+
+ {% include 'partials/reports/balance.twig' %} +
+
+
+
+ {% include 'partials/reports/bills.twig' %} + +
+
+{% endblock %} +{% block styles %} + +{% endblock %} +{% block scripts %} + + + + + {% if Config.get('firefly.chart') == 'google' %} + + + {% endif %} + {% if Config.get('firefly.chart') == 'chartjs' %} + + + {% endif %} + + + +{% endblock %}