diff --git a/schoolapps/fibu/forms.py b/schoolapps/fibu/forms.py index e3b4ed127ad53431310a8b71d5c8629df75a0def..15703fc32273f5fcfbbdcb2a2197fde91492adb8 100644 --- a/schoolapps/fibu/forms.py +++ b/schoolapps/fibu/forms.py @@ -2,9 +2,9 @@ from django import forms from django.core.exceptions import ValidationError from django.utils import timezone from datetime import datetime +from django.contrib.auth.models import User from material import Layout, Row, Fieldset -from .models import YEARLIST, Booking, Costcenter, Account - +from .models import YEARLIST, Booking, Costcenter, Account, status_choices class EditBookingForm(forms.ModelForm): description = forms.CharField(label='Beschreibung - Was soll gekauft werden?') @@ -19,12 +19,47 @@ class EditBookingForm(forms.ModelForm): class CheckBookingForm(forms.ModelForm): - costcenterlist = Costcenter.objects.filter() - costcenter = forms.ModelChoiceField(queryset=costcenterlist, label='Kostenstelle') + accounts = Account.objects.filter().order_by('costcenter','name') + account = forms.ModelChoiceField(queryset=accounts, label='Buchungskonto') class Meta: - model = Costcenter - fields = ('id', 'name') + model = Account + 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) + account = forms.ModelChoiceField(queryset=accounts, label='Buchungskonto') + contact = forms.ModelChoiceField(queryset=user, label='Kontakt') + invoice_date = forms.DateField(label='Rechnungsdatum') + invoice_number = forms.CharField(label='Rechnungsnummer') + firma = forms.CharField(label='Firma') + amount = forms.DecimalField(max_digits=9, decimal_places=2, label='Betrag') + submission_date = forms.DateField(label='Bearbeitungsdatum') + payout_number = forms.IntegerField(label='Auszahlungsnummer') + booking_date = forms.DateField(label='Buchungsdatum') + maturity = forms.DateField(label='Fälligkeit') + upload = forms.FileField(label='Scan der Rechnung', required=False) + status = forms.ChoiceField(choices=status_choices, label='Status') + + + layout = Layout(Row('description', 'justification', 'contact'), + Row('account', 'status', 'planned_amount'), + Fieldset('Details', + Row('firma', 'invoice_number', 'amount'), + Row('invoice_date', 'maturity', 'submission_date', 'booking_date'), + Row('payout_number', 'upload') + ) + ) + + class Meta: + model = Booking + fields = ('id', 'description', 'planned_amount', 'justification','account', 'contact', 'invoice_date', + 'invoice_number', 'firma', 'amount', 'submission_date', 'payout_number', 'booking_date', + 'maturity', 'upload', 'status') class EditCostcenterForm(forms.ModelForm): diff --git a/schoolapps/fibu/models.py b/schoolapps/fibu/models.py index 4ff70f291823e713f7e2d7f32a1aec37d13de4a0..4dba09ba4ded93838d5e36ccea9c33eb77fde453 100644 --- a/schoolapps/fibu/models.py +++ b/schoolapps/fibu/models.py @@ -13,7 +13,7 @@ class Status: self.style_class = style_class def __str__(self): - return self.name + return "%s" % (self.name) status_list = [ @@ -30,7 +30,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, ... - name = models.CharField(max_length=20) + name = models.CharField(max_length=30) year = models.IntegerField(default=2019, choices=YEARLIST, verbose_name="Jahr") def __str__(self): return "%s" % (self.name) @@ -45,27 +45,30 @@ class Account(models.Model): name = models.CharField(max_length=20, default='') costcenter = models.ForeignKey(to=Costcenter, on_delete=models.CASCADE, default='') budget = models.DecimalField(max_digits=9, decimal_places=2, default=0.00) + def __str__(self): + return "%s: %s" % (self.costcenter, self.name) + class Meta: permissions = ( ('edit_account', 'Can edit account'), ) class Booking(models.Model): -# account = models.ForeignKey(to=Account, on_delete=models.SET_NULL, blank=True, null=True) + account = models.ForeignKey(to=Account, on_delete=models.SET_NULL, blank=True, null=True) contact = models.ForeignKey(to=User, related_name='bookings', on_delete=models.SET_NULL , verbose_name="Erstellt von", blank=True, null=True) -# invoice_date = models.DateField() -# invoice_number = models.CharField(max_length=20) -# firma = models.CharField(max_length=30) + invoice_date = models.DateField(default='2000-12-31') + invoice_number = models.CharField(max_length=20, default='0') + firma = models.CharField(max_length=30, default='') description = models.CharField(max_length=50) -# amount = models.DecimalField(max_digits=9, decimal_places=2) + amount = models.DecimalField(max_digits=9, decimal_places=2, default=0.00) planned_amount = models.IntegerField() - submission_date = models.DateField(default='2019-01-01') + submission_date = models.DateField(default='2000-12-31') justification = models.CharField(max_length=2000, blank=True, null=True) -# payout_number = models.IntegerField() -# booking_date = models.DateField() -# maturity = models.DateField() -# upload = models.FileField(upload_to='uploads/fibu/%Y/') + payout_number = models.IntegerField(default=0) + booking_date = models.DateField(default='2000-12-31') + maturity = models.DateField(default='2000-12-31') + upload = models.FileField(upload_to='uploads/fibu/%Y/', default=None, blank=True, null=True) status = models.IntegerField(default=0, choices=status_choices, verbose_name="Status") diff --git a/schoolapps/fibu/templates/fibu/account/index.html b/schoolapps/fibu/templates/fibu/account/index.html index 550a6e2df41d41dfbbf6ed2f03bacc194196a63a..3030915c32ca2a896ffa363ca80162f36f7c5321 100755 --- a/schoolapps/fibu/templates/fibu/account/index.html +++ b/schoolapps/fibu/templates/fibu/account/index.html @@ -22,7 +22,7 @@ {% for account in accounts %} <div class="collection-item row"> <span class="col s12 m6">{{ account.name }}</span> - <span class="col s12 m2 right-align">{{ account.costcenter }}</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"> <form action="{% url 'account_edit' account.id %}" class="left"> diff --git a/schoolapps/fibu/templates/fibu/booking/book.html b/schoolapps/fibu/templates/fibu/booking/book.html new file mode 100644 index 0000000000000000000000000000000000000000..b4c8dfdb3f0222e97209ef53b8cc2b2701796abd --- /dev/null +++ b/schoolapps/fibu/templates/fibu/booking/book.html @@ -0,0 +1,25 @@ +{% include 'partials/header.html' %} +{% load material_form %} + +<main> + + <h4>Buchung bearbeiten</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> Änderungen übernehmen + </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/schoolapps/fibu/templates/fibu/booking/check.html b/schoolapps/fibu/templates/fibu/booking/check.html index 6ed9d7d724c0dad3958bc4c3c211fb5933d35bb1..904eda49f4f1b3629b54de7f8acfab9e12707887 100755 --- a/schoolapps/fibu/templates/fibu/booking/check.html +++ b/schoolapps/fibu/templates/fibu/booking/check.html @@ -1,27 +1,38 @@ {% include 'partials/header.html' %} +{% load material_form %} <main> +{% block content %} <h4>Anträge prüfen</h4> - <div class="collection"> {% for booking in filter.qs %} - <span>{{ booking.contact }}</span> - <span>{{ booking.description }}</span> - <span>{{ booking.planned_amount }} €</span> + <div class="row"> <form method="POST"> {% csrf_token %} <input type="hidden" value="{{ booking.id }}" name="booking-id"> - {% if booking.status.id != 2 %} - <span>{{ form.costcenter }}</span> - <span> + {% if booking.status < 2 %} + <span class="col s12 m1">{{ booking.contact }}</span> + <span class="col s12 m5">{{ booking.description }}</span> + <span class="col s12 m1">{{ booking.planned_amount }}</span> + <span class="col s12 m3">{{ form.account }}</span> + <span class="col s12 m1"> <button type="submit" name="allow" class="waves-effect waves-light btn-flat btn-flat-medium" title="Annehmen"> - <i class="material-icons center green-text">check_circle</i> - </button> + <i class="material-icons right green-text">check_circle</i> + </button> + </span> + {% endif %} + {% if booking.status < 3 %} + <span class="col s12 m1"> + <button type="submit" name="deny" + class="waves-effect waves-light btn-flat btn-flat-medium" title="Ablehnen"> + <i class="material-icons right red-text">not_interested</i> + </button> </span> {% endif %} </form> + </div> {% endfor %} - </div> + {% endblock %} </main> {% include 'partials/footer.html' %} diff --git a/schoolapps/fibu/templates/fibu/booking/index.html b/schoolapps/fibu/templates/fibu/booking/index.html new file mode 100755 index 0000000000000000000000000000000000000000..331d1a74985ce7febc3cc101c80358f239834011 --- /dev/null +++ b/schoolapps/fibu/templates/fibu/booking/index.html @@ -0,0 +1,36 @@ +{% include 'partials/header.html' %} +{% load material_form %} + +<main> + {% block content %} + + <h4>Buchungen</h4> + <div class="collection"> + {% for booking in bookings %} + <a href="/fibu/booking/{{ 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> + <span class="col s1 m1 center">{{ booking.contact }}</span> + <span class="col s1 m1 badge new center-align {{ booking.getStatus.style_class }}"> + {{ booking.getStatus.name }} + </span> + <span class="col s1 m1"> + {% if booking.status < 2 %} + <form method="POST" class="left"> + {% csrf_token %} + <input type="hidden" value="{{ booking.id }}" name="booking-id"> + <button type="submit" onclick="return confirm('Wollen Sie den Antrag wirklich löschen?')" + name="cancel" class="waves-effect waves-light btn-flat btn-flat-medium" + title="Löschen"> + <i class="material-icons center red-text">cancel</i> + </button> + </form> + {% endif %} + </span> + </a> + {% endfor %} + </div> + {% endblock %} +</main> +{% include 'partials/footer.html' %} diff --git a/schoolapps/fibu/templates/fibu/costcenter/index.html b/schoolapps/fibu/templates/fibu/costcenter/index.html index ae8e40a9bfc6a70ae358c515cd762d96cf488107..3390aab7e2a307fc8606a4ee1762634f2d695442 100755 --- a/schoolapps/fibu/templates/fibu/costcenter/index.html +++ b/schoolapps/fibu/templates/fibu/costcenter/index.html @@ -3,8 +3,6 @@ <main> -{# <a href="{% url 'fibu_make_booking' %}" class="waves-effect waves-light btn green">Neuen Antrag stellen</a>#} - {% block content %} <h4>Kostenstellen</h4> diff --git a/schoolapps/fibu/templates/fibu/index.html b/schoolapps/fibu/templates/fibu/index.html index 9e72faab510181e6ab86fe841c1450fe16208c38..fee5f82a93c1dfced2096851ae9ea4c368855042 100755 --- a/schoolapps/fibu/templates/fibu/index.html +++ b/schoolapps/fibu/templates/fibu/index.html @@ -3,8 +3,6 @@ <main> -{# <a href="{% url 'fibu_make_booking' %}" class="waves-effect waves-light btn green">Neuen Antrag stellen</a>#} - {% block content %} <h4>Beantragungen von {{ user }}</h4> @@ -21,10 +19,10 @@ <div class="collection"> {% for booking in bookings %} <div class="collection-item row"> - <span class="col s12 m8">{{ booking.description }}</span> + <span class="col s12 m7">{{ booking.description }}</span> <span class="col s12 m1 right-align">{{ booking.planned_amount }} €</span> <span class="col s12 m1 badge new center-align {{ booking.getStatus.style_class }}">{{ booking.getStatus.name }}</span> - <span class="col s12 m2 right-align"> + <span class="col s12 m3"> {% if booking.status == 0 %} <form action="{% url 'booking_edit' booking.id %}" class="left"> {% csrf_token %} @@ -44,8 +42,7 @@ </button> </form> {% endif %} - </span> - <form action="" method="POST" class="col s12 m1 left"> + <form action="" method="POST"> {% csrf_token %} <input type="hidden" value="{{ booking.id }}" name="booking-id"> <input type="hidden" value="{{ booking.status }}" name="booking-status"> @@ -61,6 +58,7 @@ </button> {% endif %} </form> + </span> </div> {% endfor %} </div> diff --git a/schoolapps/fibu/urls.py b/schoolapps/fibu/urls.py index 1f2906b9106b8c87440c2094b99dd7f99c3bc1cc..99f66ef49245e378fecf2df574c873aaf098a71e 100755 --- a/schoolapps/fibu/urls.py +++ b/schoolapps/fibu/urls.py @@ -6,6 +6,8 @@ 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('costcenter', views.costcenter, name='costcenter'), path('costcenter/edit/<int:id>', views.costcenter_edit, name='costcenter_edit'), path('account', views.account, name='account'), diff --git a/schoolapps/fibu/views.py b/schoolapps/fibu/views.py index 539c86449ddf94a5e3d02e374b0c49d061bbc3ba..2497fc07709ccce283555e35af9c01d8f325e45c 100644 --- a/schoolapps/fibu/views.py +++ b/schoolapps/fibu/views.py @@ -3,7 +3,7 @@ from django.urls import reverse from django.shortcuts import render, redirect, get_object_or_404 from .models import Booking, Costcenter, Account from .filters import BookingFilter -from .forms import EditBookingForm, CheckBookingForm, EditCostcenterForm, EditAccountForm +from .forms import EditBookingForm, CheckBookingForm, BookBookingForm, EditCostcenterForm, EditAccountForm @login_required @@ -84,6 +84,9 @@ def check(request): #booking = Booking.objects.get(id=booking_id) if 'allow' in request.POST: Booking.objects.filter(id=booking_id).update(status=1) + account = request.POST['account'] + print('account:', account) + Booking.objects.filter(id=booking_id).update(account=account) elif 'deny' in request.POST: Booking.objects.filter(id=booking_id).update(status=2) # Notify user @@ -104,6 +107,32 @@ def check(request): form = CheckBookingForm() return render(request, 'fibu/booking/check.html', {'filter': bookings, 'form': form}) +@login_required +# @permission_required('fibu.book_booking') +def booking(request): + bookings = Booking.objects.filter() + context = {'bookings': bookings} + return render(request, 'fibu/booking/index.html', context) + +@login_required +#@permission_required('fibu.book_booking') +def book(request, id): + booking = get_object_or_404(Booking, id=id) + form = BookBookingForm(instance=booking) + template = 'fibu/booking/book.html' + if request.method == 'POST': + form = BookBookingForm(request.POST, request.FILES, instance=booking) + 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') diff --git a/schoolapps/templates/partials/header.html b/schoolapps/templates/partials/header.html index 391d3167c2200428ba502091c557b9160efbb796..96d3dc838b6e3f54c283fee018bb100e191f1a9c 100755 --- a/schoolapps/templates/partials/header.html +++ b/schoolapps/templates/partials/header.html @@ -178,21 +178,24 @@ </div> </li> {% endif %} - <li class="bold url-fibu_index url-booking-check1 url-booking_check2"> + <li class="bold url-fibu_index url-booking-check url-booking_book"> <a class="collapsible-header waves-effect waves-primary" href="{% url 'fibu_index' %}"><i class="material-icons">euro_symbol</i> Finanzen </a> <div class="collapsible-body"> - <ul class="collapsible collapsible-accordion"> - <div> - <li><a href="{% url 'booking_check' %}"><i class="material-icons">done</i>Buchungen prüfen</a></li> - </div> - <div> - <li><a href="{% url 'costcenter' %}"><i class="material-icons">done</i>Kostenstellen</a></li> - </div> - <div> - <li><a href="{% url 'account' %}"><i class="material-icons">done</i>Buchungskonten</a></li> - </div> + <ul> + <li class="url-booking_check"> + <a href="{% url 'booking_check' %}"><i class="material-icons">done</i>Anträge</a> + </li> + <li class="url-booking_book"> + <a href="{% url 'booking' %}"><i class="material-icons">done</i>Buchungen</a> + </li> + <li class="url-costcenter"> + <a href="{% url 'costcenter' %}"><i class="material-icons">done</i>Kostenstellen</a> + </li> + <li class="url-account"> + <a href="{% url 'account' %}"><i class="material-icons">done</i>Buchungskonten</a> + </li> </ul> </div> </li>