diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php
index 9c82e2f7cc..6799c3f3a4 100644
--- a/app/Http/Controllers/ReportController.php
+++ b/app/Http/Controllers/ReportController.php
@@ -47,50 +47,51 @@ class ReportController extends Controller
*/
public function budget($year = '2014', $month = '1')
{
- try {
- new Carbon($year . '-' . $month . '-01');
- } catch (Exception $e) {
- return view('error')->with('message', 'Invalid date');
- }
- $date = new Carbon($year . '-' . $month . '-01');
- $start = clone $date;
+ $date = new Carbon($year . '-' . $month . '-01');
+ $subTitle = 'Budget report for ' . $date->format('F Y');
+ $subTitleIcon = 'fa-calendar';
+ $start = clone $date;
+
+
$start->startOfMonth();
$end = clone $date;
$end->endOfMonth();
- $start->subDay();
+ // should show shared reports?
/** @var Preference $pref */
$pref = Preferences::get('showSharedReports', false);
$showSharedReports = $pref->data;
+ $accountAmounts = []; // array with sums of spent amounts on each account.
+ $accounts = $this->query->getAllAccounts($start, $end, $showSharedReports); // all accounts and some data.
+ foreach ($accounts as $account) {
- $dayEarly = clone $date;
- $subTitle = 'Budget report for ' . $date->format('F Y');
- $subTitleIcon = 'fa-calendar';
- $dayEarly = $dayEarly->subDay();
- $accounts = $this->query->getAllAccounts($start, $end, $showSharedReports);
- $start->addDay();
+ $budgets = $this->query->getBudgetSummary($account, $start, $end);// get budget summary for this account:
+ $balancedAmount = $this->query->balancedTransactionsSum($account, $start, $end);
+ $accountAmounts[$account->id] = $balancedAmount;
+ // balance out the transactions (see transaction groups & tags) ^^
- $accounts->each(
- function (Account $account) use ($start, $end) {
- $budgets = $this->query->getBudgetSummary($account, $start, $end);
- $balancedAmount = $this->query->balancedTransactionsSum($account, $start, $end);
- $array = [];
- $hide = true;
- foreach ($budgets as $budget) {
- $id = intval($budget->id);
- $data = $budget->toArray();
- $array[$id] = $data;
- if (floatval($data['queryAmount']) != 0) {
- $hide = false;
- }
+ // array with budget information for each account:
+ $array = [];
+ // should always hide account
+ $hide = true;
+ // loop all budgets
+ foreach ($budgets as $budget) {
+ $id = intval($budget->id);
+ $data = $budget->toArray();
+ $array[$id] = $data;
+
+ // no longer hide account if any budget has money in it.
+ if (floatval($data['queryAmount']) != 0) {
+ $hide = false;
}
- $account->hide = $hide;
- $account->budgetInformation = $array;
- $account->balancedAmount = $balancedAmount;
-
+ $accountAmounts[$account->id] += $data['queryAmount'];
}
- );
+ $account->hide = $hide;
+ $account->budgetInformation = $array;
+ $account->balancedAmount = $balancedAmount;
+
+ }
/**
* Start getBudgetsForMonth DONE
@@ -101,7 +102,7 @@ class ReportController extends Controller
* End getBudgetsForMonth DONE
*/
- return view('reports.budget', compact('subTitle', 'year', 'month', 'subTitleIcon', 'date', 'accounts', 'budgets', 'dayEarly'));
+ return view('reports.budget', compact('subTitle', 'accountAmounts', 'year', 'month', 'subTitleIcon', 'date', 'accounts', 'budgets'));
}
diff --git a/resources/twig/reports/budget.twig b/resources/twig/reports/budget.twig
new file mode 100644
index 0000000000..11af7d0b90
--- /dev/null
+++ b/resources/twig/reports/budget.twig
@@ -0,0 +1,159 @@
+{% extends "./layout/default.twig" %}
+{% block content %}
+ {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, date) }}
+
+
+
+
+
+
+ Accounts
+
+
+
+ Account |
+ Start of month |
+ Current balance |
+ Spent |
+ Earned |
+
+
+ {% for account in accounts %}
+
+ {{ account.name }} |
+ {{ account.startBalance|formatAmount }} |
+ {{ account.endBalance|formatAmount }} |
+
+ {% if account.startBalance - account.endBalance > 0 %}
+ {{ (account.startBalance - account.endBalance)|formatAmountPlain }}
+ {% endif %}
+ |
+
+ {% if account.startBalance - account.endBalance < 0 %}
+ {{ ((account.startBalance - account.endBalance)*-1)|formatAmountPlain }}
+ {% endif %}
+ |
+
+ {% endfor %}
+
+
+
+
+
+
+
+
+
+ Budgets
+
+
+
+ Budgets |
+ {% for account in accounts %}
+ {% if not account.hide %}
+ {{ account.name }} |
+ {% endif %}
+ {% endfor %}
+
+ Left in budget
+ |
+
+ {% for id,budget in budgets %}
+
+ {{ budget.name }} |
+ {{ budget.queryAmount|formatAmount }} |
+ {% set spent = 0 %}
+ {% for account in accounts %}
+ {% if not account.hide %}
+ {% if account.budgetInformation[id] %}
+
+ {% if id == 0 %}
+
+ {{ account.budgetInformation[id].queryAmount|formatAmount }}
+
+ {% else %}
+ {{ account.budgetInformation[id].queryAmount|formatAmount }}
+ {% endif %}
+ |
+ {% set spent = spent + account.budgetInformation[id].queryAmount %}
+ {% else %}
+ {{ 0|formatAmount }} |
+ {% endif %}
+ {% endif %}
+ {% endfor %}
+ {{ (budget.queryAmount + budget.spent)|formatAmount }} |
+ {{ (budget.queryAmount + spent)|formatAmount }} |
+
+ {% endfor %}
+
+ Balanced by transfers |
+ {% for account in accounts %}
+ {% if not account.hide %}
+
+ {{ account.balancedAmount|formatAmount }}
+ |
+ {% endif %}
+ {% endfor %}
+ |
+
+
+ Left unbalanced |
+ {% for account in accounts %}
+
+ {% if not account.hide %}
+ {% if account.budgetInformation[0] %}
+
+ {% if account.budgetInformation[0].queryAmount + account.balancedAmount != 0.0 %}
+ {{ (account.budgetInformation[0].queryAmount + account.balancedAmount)|formatAmount }}
+ {% else %}
+ {{ (account.budgetInformation[0].queryAmount + account.balancedAmount)|formatAmount }}
+ {% endif %}
+ |
+ {% else %}
+ {{ 0|formatAmount }} |
+ {% endif %}
+ {% endif %}
+ {% endfor %}
+ |
+
+
+ Sum |
+ {% for account in accounts %}
+ {% if not account.hide %}
+ {{ accountAmounts[account.id]|formatAmount }} |
+ {% endif %}
+ {% endfor %}
+ |
+
+
+ Expected balance |
+ {% for account in accounts %}
+ {% if not account.hide %}
+ {{ (account.startBalance + accountAmounts[account.id])|formatAmount }} |
+ {% endif %}
+ {% endfor %}
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+{% endblock %}
+{% block scripts %}
+
+{% endblock %}
diff --git a/resources/twig/reports/index.twig b/resources/twig/reports/index.twig
new file mode 100644
index 0000000000..0768e23c4a
--- /dev/null
+++ b/resources/twig/reports/index.twig
@@ -0,0 +1,74 @@
+{% extends "./layout/default.twig" %}
+{% block content %}
+ {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName) }}
+
+
+
+
+
+
+ Yearly reports
+
+
+
+ {% for year in years %}
+ - {{ year }}
+ {% endfor %}
+
+
+
+
+
+
+
+
+
+ Monthly reports
+
+
+
+ {% for year, entries in months %}
+
{{ year }}
+
+ {% endfor %}
+
+
+
+
+
+
+
+
+
+ Budget reports
+
+
+ {% for year, entries in months %}
+
{{ year }}
+
+ {% endfor %}
+
+
+
+
+{% endblock %}
+
+{% block scripts %}
+
+{% endblock %}
diff --git a/resources/twig/reports/month.twig b/resources/twig/reports/month.twig
new file mode 100644
index 0000000000..62f1212e44
--- /dev/null
+++ b/resources/twig/reports/month.twig
@@ -0,0 +1,257 @@
+{% extends "./layout/default.twig" %}
+{% block content %}
+ {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, date) }}
+
+
+
+
+
+
+ Income
+
+
+ {% set sum = 0 %}
+ {% for entry in income %}
+ {% set sum = sum + entry.queryAmount %}
+
+
+ {{ entry.description }}
+ |
+
+ {% if entry.type == 'Withdrawal' %}
+ {{entry.queryAmount|formatAmountPlain}}
+ {% endif %}
+ {% if entry.type == 'Deposit' %}
+ {{entry.queryAmount|formatAmountPlain}}
+ {% endif %}
+ {% if entry.type == 'Transfer' %}
+ {{entry.queryAmount|formatAmountPlain}}
+ {% endif %}
+ |
+
+ {{entry.date.format('j F Y')}}
+ |
+
+ {{ entry.name }}
+ |
+
+ {% endfor %}
+ {% if displaySum %}
+
+ Sum |
+ {{ sum|formatAmount }} |
+
+ {% endif %}
+
+
+
+
+
+
+
+ Expenses (top 10)
+
+
+ {% set sum = 0 %}
+
+ {% for id,expense in expenses %}
+ {% set sum = sum + expense.queryAmount %}
+
+ {% if id > 0 %}
+ {{ expense.name }} |
+ {% else %}
+ {{ expense.name }} |
+ {% endif %}
+ {{ expense.queryAmount|formatAmountPlain }} |
+
+ {% endfor %}
+
+ Sum |
+ {{ sum|formatAmountPlain }} |
+
+
+
+
+
+
+
+
+ Sums
+
+ {% set totalIn = 0 %}
+ {% for entry in income %}
+ {% set totalIn = totalIn + entry.queryAmount %}
+ {% endfor %}
+
+
+ In |
+ {{ totalIn|formatAmount }} |
+
+
+ Out |
+ {{ sum|formatAmountPlain }} |
+
+
+ Difference |
+ {{ (totalIn - sum)|formatAmount }} |
+
+
+
+
+
+
+
+
+
+
+ Budgets
+
+
+
+ Budget |
+ Envelope |
+ Spent |
+ Left |
+
+ {% set sumSpent = 0 %}
+ {% set sumEnvelope = 0 %}
+ {% set sumLeft = 0 %}
+ {% for id,budget in budgets %}
+ {% set sumSpent = sumSpent + budget.spent %}
+ {% set sumEnvelope = sumEnvelope + budget.queryAmount %}
+ {% set sumLeft = sumLeft + budget.queryAmount + budget.spent %}
+
+ {% if budget.queryAmount != 0 or budget.spent != 0 %}
+
+
+ {% if id > 0 %}
+ {{ budget.name }}
+ {% else %}
+ {{ budget.name }}
+ {% endif %}
+ |
+ {{ budget.queryAmount|formatAmount }} |
+ {{ (budget.spent*-1)|formatAmountPlain }} |
+ {{ (budget.queryAmount + budget.spent)|formatAmount }} |
+
+ {% endif %}
+ {% endfor %}
+
+ Sum |
+ {{ sumEnvelope|formatAmount }} |
+ {{ sumSpent|formatAmount }} |
+ {{ sumLeft|formatAmount }} |
+
+
+
+
+
+
+
+
+ Categories
+
+
+
+ Category |
+ Spent |
+
+ {% set sum = 0 %}
+ {% for id,category in categories %}
+ {% set sum = sum + category.queryAmount %}
+
+
+ {% if id > 0 %}
+ {{ category.name }}
+ {% else %}
+ {{ category.name }}
+ {% endif %}
+ |
+ {{ (category.queryAmount * -1)|formatAmountPlain }} |
+
+ {% endfor %}
+
+ Sum |
+ {{ (sum * -1)|formatAmountPlain }} |
+
+
+
+
+
+
+
+
+
+
+ Accounts
+
+
+ {% set sumStart = 0 %}
+ {% set sumEnd = 0 %}
+ {% set sumDiff = 0 %}
+ {% for id,account in accounts %}
+
+ {% set sumStart = sumStart + account.startBalance %}
+ {% set sumEnd = sumEnd + account.endBalance %}
+ {% set sumDiff = sumDiff + account.difference %}
+
+ {{ account.name }} |
+ {{ account.startBalance|formatAmount }} |
+ {{ account.endBalance|formatAmount }} |
+ {{ account.difference|formatAmount }} |
+
+ {% endfor %}
+
+ Sum |
+ {{ sumStart|formatAmount }} |
+ {{ sumEnd|formatAmount }} |
+ {{ sumDiff|formatAmount }} |
+
+
+
+
+
+
+
+
+
+
+ Piggy banks
+
+
Body
+
+
+
+
+
+
+
+
+
+ Outside of budgets
+
+
Body
+
+
+
+{% endblock %}
+{% block scripts %}
+
+{% endblock %}
diff --git a/resources/twig/reports/year.twig b/resources/twig/reports/year.twig
new file mode 100644
index 0000000000..d59c747791
--- /dev/null
+++ b/resources/twig/reports/year.twig
@@ -0,0 +1,185 @@
+{% extends "./layout/default.twig" %}
+{% block content %}
+ {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, date) }}
+
+
+
+
+
+
+ Income vs. expenses
+
+
+
+
+
+
+
+
+ Income vs. expenses
+
+
+
+
+
+
+
+
+
+
+
+ Account balance
+
+
+
+ Name |
+ Balance at start of year |
+ Balance at end of year |
+ Difference |
+
+ {% 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 %}
+
+
+ {{ balance.account.name }}
+ {% if balance.shared %}
+ shared
+ {% endif %}
+ |
+ {{ balance.start|formatAmount }} |
+ {{ balance.end|formatAmount }} |
+ {{ (balance.end - balance.start)|formatAmount }} |
+
+ {% endif %}
+ {% endfor %}
+
+ Sum of sums |
+ {{ start|formatAmount }} |
+ {{ end|formatAmount }} |
+ {{ diff|formatAmount }} |
+
+
+
+
+
+
+
+ Income vs. expense
+
+ {% 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 %}
+
+
+
+ In |
+ {{ incomeSum|formatAmount }} |
+
+
+ Out |
+ {{ (expenseSum*-1)|formatAmount }} |
+
+
+ Difference |
+ {{ (incomeSum - expenseSum)|formatAmount }} |
+
+
+
+
+
+
+
+
+ Income
+
+
+ {% set sum = 0 %}
+ {% for income in groupedIncomes %}
+ {% set sum = sum + (income.queryAmount * -1) %}
+
+ {{ income.name }} |
+ {{ (income.queryAmount * -1)|formatAmount }} |
+
+ {% endfor %}
+
+ Sum |
+ {{ sum|formatAmount }} |
+
+
+
+
+
+
+
+
+ Expenses
+
+
+ {% set sum =0 %}
+ {% for expense in groupedExpenses %}
+
+ {{ expense.name }} |
+ {{ (expense.queryAmount*-1)|formatAmount }} |
+
+ {% set sum = sum + (expense.queryAmount * -1) %}
+ {% endfor %}
+
+ Sum |
+ {{ sum|formatAmount }} |
+
+
+
+
+
+
+
+{% endblock %}
+{% block scripts %}
+
+
+
+
+
+
+
+
+
+{% endblock %}