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 +
+ + + + + + + + + + {% for account in accounts %} + + + + + + + + {% endfor %} +
AccountStart of monthCurrent balanceSpentEarned
{{ 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 %} +
+
+
+
+
+
+
+
+ + Budgets +
+ + + + {% for account in accounts %} + {% if not account.hide %} + + {% endif %} + {% endfor %} + + + {% for id,budget in budgets %} + + + + {% set spent = 0 %} + {% for account in accounts %} + {% if not account.hide %} + {% if account.budgetInformation[id] %} + + {% set spent = spent + account.budgetInformation[id].queryAmount %} + {% else %} + + {% endif %} + {% endif %} + {% endfor %} + + + + {% endfor %} + + + {% for account in accounts %} + {% if not account.hide %} + + {% endif %} + {% endfor %} + + + + + {% for account in accounts %} + + {% if not account.hide %} + {% if account.budgetInformation[0] %} + + {% else %} + + {% endif %} + {% endif %} + {% endfor %} + + + + + {% for account in accounts %} + {% if not account.hide %} + + {% endif %} + {% endfor %} + + + + + {% for account in accounts %} + {% if not account.hide %} + + {% endif %} + {% endfor %} + + + +
Budgets{{ account.name }} + Left in budget +
{{ budget.name }}{{ budget.queryAmount|formatAmount }} + {% if id == 0 %} + + {{ account.budgetInformation[id].queryAmount|formatAmount }} + + {% else %} + {{ account.budgetInformation[id].queryAmount|formatAmount }} + {% endif %} + {{ 0|formatAmount }}{{ (budget.queryAmount + budget.spent)|formatAmount }}{{ (budget.queryAmount + spent)|formatAmount }}
Balanced by transfers + {{ account.balancedAmount|formatAmount }} +  
Left unbalanced + {% 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 %} + {{ 0|formatAmount }} 
Sum{{ accountAmounts[account.id]|formatAmount }} 
Expected balance{{ (account.startBalance + accountAmounts[account.id])|formatAmount }} 
+
+
+
+ + + + +{% 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 %} + + + + + + + {% endfor %} + {% if displaySum %} + + + + + {% endif %} +
+ {{ 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 }} +
Sum{{ sum|formatAmount }}
+
+
+
+
+
+ + Expenses (top 10) +
+ + {% set sum = 0 %} + + {% for id,expense in expenses %} + {% set sum = sum + expense.queryAmount %} + + {% if id > 0 %} + + {% else %} + + {% endif %} + + + {% endfor %} + + + + +
{{ expense.name }}{{ expense.name }}{{ expense.queryAmount|formatAmountPlain }}
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 +
+ + + + + + + + {% 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 %} + + + + + + + {% endif %} + {% endfor %} + + + + + + +
BudgetEnvelopeSpentLeft
+ {% if id > 0 %} + {{ budget.name }} + {% else %} + {{ budget.name }} + {% endif %} + {{ budget.queryAmount|formatAmount }}{{ (budget.spent*-1)|formatAmountPlain }}{{ (budget.queryAmount + budget.spent)|formatAmount }}
Sum{{ sumEnvelope|formatAmount }}{{ sumSpent|formatAmount }}{{ sumLeft|formatAmount }}
+
+
+
+
+
+ + Categories +
+ + + + + + {% set sum = 0 %} + {% for id,category in categories %} + {% set sum = sum + category.queryAmount %} + + + + + {% endfor %} + + + + +
CategorySpent
+ {% if id > 0 %} + {{ category.name }} + {% else %} + {{ category.name }} + {% endif %} + {{ (category.queryAmount * -1)|formatAmountPlain }}
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 %} + + + + + + + {% endfor %} + + + + + + +
{{ account.name }}{{ account.startBalance|formatAmount }}{{ account.endBalance|formatAmount }}{{ account.difference|formatAmount }}
Sum{{ sumStart|formatAmount }}{{ sumEnd|formatAmount }}{{ sumDiff|formatAmount }}
+
+
+
+
+
+
+
+ + Piggy banks +
+
Body
+
+
+
+
+
+
+
+ + Bills +
+
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 +
+ + + + + + + + {% 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 %} + + + + + + + {% endif %} + {% endfor %} + + + + + + +
NameBalance at start of yearBalance at end of yearDifference
+ {{ balance.account.name }} + {% if balance.shared %} + shared + {% endif %} + {{ balance.start|formatAmount }}{{ balance.end|formatAmount }}{{ (balance.end - balance.start)|formatAmount }}
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) %} + + + + + {% endfor %} + + + + +
{{ income.name }}{{ (income.queryAmount * -1)|formatAmount }}
Sum{{ sum|formatAmount }}
+
+
+
+
+
+ + Expenses +
+ + {% set sum =0 %} + {% for expense in groupedExpenses %} + + + + + {% set sum = sum + (expense.queryAmount * -1) %} + {% endfor %} + + + + +
{{ expense.name }}{{ (expense.queryAmount*-1)|formatAmount }}
Sum{{ sum|formatAmount }}
+
+
+
+
+
+
+
+ + Budgets +
+
+
+
+
+
+
+ +{% endblock %} +{% block scripts %} + + + + + + + + + +{% endblock %}