diff --git a/app/Helpers/Collection/Budget.php b/app/Helpers/Collection/Budget.php new file mode 100644 index 0000000000..3347302dcd --- /dev/null +++ b/app/Helpers/Collection/Budget.php @@ -0,0 +1,14 @@ + $start->formatLocalized($this->monthFormat)]); $subTitleIcon = 'fa-calendar'; $end = clone $start; - $totalExpense = 0; - $totalIncome = 0; $incomeTopLength = 8; $expenseTopLength = 8; if ($shared == 'shared') { @@ -159,152 +155,87 @@ class ReportController extends Controller $end->endOfMonth(); - // all accounts: - $accounts = $this->helper->getAccountReport($start, $end, $shared); + $accounts = $this->helper->getAccountReport($start, $end, $shared); + $incomes = $this->helper->getIncomeReport($start, $end, $shared); + $expenses = $this->helper->getExpenseReport($start, $end, $shared); + $budgets = $this->helper->getBudgetReport($start, $end, $shared); + $categories = $this->helper->getCategoryReport($start, $end, $shared); - /** - * ALL INCOMES. - * Grouped, sorted and summarized. - */ - $set = $this->query->incomeInPeriod($start, $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, - 'id' => $id, - ]; - } - } - // sort with callback: - uasort( - $incomes, function ($a, $b) { - if ($a['amount'] == $b['amount']) { - return 0; - } + // /** + // * DO BUDGETS. + // */ + // /** @var \FireflyIII\Repositories\Budget\BudgetRepositoryInterface $repository */ + // $repository = App::make('FireflyIII\Repositories\Budget\BudgetRepositoryInterface'); + // $set = $repository->getBudgets(); + // $budgets = new Collection; + // $budgetSums = ['budgeted' => 0, 'spent' => 0, 'left' => 0, 'overspent' => 0]; + // /** @var Budget $budget */ + // foreach ($set as $budget) { + // $repetitions = $repository->getBudgetLimitRepetitions($budget, $start, $end); + // if ($repetitions->count() == 0) { + // $exp = $repository->spentInPeriod($budget, $start, $end, $shared); + // $budgets->push([$budget, null, 0, 0, $exp]); + // $budgetSums['overspent'] += $exp; + // continue; + // } + // /** @var LimitRepetition $repetition */ + // foreach ($repetitions as $repetition) { + // $exp = $repository->spentInPeriod($budget, $repetition->startdate, $repetition->enddate, $shared); + // $left = $exp < floatval($repetition->amount) ? floatval($repetition->amount) - $exp : 0; + // $spent = $exp > floatval($repetition->amount) ? 0 : $exp; + // $overspent = $exp > floatval($repetition->amount) ? $exp - floatval($repetition->amount) : 0; + // + // $budgetSums['budgeted'] += floatval($repetition->amount); + // $budgetSums['spent'] += $spent; + // $budgetSums['left'] += $left; + // $budgetSums['overspent'] += $overspent; + // + // $budgets->push([$budget, $repetition, $left, $spent, $overspent]); + // } + // } + // + // $noBudgetExpenses = $repository->getWithoutBudgetSum($start, $end); + // $budgets->push([null, null, 0, 0, $noBudgetExpenses]); + // $budgetSums['overspent'] += $noBudgetExpenses; + // unset($noBudgetExpenses, $repository, $set, $repetition, $repetitions, $exp); - return ($a['amount'] < $b['amount']) ? 1 : -1; - } - ); - unset($set, $id); - - /** - * GET ALL EXPENSES - * Summarized. - */ - $set = $this->query->expenseInPeriod($start, $end, $shared); - // group, sort and sum: - $expenses = []; - foreach ($set as $entry) { - $id = $entry->account_id; - $totalExpense += floatval($entry->queryAmount); - if (isset($expenses[$id])) { - $expenses[$id]['amount'] += floatval($entry->queryAmount); - $expenses[$id]['count']++; - } else { - $expenses[$id] = [ - 'amount' => floatval($entry->queryAmount), - 'name' => $entry->name, - 'count' => 1, - 'id' => $id, - ]; - } - } - // sort with callback: - uasort( - $expenses, function ($a, $b) { - if ($a['amount'] == $b['amount']) { - return 0; - } - - return ($a['amount'] < $b['amount']) ? -1 : 1; - } - ); - unset($set, $id); - - /** - * DO BUDGETS. - */ - /** @var \FireflyIII\Repositories\Budget\BudgetRepositoryInterface $repository */ - $repository = App::make('FireflyIII\Repositories\Budget\BudgetRepositoryInterface'); - $set = $repository->getBudgets(); - $budgets = new Collection; - $budgetSums = ['budgeted' => 0, 'spent' => 0, 'left' => 0, 'overspent' => 0]; - /** @var Budget $budget */ - foreach ($set as $budget) { - $repetitions = $repository->getBudgetLimitRepetitions($budget, $start, $end); - if ($repetitions->count() == 0) { - $exp = $repository->spentInPeriod($budget, $start, $end, $shared); - $budgets->push([$budget, null, 0, 0, $exp]); - $budgetSums['overspent'] += $exp; - continue; - } - /** @var LimitRepetition $repetition */ - foreach ($repetitions as $repetition) { - $exp = $repository->spentInPeriod($budget, $repetition->startdate, $repetition->enddate, $shared); - $left = $exp < floatval($repetition->amount) ? floatval($repetition->amount) - $exp : 0; - $spent = $exp > floatval($repetition->amount) ? 0 : $exp; - $overspent = $exp > floatval($repetition->amount) ? $exp - floatval($repetition->amount) : 0; - - $budgetSums['budgeted'] += floatval($repetition->amount); - $budgetSums['spent'] += $spent; - $budgetSums['left'] += $left; - $budgetSums['overspent'] += $overspent; - - $budgets->push([$budget, $repetition, $left, $spent, $overspent]); - } - } - - $noBudgetExpenses = $repository->getWithoutBudgetSum($start, $end); - $budgets->push([null, null, 0, 0, $noBudgetExpenses]); - $budgetSums['overspent'] += $noBudgetExpenses; - unset($noBudgetExpenses, $repository, $set, $repetition, $repetitions, $exp); - - /** - * GET CATEGORIES: - */ - /** @var \FireflyIII\Repositories\Category\CategoryRepositoryInterface $repository */ - $repository = App::make('FireflyIII\Repositories\Category\CategoryRepositoryInterface'); - $set = $repository->getCategories(); - $categories = []; - $categorySum = 0; - foreach ($set as $category) { - $spent = $repository->spentInPeriod($category, $start, $end, $shared); - $categories[] = [$category, $spent]; - $categorySum += $spent; - } - // no category: - - // sort with callback: - uasort( - $categories, function ($a, $b) { - if ($a[1] == $b[1]) { - return 0; - } - - return ($a[1] < $b[1]) ? 1 : -1; - } - ); - unset($set, $repository, $spent); + // /** + // * GET CATEGORIES: + // */ + // /** @var \FireflyIII\Repositories\Category\CategoryRepositoryInterface $repository */ + // $repository = App::make('FireflyIII\Repositories\Category\CategoryRepositoryInterface'); + // $set = $repository->getCategories(); + // $categories = []; + // $categorySum = 0; + // foreach ($set as $category) { + // $spent = $repository->spentInPeriod($category, $start, $end, $shared); + // $categories[] = [$category, $spent]; + // $categorySum += $spent; + // } + // // no category: + // + // // sort with callback: + // uasort( + // $categories, function ($a, $b) { + // if ($a[1] == $b[1]) { + // return 0; + // } + // + // return ($a[1] < $b[1]) ? 1 : -1; + // } + // ); + // unset($set, $repository, $spent); return view( 'reports.month', compact( 'start', 'shared', 'subTitle', 'subTitleIcon', - 'accounts', 'accountsSums', - 'incomes', 'totalIncome', 'incomeTopLength', - 'expenses', 'totalExpense', 'expenseTopLength', - 'budgets', 'budgetSums', - 'categories', 'categorySum' + 'accounts', + 'incomes', 'incomeTopLength', + 'expenses', 'expenseTopLength', + 'budgets', + 'categories' ) ); diff --git a/resources/twig/partials/reports/accounts.twig b/resources/twig/partials/reports/accounts.twig new file mode 100644 index 0000000000..eb810fe051 --- /dev/null +++ b/resources/twig/partials/reports/accounts.twig @@ -0,0 +1,30 @@ +
+
+ + {{ 'accountBalances'|_ }} +
+ + + + + + + + {% for account in accounts.getAccounts %} + + + + + + + {% endfor %} + + + + + + +
{{ 'name'|_ }}{{ 'balanceStartOfYear'|_ }}{{ 'balanceStartOfYear'|_ }}{{ 'difference'|_ }}
+ {{ account.name }} + {{ account.startBalance|formatAmount }}{{ account.endBalance|formatAmount }}{{ (account.endBalance - account.startBalance)|formatAmount }}
Sum of sums{{ accounts.getStart|formatAmount }}{{ accounts.getEnd|formatAmount }}{{ accounts.getDifference|formatAmount }}
+
\ No newline at end of file diff --git a/resources/twig/partials/reports/expenses.twig b/resources/twig/partials/reports/expenses.twig new file mode 100644 index 0000000000..c4e588e731 --- /dev/null +++ b/resources/twig/partials/reports/expenses.twig @@ -0,0 +1,34 @@ +
+
+ + {{ 'expenses'|_ }} ({{ trans('firefly.topX',{number: expenseTopLength}) }}) +
+ + {% for expense in expenses.getExpenses %} + {% if loop.index > expenseTopLength %} + + {% else %} + + {% endif %} + + + + {% endfor %} + {% if expenses.getExpenses|length > expenseTopLength %} + + + + {% endif %} + + + + +
+ {{ expense.name }} + {% if expense.count > 1 %} +
{{ expense.count }} {{ 'transactions'|_|lower }} + {% endif %} +
{{ (expense.amount*-1)|formatAmountPlain }}
+ {{ trans('firefly.showTheRest',{number:incomeTopLength}) }} +
{{ 'sum'|_ }}{{ (expenses.getTotal * -1)|formatAmountPlain }}
+
\ No newline at end of file diff --git a/resources/twig/partials/reports/income-vs-expenses.twig b/resources/twig/partials/reports/income-vs-expenses.twig new file mode 100644 index 0000000000..5ef1e880a0 --- /dev/null +++ b/resources/twig/partials/reports/income-vs-expenses.twig @@ -0,0 +1,20 @@ +
+
+ + {{ 'incomeVsExpenses'|_ }} +
+ + + + + + + + + + + + + +
{{ 'in'|_ }}{{ incomes.getTotal|formatAmount }}
{{ 'out'|_ }}{{ expenses.getTotal|formatAmountPlain }}
{{ 'difference'|_ }}{{ (incomes.getTotal - expenses.getTotal)|formatAmount }}
+
\ No newline at end of file diff --git a/resources/twig/partials/reports/income.twig b/resources/twig/partials/reports/income.twig new file mode 100644 index 0000000000..145d487a05 --- /dev/null +++ b/resources/twig/partials/reports/income.twig @@ -0,0 +1,34 @@ +
+
+ + {{ 'income'|_ }} ({{ trans('firefly.topX',{number: incomeTopLength}) }}) +
+ + {% for income in incomes.getIncomes %} + {% if loop.index > incomeTopLength %} + + {% else %} + + {% endif %} + + + + {% endfor %} + {% if incomes.getIncomes|length > incomeTopLength %} + + + + {% endif %} + + + + +
+ {{ income.name }} + {% if income.count > 1 %} +
{{ income.count }} {{ 'transactions'|_|lower }} + {% endif %} +
{{ income.amount|formatAmount }}
+ {{ trans('firefly.showTheRest',{number:incomeTopLength}) }} +
{{ 'sum'|_ }}{{ incomes.getTotal|formatAmount }}
+
\ No newline at end of file diff --git a/resources/twig/reports/month.twig b/resources/twig/reports/month.twig index 16594a5a8b..6f39a41189 100644 --- a/resources/twig/reports/month.twig +++ b/resources/twig/reports/month.twig @@ -18,129 +18,16 @@
-
-
- - {{ 'accountBalances'|_ }} -
- - - - - - - - - {% for account in accounts %} - - - - - - - {% endfor %} -
{{ 'account'|_ }}{{ 'balanceStartOfMonth'|_ }}{{ 'balanceEndOfMonth'|_ }}{{ 'difference'|_ }}
{{ account.name }}{{ account.startBalance|formatAmount }}{{ account.endBalance|formatAmount }} - {{ (account.startBalance - account.endBalance)|formatAmount }} -
-
- - -
-
- - {{ 'incomeVsExpenses'|_ }} -
- - - - - - - - - - - - - -
{{ 'in'|_ }}{{ totalIncome|formatAmount }}
{{ 'out'|_ }}{{ (totalExpense * -1)|formatAmountPlain }}
{{ 'difference'|_ }}{{ (totalIncome + totalExpense)|formatAmount }}
-
+ {% include 'partials/reports/accounts.twig' %} + {% include 'partials/reports/income-vs-expenses.twig' %}
-
-
- - {{ 'income'|_ }} ({{ trans('firefly.topX',{number: incomeTopLength}) }}) -
- - {% for id,row in incomes %} - {% if loop.index > incomeTopLength %} - - {% else %} - - {% endif %} - - - - {% endfor %} - {% if incomes|length > incomeTopLength %} - - - - {% endif %} - - - - -
- {{ row.name }} - {% if row.count > 1 %} -
{{ row.count }} {{ 'transactions'|_|lower }} - {% endif %} -
{{ row.amount|formatAmount }}
- {{ trans('firefly.showTheRest',{number:incomeTopLength}) }} -
{{ 'sum'|_ }}{{ totalIncome|formatAmount }}
-
+ {% include 'partials/reports/income.twig' %}
-
-
- - {{ 'expenses'|_ }} ({{ trans('firefly.topX',{number: expenseTopLength}) }}) -
- - {% set sum =0 %} - {% for row in expenses %} - {% if loop.index > expenseTopLength %} - - {% else %} - - {% endif %} - - - - {% set sum = sum + row.amount %} - {% endfor %} - {% if expenses|length > expenseTopLength %} - - - - {% endif %} - - - - -
- {{ row.name }} - {% if row.count > 1 %} -
{{ row.count }} {{ 'transactions'|_|lower }} - {% endif %} -
{{ (row.amount*-1)|formatAmountPlain }}
- {{ trans('firefly.showTheRest',{number:incomeTopLength}) }} -
{{ 'sum'|_ }}{{ (sum * -1)|formatAmountPlain }}
-
+ {% include 'partials/reports/expenses.twig' %}
diff --git a/resources/twig/reports/year.twig b/resources/twig/reports/year.twig index faaabd1ae4..ed9bd1c78b 100644 --- a/resources/twig/reports/year.twig +++ b/resources/twig/reports/year.twig @@ -29,129 +29,15 @@
-
-
- - {{ 'accountBalances'|_ }} -
- - - - - - - - {% for account in accounts.getAccounts %} - - - - - - - {% endfor %} - - - - - - -
{{ 'name'|_ }}{{ 'balanceStartOfYear'|_ }}{{ 'balanceStartOfYear'|_ }}{{ 'difference'|_ }}
- {{ account.name }} - {{ account.startBalance|formatAmount }}{{ account.endBalance|formatAmount }}{{ (account.endBalance - account.startBalance)|formatAmount }}
Sum of sums{{ accounts.getStart|formatAmount }}{{ accounts.getEnd|formatAmount }}{{ accounts.getDifference|formatAmount }}
-
+ {% include 'partials/reports/accounts.twig' %} + {% include 'partials/reports/income-vs-expenses.twig' %} -
-
- - {{ 'incomeVsExpenses'|_ }} -
- - - - - - - - - - - - - -
{{ 'in'|_ }}{{ totalIncome|formatAmount }}
{{ 'out'|_ }}{{ totalExpense|formatAmountPlain }}
{{ 'difference'|_ }}{{ (totalIncome - totalExpense)|formatAmount }}
-
-
-
- - {{ 'income'|_ }} ({{ trans('firefly.topX',{number: incomeTopLength}) }}) -
- - {% for income in incomes.getIncomes %} - {% if loop.index > incomeTopLength %} - - {% else %} - - {% endif %} - - - - {% endfor %} - {% if incomes.getIncomes|length > incomeTopLength %} - - - - {% endif %} - - - - -
- {{ income.name }} - {% if income.count > 1 %} -
{{ income.count }} {{ 'transactions'|_|lower }} - {% endif %} -
{{ income.amount|formatAmount }}
- {{ trans('firefly.showTheRest',{number:incomeTopLength}) }} -
{{ 'sum'|_ }}{{ incomes.getTotal|formatAmount }}
-
+ {% include 'partials/reports/income.twig' %}
-
-
- - {{ 'expenses'|_ }} ({{ trans('firefly.topX',{number: expenseTopLength}) }}) -
- - {% for expense in expenses.getExpenses %} - {% if loop.index > expenseTopLength %} - - {% else %} - - {% endif %} - - - - {% endfor %} - {% if expenses.getExpenses|length > expenseTopLength %} - - - - {% endif %} - - - - -
- {{ expense.name }} - {% if expense.count > 1 %} -
{{ expense.count }} {{ 'transactions'|_|lower }} - {% endif %} -
{{ (expense.amount*-1)|formatAmountPlain }}
- {{ trans('firefly.showTheRest',{number:incomeTopLength}) }} -
{{ 'sum'|_ }}{{ (expenses.getTotal * -1)|formatAmountPlain }}
-
+ {% include 'partials/reports/expenses.twig' %}