diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index f72ec26884..733e08f544 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -190,6 +190,7 @@ class BudgetController extends Controller $journals = $repository->getJournals($budget, $repetition); $limits = !is_null($repetition->id) ? [$repetition->budgetLimit] : $repository->getBudgetLimits($budget); $subTitle = !is_null($repetition->id) ? e($budget->name) . ' in ' . $repetition->startdate->format('F Y') : e($budget->name); + $journals->setPath('/budgets/show/'.$budget->id); return view('budgets.show', compact('limits', 'budget', 'repetition', 'journals', 'subTitle')); } diff --git a/app/Providers/ConfigServiceProvider.php b/app/Providers/ConfigServiceProvider.php index 926e9363c4..c2cfad8399 100644 --- a/app/Providers/ConfigServiceProvider.php +++ b/app/Providers/ConfigServiceProvider.php @@ -162,6 +162,7 @@ class ConfigServiceProvider extends ServiceProvider ], 'Session', 'Route', + 'URL', 'Config', 'ExpandedForm' => [ 'is_safe' => [ diff --git a/app/Providers/FireflyServiceProvider.php b/app/Providers/FireflyServiceProvider.php index b9d5601eaa..b2a298caf4 100644 --- a/app/Providers/FireflyServiceProvider.php +++ b/app/Providers/FireflyServiceProvider.php @@ -9,6 +9,7 @@ use FireflyIII\Support\ExpandedForm; use FireflyIII\Support\Navigation; use FireflyIII\Support\Preferences; use FireflyIII\Support\Steam; +use FireflyIII\Support\Twig\Budget; use FireflyIII\Support\Twig\General; use FireflyIII\Support\Twig\Journals; use FireflyIII\Validation\FireflyValidator; @@ -39,6 +40,7 @@ class FireflyServiceProvider extends ServiceProvider Twig::addExtension(new Functions($config)); Twig::addExtension(new General); Twig::addExtension(new Journals); + Twig::addExtension(new Budget); } public function register() diff --git a/app/Support/Twig/Budget.php b/app/Support/Twig/Budget.php new file mode 100644 index 0000000000..39ec2a1e04 --- /dev/null +++ b/app/Support/Twig/Budget.php @@ -0,0 +1,53 @@ +leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id') + ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') + ->leftJoin('budget_limits', 'budget_limits.budget_id', '=', 'budget_transaction_journal.budget_id') + ->leftJoin('limit_repetitions', 'limit_repetitions.budget_limit_id', '=', 'budget_limits.id') + ->where('transaction_journals.date', '>=', $repetition->startdate->format('Y-m-d')) + ->where('transaction_journals.date', '<=', $repetition->enddate->format('Y-m-d')) + ->where('transaction_journals.user_id', Auth::user()->id) + ->whereNull('transactions.deleted_at') + ->where('transactions.amount', '>', 0) + ->where('limit_repetitions.id', '=', $repetition->id) + ->sum('transactions.amount'); + + return floatval($sum); + } + ); + + return $functions; + + } + + /** + * {@inheritDoc} + */ + public function getName() + { + return 'FireflyIII\Support\Twig\Budget'; + } +} \ No newline at end of file diff --git a/resources/twig/budgets/delete.twig b/resources/twig/budgets/delete.twig new file mode 100644 index 0000000000..e1b7e5ef95 --- /dev/null +++ b/resources/twig/budgets/delete.twig @@ -0,0 +1,43 @@ +{% extends "./layout/default.twig" %} +{% block content %} + {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, budget) }} + {{ Form.open({'class' : 'form-horizontal','id' : 'destroy','url' : route('budgets.destroy',budget.id) }) }} +
+
+
+
+ Delete budget "{{ budget.name}}" +
+
+

+ Are you sure that you want to delete budget "{{ budget.name }}"? +

+ + {% if budget.transactionjournals|length > 0 %} +

+ Budget "{{ budget.name }}" still has {{ budget.transactionjournals|length }} transactions connected + to it. These will not be removed but will lose their connection to this budget. +

