From 76e0215a41dd389b2f37866a827c8a85664b9dab Mon Sep 17 00:00:00 2001 From: Frank Poetzsch-Heffter <p-h@katharineum.de> Date: Thu, 26 Dec 2019 17:24:06 +0100 Subject: [PATCH] view and template for reports, some changes in models, view booking archive --- biscuit/apps/fibu/forms.py | 25 +++++----- biscuit/apps/fibu/models.py | 9 ++-- .../fibu/templates/fibu/account/final.html | 34 ------------- .../fibu/templates/fibu/account/index.html | 15 ++++-- .../fibu/templates/fibu/booking/book.html | 2 +- .../fibu/templates/fibu/booking/index.html | 10 +++- .../apps/fibu/templates/fibu/booking/new.html | 25 ++++++++++ .../fibu/templates/fibu/costcenter/index.html | 2 +- .../fibu/templates/fibu/reports/expenses.html | 40 +++++++++++++++ .../fibu/templates/fibu/reports/index.html | 16 ++++++ biscuit/apps/fibu/urls.py | 8 +-- biscuit/apps/fibu/views.py | 49 +++++++++++++++---- 12 files changed, 164 insertions(+), 71 deletions(-) delete mode 100755 biscuit/apps/fibu/templates/fibu/account/final.html create mode 100644 biscuit/apps/fibu/templates/fibu/booking/new.html create mode 100755 biscuit/apps/fibu/templates/fibu/reports/expenses.html create mode 100755 biscuit/apps/fibu/templates/fibu/reports/index.html diff --git a/biscuit/apps/fibu/forms.py b/biscuit/apps/fibu/forms.py index 15703fc..5e4bf2c 100644 --- a/biscuit/apps/fibu/forms.py +++ b/biscuit/apps/fibu/forms.py @@ -27,11 +27,11 @@ class CheckBookingForm(forms.ModelForm): fields = ('account', ) class BookBookingForm(forms.ModelForm): - accounts = Account.objects.filter().order_by('costcenter','name') - user = User.objects.filter() - description = forms.CharField(label='Beschreibung') - planned_amount = forms.IntegerField(label='Erwarteter Betrag (ganze Euro)') - justification = forms.CharField(label='Begründung', required=False) + accounts = Account.objects.filter().order_by('costcenter','name') + user = User.objects.filter() + description = forms.CharField(label='Beschreibung') + planned_amount = forms.IntegerField(label='Erwarteter Betrag (ganze Euro)') + justification = forms.CharField(label='Begründung', required=False) account = forms.ModelChoiceField(queryset=accounts, label='Buchungskonto') contact = forms.ModelChoiceField(queryset=user, label='Kontakt') invoice_date = forms.DateField(label='Rechnungsdatum') @@ -57,7 +57,7 @@ class BookBookingForm(forms.ModelForm): class Meta: model = Booking - fields = ('id', 'description', 'planned_amount', 'justification','account', 'contact', 'invoice_date', + fields = ('id', 'description', 'planned_amount', 'justification', 'account', 'contact', 'invoice_date', 'invoice_number', 'firma', 'amount', 'submission_date', 'payout_number', 'booking_date', 'maturity', 'upload', 'status') @@ -74,16 +74,17 @@ class EditCostcenterForm(forms.ModelForm): class EditAccountForm(forms.ModelForm): - name = forms.CharField(max_length=30, label='Buchungskonto') - costcenterlist = Costcenter.objects.filter() - costcenter = forms.ModelChoiceField(queryset=costcenterlist, label='Kostenstelle') - budget = forms.IntegerField(label='Budget') + name = forms.CharField(max_length=30, label='Buchungskonto') + costcenterlist = Costcenter.objects.filter() + costcenter = forms.ModelChoiceField(queryset=costcenterlist, label='Kostenstelle') + income = forms.BooleanField(label='Budget-/Einnanhmekonto', required=False) + budget = forms.IntegerField(label='Budget') - layout = Layout(Row('name', 'costcenter', 'budget')) + layout = Layout(Row('name', 'costcenter', 'income', 'budget')) class Meta: model = Account - fields = ('id', 'name', 'costcenter', 'budget') + fields = ('id', 'name', 'costcenter', 'income', 'budget') # diff --git a/biscuit/apps/fibu/models.py b/biscuit/apps/fibu/models.py index 0cfab05..50a0cd3 100644 --- a/biscuit/apps/fibu/models.py +++ b/biscuit/apps/fibu/models.py @@ -1,8 +1,7 @@ from django.db import models from django.contrib.auth.models import User -YEARLIST = [(2019,'2019'), - (2020,'2020'), +YEARLIST = [(2020,'2020'), (2021,'2021'), (2022,'2022'), (2023,'2023')] @@ -20,7 +19,8 @@ status_list = [ Status(name='beantragt', style_class='red'), Status(name='bewilligt', style_class='orange'), Status(name='abgelehnt', style_class='black'), - Status(name='bestellt', style_class='yellow'), + Status(name='bestellt', style_class='darkyellow'), + Status(name='eingereicht', style_class='blue'), Status(name='bezahlt', style_class='green'), ] @@ -29,7 +29,7 @@ status_choices = [(x, val.name) for x, val in enumerate(status_list)] class Costcenter(models.Model): - # Kostenstellen z.B. Schoolträger-konsumtiv, Schulträger-investiv, Elternberein, ... + # Kostenstellen z.B. Schulträger-konsumtiv, Schulträger-investiv, Elternverein, ... name = models.CharField(max_length=30) year = models.IntegerField(default=2019, choices=YEARLIST, verbose_name="Jahr") def __str__(self): @@ -44,6 +44,7 @@ class Account(models.Model): # Buchungskonten, z.B. Fachschaften, Sekretariat, Schulleiter, Kopieren, Tafelnutzung name = models.CharField(max_length=20, default='') costcenter = models.ForeignKey(to=Costcenter, on_delete=models.CASCADE, default='') + income = models.BooleanField(default=False) # True, wenn es sich um ein Einnahmekonto handelt budget = models.DecimalField(max_digits=9, decimal_places=2, default=0.00) saldo = models.DecimalField(max_digits=9, decimal_places=2, default=0.00) rest = models.DecimalField(max_digits=9, decimal_places=2, default=0.00) diff --git a/biscuit/apps/fibu/templates/fibu/account/final.html b/biscuit/apps/fibu/templates/fibu/account/final.html deleted file mode 100755 index e882c4a..0000000 --- a/biscuit/apps/fibu/templates/fibu/account/final.html +++ /dev/null @@ -1,34 +0,0 @@ -{% include 'partials/header.html' %} -{% load material_form %} - -<main> - - {% block content %} - - <h4>Schlussrechnung</h4> - - <div class="collection"> - {% for costcenter, accounts in costcenter_accounts.items %} - <h5 class="collection-item">{{ costcenter }}</h5> - - <div class="collection"> - <div class="collection-item row"> - <span class="col s4 m4 ">Buchungskonto</span> - <span class="col s2 m2 right-align">zugeteiltes Budget</span> - <span class="col s2 m2 right-align">bisherige Ausgaben</span> - <span class="col s2 m2 right-align">verfügbare Reste</span> - </div> - {% for account in accounts %} - <div class="collection-item row"> - <span class="col s4 m4">{{ account.name }}</span> - <span class="col s2 m2 right-align">{{ account.budget }}</span> - <span class="col s2 m2 right-align">{{ account.saldo }}</span> - <span class="col s2 m2 right-align">{{ account.rest }}</span> - </div> - {% endfor %} - </div> - {% endfor %} - </div> - {% endblock %} -</main> -{% include 'partials/footer.html' %} diff --git a/biscuit/apps/fibu/templates/fibu/account/index.html b/biscuit/apps/fibu/templates/fibu/account/index.html index 3030915..ed8a622 100755 --- a/biscuit/apps/fibu/templates/fibu/account/index.html +++ b/biscuit/apps/fibu/templates/fibu/account/index.html @@ -7,7 +7,7 @@ {% block content %} - <h4>Buchungskonten</h4> + <h4>Neues Buchungskonto</h4> <form method="POST" style="border-width: 5px; background: #eee;"> {% csrf_token %} {% form form=form %} @@ -21,10 +21,15 @@ <div class="collection"> {% for account in accounts %} <div class="collection-item row"> - <span class="col s12 m6">{{ account.name }}</span> - <span class="col s12 m2">{{ account.costcenter }}</span> - <span class="col s12 m2 right-align">{{ account.budget }}</span> - <span class="col s12 m2 right-align"> + <span class="col s6 m6">{{ account.name }}</span> + <span class="col s2 m2">{{ account.costcenter }}</span> + {% if account.income %} + <span class="col s1 m1 right-align">{{ account.budget }}</span> + <span class="col s1 m1 right-align"></span> + {% else %} + <span class="col s2 m2 right-align">{{ account.budget }}</span> + {% endif %} + <span class="col s2 m2 right-align"> <form action="{% url 'account_edit' account.id %}" class="left"> {% csrf_token %} <input type="hidden" value="{{ account.id }}" name="account-id"> diff --git a/biscuit/apps/fibu/templates/fibu/booking/book.html b/biscuit/apps/fibu/templates/fibu/booking/book.html index b4c8dfd..00767f7 100644 --- a/biscuit/apps/fibu/templates/fibu/booking/book.html +++ b/biscuit/apps/fibu/templates/fibu/booking/book.html @@ -13,7 +13,7 @@ <button type="submit" class="waves-effect waves-light btn green"> <i class="material-icons left">send</i> Änderungen übernehmen </button> - <a href="{% url 'booking' %}"> + <a href="{% url 'booking' 0 %}"> <button type="button" class="waves-effect waves-light btn grey"> <i class="material-icons left">cancel</i> Abbrechen </button> diff --git a/biscuit/apps/fibu/templates/fibu/booking/index.html b/biscuit/apps/fibu/templates/fibu/booking/index.html index 331d1a7..1e0d3c7 100755 --- a/biscuit/apps/fibu/templates/fibu/booking/index.html +++ b/biscuit/apps/fibu/templates/fibu/booking/index.html @@ -3,11 +3,17 @@ <main> {% block content %} - + <a href="{% url 'new_booking' %}" class="waves-effect waves-light btn green right">Neue Buchung anlegen</a> + <span class="right" style="width: 20px;"> </span> + {% if archiv %} + <a href="{% url 'booking' 0 %}" class="waves-effect waves-light btn grey right">Zur aktuellen Übersicht</a> + {% else %} + <a href="{% url 'booking' 1 %}" class="waves-effect waves-light btn grey right">Zum Archiv</a> + {% endif %} <h4>Buchungen</h4> <div class="collection"> {% for booking in bookings %} - <a href="/fibu/booking/{{ booking.id }}" class="collection-item row"> + <a href="/fibu/booking/book/{{ booking.id }}" class="collection-item row"> <span class="col s5 m5">{{ booking.description }}</span> <span class="col s1 m1 right-align">{{ booking.planned_amount }} €</span> <span class="col s3 m3">{{ booking.account }}</span> diff --git a/biscuit/apps/fibu/templates/fibu/booking/new.html b/biscuit/apps/fibu/templates/fibu/booking/new.html new file mode 100644 index 0000000..3409f57 --- /dev/null +++ b/biscuit/apps/fibu/templates/fibu/booking/new.html @@ -0,0 +1,25 @@ +{% include 'partials/header.html' %} +{% load material_form %} + +<main> + + <h4>Neue Buchung</h4> + + <form method="POST" style="background: #eee"> + {% csrf_token %} + {% form form=form %} + {% endform %} + <span class="right"> + <button type="submit" class="waves-effect waves-light btn green"> + <i class="material-icons left">send</i> Buchung anlegen + </button> + <a href="{% url 'booking' %}"> + <button type="button" class="waves-effect waves-light btn grey"> + <i class="material-icons left">cancel</i> Abbrechen + </button> + </a> + </span> + </form> + +</main> +{% include 'partials/footer.html' %} diff --git a/biscuit/apps/fibu/templates/fibu/costcenter/index.html b/biscuit/apps/fibu/templates/fibu/costcenter/index.html index 3390aab..89e3485 100755 --- a/biscuit/apps/fibu/templates/fibu/costcenter/index.html +++ b/biscuit/apps/fibu/templates/fibu/costcenter/index.html @@ -5,7 +5,7 @@ {% block content %} - <h4>Kostenstellen</h4> + <h4>Neue Kostenstelle</h4> <form method="POST" style="border-width: 5px; background: #eee;"> {% csrf_token %} {% form form=form %} diff --git a/biscuit/apps/fibu/templates/fibu/reports/expenses.html b/biscuit/apps/fibu/templates/fibu/reports/expenses.html new file mode 100755 index 0000000..10a7668 --- /dev/null +++ b/biscuit/apps/fibu/templates/fibu/reports/expenses.html @@ -0,0 +1,40 @@ +{% include 'partials/header.html' %} +{% load material_form %} + +<main> + + {% block content %} + + <h4>Schlussrechnung</h4> + + <div class="collection"> + {% for costcenter, accounts in costcenter_accounts.items %} + <h5 class="collection-item">{{ costcenter }}</h5> + + <div class="collection"> + <div class="row"> + <span class="col s5 m5 white-text grey">Buchungskonto</span> + <span class="col s2 m2 white-text grey right-align">Budget</span> + <span class="col s1 m1 white-text grey right-align">Einnahmen</span> + <span class="col s1 m1 white-text grey right-align">Ausgaben</span> + <span class="col s1 m1 white-text grey right-align">Reste</span> + </div> + {% for account in accounts %} + <div class="collection-item row"> + <span class="col s5 m5">{{ account.name }}</span> + <span class="col s2 m2 right-align">{{ account.budget }}</span> + <span class="col s1 m1 right-align"> + {% if account.income %}{{ account.saldo }}{% endif %} + </span> + <span class="col s1 m1 right-align"> + {% if not account.income %}{{ account.saldo }}{% endif %} + </span> + <span class="col s1 m1 right-align">{{ account.rest }}</span> + </div> + {% endfor %} + </div> + {% endfor %} + </div> + {% endblock %} +</main> +{% include 'partials/footer.html' %} diff --git a/biscuit/apps/fibu/templates/fibu/reports/index.html b/biscuit/apps/fibu/templates/fibu/reports/index.html new file mode 100755 index 0000000..4b45b41 --- /dev/null +++ b/biscuit/apps/fibu/templates/fibu/reports/index.html @@ -0,0 +1,16 @@ +{% include 'partials/header.html' %} +{% load material_form %} + +<main> + + {% block content %} + + <h4>Berichte</h4> + + <div class="collection"> + <a href="reports/expenses" class="collection-item">Ausgaben</a> + </div> + + {% endblock %} +</main> +{% include 'partials/footer.html' %} diff --git a/biscuit/apps/fibu/urls.py b/biscuit/apps/fibu/urls.py index 2322c06..9f23b05 100755 --- a/biscuit/apps/fibu/urls.py +++ b/biscuit/apps/fibu/urls.py @@ -6,13 +6,15 @@ urlpatterns = [ path('', views.index, name='fibu_index'), path('booking/check', views.check, name='booking_check'), path('booking/edit/<int:id>', views.edit, name='booking_edit'), - path('booking', views.booking, name='booking'), - path('booking/<int:id>', views.book, name='booking_book'), + path('booking/new', views.new_booking, name='new_booking'), + path('booking/<int:archiv>', views.booking, name='booking'), + path('booking/book/<int:id>', views.book, name='booking_book'), path('costcenter', views.costcenter, name='costcenter'), path('costcenter/edit/<int:id>', views.costcenter_edit, name='costcenter_edit'), path('account', views.account, name='account'), path('account/edit/<int:id>', views.account_edit, name='account_edit'), - path('account/final', views.final_account, name='final_account'), + path('reports', views.reports, name='reports'), + path('reports/expenses', views.expenses, name='expenses'), # path('make_booking', views.make_booking, name='fibu_make_booking'), # path('edit/<int:id>', views.edit, name='booking_edit'), ] diff --git a/biscuit/apps/fibu/views.py b/biscuit/apps/fibu/views.py index c0b6634..04a46b8 100644 --- a/biscuit/apps/fibu/views.py +++ b/biscuit/apps/fibu/views.py @@ -49,7 +49,8 @@ def index(request): # a.save() # return redirect('fibu_make_booking') return redirect('fibu_index') - bookings = Booking.objects.filter() + bookings = Booking.objects.filter().order_by('status') + context = {'bookings': bookings, 'form': form} return render(request, 'fibu/index.html', context) @@ -110,9 +111,12 @@ def check(request): @login_required # @permission_required('fibu.book_booking') -def booking(request): - bookings = Booking.objects.filter() - context = {'bookings': bookings} +def booking(request, archiv): + if archiv: + bookings = Booking.objects.filter(status=5).order_by('-status') + else: + bookings = Booking.objects.filter(status__lt=5).order_by('-status') + context = {'bookings': bookings, 'archiv': archiv} return render(request, 'fibu/booking/index.html', context) @login_required @@ -134,6 +138,24 @@ def book(request, id): context = {'form': form} return render(request, template, context) +@login_required +#@permission_required('fibu.book_booking') +def new_booking(request): + form = BookBookingForm() + template = 'fibu/booking/new.html' + if request.method == 'POST': + form = BookBookingForm(request.POST, request.FILES) + if form.is_valid(): + form.save() + # a = Activity(user=request.user, title="Antrag auf Unterrichtsbefreiung verändert", + # description="Sie haben Ihren Antrag auf Unterrichtsbefreiung " + + # "für den Zeitraum von {} bis {} bearbeitet.".format( + # aub.from_date, aub.to_date), app=AubConfig.verbose_name) + # a.save() + return redirect(reverse('booking')) + context = {'form': form} + return render(request, template, context) + @login_required #@permission_required('fibu.view_booking') @@ -221,8 +243,9 @@ def account(request): if form.is_valid(): name = form.cleaned_data['name'] costcenter = form.cleaned_data['costcenter'] + income = form.cleaned_data['income'] budget = form.cleaned_data['budget'] - account = Account(name=name, costcenter=costcenter, budget=budget) + account = Account(name=name, costcenter=costcenter, income=income, budget=budget) account.save() # a = Activity(user=request.user, title="Antrag auf Unterrichtsbefreiung gestellt", @@ -261,7 +284,12 @@ def account_edit(request, id): @login_required #@permission_required('fibu.view_booking') -def final_account(request): +def reports(request): + return render(request, 'fibu/reports/index.html') + +@login_required +#@permission_required('fibu.view_booking') +def expenses(request): costcenterlist = Costcenter.objects.filter() costcenter_accounts = {} account_rests = {} @@ -271,12 +299,15 @@ def final_account(request): for account in accounts: saldo = Booking.objects.filter(account=account).aggregate(Sum('amount')) saldo = saldo['amount__sum'] - rest = account.budget - saldo + try: + rest = account.budget - saldo + except: + rest = 0 try: Account.objects.filter(id=account.id).update(saldo=saldo, rest=rest) except: Account.objects.filter(id=account.id).update(saldo=0, rest=0) - costcenter_accounts[costcenter.name] = list(Account.objects.filter(costcenter=costcenter)) + costcenter_accounts[costcenter.name] = list(Account.objects.filter(costcenter=costcenter).order_by('-income')) context = {'costcenter_accounts': costcenter_accounts, 'account_rests': account_rests} - return render(request, 'fibu/account/final.html', context) + return render(request, 'fibu/reports/expenses.html', context) -- GitLab