+ {% endif %} + +

+ + Cancel +

+
+
+
+
+ +
+
+
+
+ +
+
+
+
+ + +{% endblock %} \ No newline at end of file diff --git a/resources/twig/budgets/edit.twig b/resources/twig/budgets/edit.twig new file mode 100644 index 0000000000..edb967500f --- /dev/null +++ b/resources/twig/budgets/edit.twig @@ -0,0 +1,49 @@ +{% extends "./layout/default.twig" %} +{% block content %} + {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, budget) }} +
+
+

Use budgets to organize and limit your expenses.

+
+
+ + {{ Form.model(budget, {'class' : 'form-horizontal','id' : 'update','url' : route('budgets.update',budget.id) } ) }} + +
+
+
+
+ Mandatory fields +
+
+ {{ ExpandedForm.checkbox('active') }} + {{ ExpandedForm.text('name') }} +
+
+ +
+
+ +
+
+ Options +
+
+ {{ ExpandedForm.optionsList('update','budget') }} +
+
+
+
+
+
+

+ +

+
+
+ + + +{% endblock %} diff --git a/resources/twig/budgets/income.twig b/resources/twig/budgets/income.twig new file mode 100644 index 0000000000..de8420042b --- /dev/null +++ b/resources/twig/budgets/income.twig @@ -0,0 +1,22 @@ +
+ + + +
diff --git a/resources/twig/budgets/noBudget.twig b/resources/twig/budgets/noBudget.twig new file mode 100644 index 0000000000..df482d3546 --- /dev/null +++ b/resources/twig/budgets/noBudget.twig @@ -0,0 +1,17 @@ +{% extends "./layout/default.twig" %} +{% block content %} + {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName) }} +
+
+
+
+ {{ subTitle }} +
+
+ {% include 'list/journals.twig' with {'journals': list} %} +
+
+
+
+ +{% endblock %} \ No newline at end of file diff --git a/resources/twig/budgets/show.twig b/resources/twig/budgets/show.twig new file mode 100644 index 0000000000..d062d785a5 --- /dev/null +++ b/resources/twig/budgets/show.twig @@ -0,0 +1,108 @@ +{% extends "./layout/default.twig" %} +{% block content %} + {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName,budget, repetition) }} +
+
+
+
+ Overview + + + +
+
+ + +
+
+
+
+
+
+
+ +
+
+ Transactions +
+ {% include 'list/journals.twig' %} +
+
+
+ {% if limits|length == 1 %} +

Show everything

+ {% endif %} + + {% for limit in limits %} + {% for rep in limit.limitRepetitions %} +
+ +
+
+
+ Amount: {{ rep.amount|formatAmount }} +
+
+ Spent: {{ spentInRepetition(rep)|formatAmount }} +
+
+
+
+ {% set overspent = spentInRepetition(rep) > rep.amount %} + {% if overspent %} + {% set spent = spentInRepetition(rep) %} + {% set pct = (spent != 0 ? (rep.amount / spent)*100 : 0) %} +
+
+
+
+ {% else %} + {% set amount = rep.amount %} + {% set pct = (amount != 0 ? (spentInRepetition(rep) / amount)*100 : 0) %} +
+
+
+ {% endif %} +
+
+
+
+ {% endfor %} + {% endfor %} + + {% if limits|length == 1 %} +

Show everything

+ {% endif %} + +
+
+ +{% endblock %} +{% block scripts %} + + + + + + + + +{% endblock %} diff --git a/resources/twig/list/journals.twig b/resources/twig/list/journals.twig index 0fa99ec0ab..7e61c16bf4 100644 --- a/resources/twig/list/journals.twig +++ b/resources/twig/list/journals.twig @@ -1,4 +1,4 @@ -{{ journals.render }} +{{ journals.render|raw }} @@ -110,4 +110,4 @@ {% endfor %}
-{{ journals.render }} +{{ journals.render|raw }} \ No newline at end of file