From 2e3ac42c1b2e89ee93e4908e8b695015d94ed94d Mon Sep 17 00:00:00 2001 From: "holger.trampe" Date: Fri, 2 Oct 2020 11:15:53 +0200 Subject: [PATCH] Abrechnung inkl. Abbestellen fertig --- dasettings/forms.py | 8 +++ .../dasettings/bill_removepayplan.html | 36 ++++++++++++ .../templates/dasettings/calc_content.html | 27 +++++---- .../dasettings/dasettings_billplan.html | 1 + dasettings/urls.py | 3 +- dasettings/views.py | 57 +++++++++++++------ 6 files changed, 102 insertions(+), 30 deletions(-) create mode 100644 dasettings/templates/dasettings/bill_removepayplan.html diff --git a/dasettings/forms.py b/dasettings/forms.py index 009b71a..0fcfde6 100644 --- a/dasettings/forms.py +++ b/dasettings/forms.py @@ -80,7 +80,15 @@ class AgencyBillPlan(forms.ModelForm): self.fields['contract'] = forms.BooleanField(required=True, label="Auftragsdatenverarbeitung akzeptieren") +class AgencyEndBillPlan(forms.ModelForm): + class Meta: + model = Agency + fields = ['paymentplan'] + def __init__(self, *args, **kwargs): + super(AgencyEndBillPlan, self).__init__(*args, **kwargs) + self.fields['paymentplan'] = forms.CharField(initial=None, required=True, widget=forms.HiddenInput()) + # Form für die Benachrichtigungseinstellungen ''' diff --git a/dasettings/templates/dasettings/bill_removepayplan.html b/dasettings/templates/dasettings/bill_removepayplan.html new file mode 100644 index 0000000..982bdcf --- /dev/null +++ b/dasettings/templates/dasettings/bill_removepayplan.html @@ -0,0 +1,36 @@ +{% extends "users/base.html" %} +{% load crispy_forms_tags %} +{% load counter_tag %} +{% block content %} +
+

Zahlplan abbestellen

+
+
+ {% csrf_token %} + {{form|crispy}} +

Bestellen Sie den Zahlplan ab, erhalten Sie keine automatische Verlängerung. Beachten Sie, dass sich Ihre Mitarbeiter spätestens zwei Wochen nach dem letzten Tag des bezahlten Zeitraums Ihre Digitale Agentur nicht mehr anmelden können.

+

Sie können jederzeit einen neuen Zahlplan auswählen. Dieser beginnt dann frühestens nach dem Tag, an dem der aktuelle Plan ausläuft.

+
+
+ Abbrechen +   +
+
+
+{% endblock content %} + + + + + + + + + + + + + + + + diff --git a/dasettings/templates/dasettings/calc_content.html b/dasettings/templates/dasettings/calc_content.html index ef8a378..77c5078 100644 --- a/dasettings/templates/dasettings/calc_content.html +++ b/dasettings/templates/dasettings/calc_content.html @@ -11,7 +11,7 @@
Ihr Betrag

Ihr monatlicher Nutzungsbeitrag setzt sich wie folgt zusammen:

- +
@@ -35,17 +35,19 @@
Ihre Zahlungsweise
{% getNextMonth request.user.profile.agency as nextMonth %} - Ihre Agentur wurde am {{ request.user.profile.agency.registerdate|date:"d.m.Y" }} registriert. - {% if paymentplan == "" %} - Es wurde noch keine Zahlungsweise ausgewählt. Sie können die Digitale Agentur bis zum {{nextMonth|date:"d.m.Y"}} kostenlos nutzen. Möchten Sie die Digitale Agentur auch nach diesem Zeitraum nutzen, wählen Sie bitte einen Zahlplan aus. -
- Zahlplan jetzt auswählen + {% if paymentplan == None and bills|length == 0 %} + Es wurde noch keine Zahlungsweise ausgewählt und keine Rechnungen gefunden. Sie können die Digitale Agentur bis zum {{nextMonth|date:"d.m.Y"}} kostenlos nutzen. Möchten Sie die Digitale Agentur auch nach diesem Zeitraum nutzen, wählen Sie bitte einen Zahlplan aus. +
+ Zahlplan jetzt auswählen + {% elif bills|length > 0 and paymentplan == "" %} + Ihre aktuelle Rechnungen erlaubt Ihnen die Nutzung der digitalen Agentur bis zum {{bills.0.end|date:"d.m.Y"}}. Danach wird der Zugang gesperrt. Legen Sie einen neuen Zahlplan fest, um die digitale Agentur auch weiterhin zu nutzen.
+ Zahlplan jetzt auswählen {% else %} -
- Ausgewählter Zahlungsplan: {{request.user.profile.agency.paymentplan}} Monat{% if request.user.profile.agency.paymentplan > 1 %}e{% endif %}
- Nächste Rechnungserstellung am: {{bills.0.end|date:"d.m.Y"}}
- Zahlplan abbestellen +
+ Ausgewählter Zahlungsplan: {{request.user.profile.agency.paymentplan}} Monat{% if request.user.profile.agency.paymentplan > 1 %}e{% endif %}
+ Nächste Rechnungserstellung am {{bills.0.end|date:"d.m.Y"}}
+ Zahlplan abbestellen {% endif %}
Fragen, Hilfe, Kündigung
@@ -60,7 +62,7 @@
E-Mail-Adresse
- Ihre Rechnungen werden automatisch an folgende E-Mailadresse gesendet.
+ Informationen über neue Rechnungen werden automatisch an folgende E-Mailadresse gesendet.
{% if request.user.profile.agency.payment_address == None %} Es wurde keine Adresse hinterlegt. Die Adresse wird an die Agenturadresse versendet: {{request.user.profile.agency.agency_email}} {% else %} @@ -74,6 +76,9 @@
Rechnungen
+ {% if bills|length == 0 %} + Es liegen keine Rechnungen vor. + {% endif %} {% for bill in bills %} Rechnung vom {{bill.billdate|date:"d.m.Y"}} ({{bill.billnumber}}) - {% if bill.billstatus == "open" %} Offen {% elif bill.billstatus == "paid" %} Bezahlt {% endif %}
{% endfor %} diff --git a/dasettings/templates/dasettings/dasettings_billplan.html b/dasettings/templates/dasettings/dasettings_billplan.html index 05e6eb3..fc24071 100644 --- a/dasettings/templates/dasettings/dasettings_billplan.html +++ b/dasettings/templates/dasettings/dasettings_billplan.html @@ -54,6 +54,7 @@

Mit Klick auf dem Button Jetzt kostenpflichtig bestellen wird eine Rechnung für Ihre Agentur generiert und per E-Mail an die hinterlegte Rechnungs-E-Mailadresse oder an die Agentur-E-Mailadresse versendet. Der Rechnungsbetrag muss innerhalb von 14 Tagen beglichen werden.


+ Beginn des Leistungszeitraums: {{start|date:"d.m.Y"}}
{% loadFinalMoney user as fm %} Rechnungsbetrag: {{fm|floatformat:2|intcomma}} €
diff --git a/dasettings/urls.py b/dasettings/urls.py index 6fbd7f6..b169384 100644 --- a/dasettings/urls.py +++ b/dasettings/urls.py @@ -3,7 +3,7 @@ from django.contrib.auth import views as auth_views from django.contrib.auth.decorators import login_required, permission_required from . import views from .views import FreeDayDeleteView, AbsenceReasonDeleteView, AbsenceReasonUpdateView, AbsenceReasonAddView -from .views import NewUserFirstStep, UserProfileUpdate, UserChangeMain, BillMailUpdate, BillPlanUpdate, GetBill, GetBillPDF +from .views import NewUserFirstStep, UserProfileUpdate, UserChangeMain, BillMailUpdate, BillPlanUpdate, GetBill, GetBillPDF, BillPlanEnd ''' Permissions definiert in models.py bei USERS und dann hier vor die View geschrieben! ''' @@ -37,5 +37,6 @@ urlpatterns = [ path('ag/billplan/', permission_required('users.agencyinfo')(BillPlanUpdate.as_view()), name='ag-billplanupdate'), path('ag/getbill/', permission_required('users.agencyinfo')(GetBill), name='ag-getbill'), path('ag/getbillpdf/', permission_required('users.agencyinfo')(GetBillPDF), name='ag-getbillpdf'), + path('ag/billplanend/', permission_required('users.agencyinfo')(BillPlanEnd.as_view()), name='ag-billplanend'), ] \ No newline at end of file diff --git a/dasettings/views.py b/dasettings/views.py index f9c7898..9f9947f 100644 --- a/dasettings/views.py +++ b/dasettings/views.py @@ -1,7 +1,7 @@ from django.shortcuts import render, redirect from django.contrib.auth.decorators import login_required from django.http import HttpResponseRedirect,HttpResponse, JsonResponse -from .forms import UsersSelfChangeForm, UsersNotificationFormStandard, AgencyGroupPerms, AgencyModulsForm, UserNewUserForm, UserProfileForm, AgencyNetworkForm, AgencyOrganigrammForm, UserTimeForm, AbsenceReasonForm, UsersNotificationFormNews, UsersNotificationFormFiles, UsersNotificationFormMessages ,UsersNotificationFormOrganizer, UsersNotificationFormChat, UsersNotificationFormAbTime, UsersNotificationFormGroups, UsersNotificationFormAgn, UsersNotificationFormTasks, AgencyBillMail, AgencyBillPlan +from .forms import UsersSelfChangeForm, UsersNotificationFormStandard, AgencyGroupPerms, AgencyModulsForm, UserNewUserForm, UserProfileForm, AgencyNetworkForm, AgencyOrganigrammForm, UserTimeForm, AbsenceReasonForm, UsersNotificationFormNews, UsersNotificationFormFiles, UsersNotificationFormMessages ,UsersNotificationFormOrganizer, UsersNotificationFormChat, UsersNotificationFormAbTime, UsersNotificationFormGroups, UsersNotificationFormAgn, UsersNotificationFormTasks, AgencyBillMail, AgencyBillPlan, AgencyEndBillPlan from django.contrib import messages from django.contrib.auth import update_session_auth_hash from django.contrib.auth.forms import PasswordChangeForm @@ -33,6 +33,8 @@ from timemanagement.forms import AddFreeDayForm from django.urls import reverse_lazy import re import json +from django.conf import settings # import the settings file + def randomString(stringLength=10): """Generate a random string of fixed length """ @@ -250,7 +252,7 @@ def DASettings(request): # HEADERS CURL headers = { - 'Authorization': 'Bearer 8f9ba01f-9e84-42c7-9548-48c254f14c19', + 'Authorization': 'Bearer ' + settings.LEX_API, 'Content-Type': 'application/json', 'Accept': 'application/json', } @@ -270,7 +272,7 @@ from django.http import FileResponse, Http404 def GetBill(request, pk): # HEADERS CURL headers = { - 'Authorization': 'Bearer 8f9ba01f-9e84-42c7-9548-48c254f14c19', + 'Authorization': 'Bearer ' + settings.LEX_API, 'Content-Type': 'application/json', 'Accept': 'application/json', } @@ -288,18 +290,15 @@ def GetBill(request, pk): return render(request, 'dasettings/bill_single.html', context) -from fpdf import FPDF, HTMLMixin -class HtmlPdf(FPDF, HTMLMixin): - pass - import io as BytesIO import base64 from django.http import HttpResponse + @login_required def GetBillPDF(request, pk): headers = { - 'Authorization': 'Bearer 8f9ba01f-9e84-42c7-9548-48c254f14c19', + 'Authorization': 'Bearer ' + settings.LEX_API, 'Content-Type': 'application/json', 'Accept': 'application/json', } @@ -1548,6 +1547,17 @@ def getBill(request, billid): else: pass ''' +class BillPlanEnd(UpdateView): + model = Agency + success_url = reverse_lazy('dasettings') + form_class = AgencyEndBillPlan + template_name = "dasettings/bill_removepayplan.html" + + def form_valid(self, form): + self.object.paymentplan = None + messages.success(self.request, f"Zahlplan abbestellt!") + + return super().form_valid(form) from dateutil.relativedelta import * class BillPlanUpdate(UpdateView): @@ -1561,6 +1571,11 @@ class BillPlanUpdate(UpdateView): agency = self.request.user.profile.agency month = agency.registerdate + + # Wenn die Agentur noch KEINE Lexoffice-ID hat, dann ist der Freimonat noch nicht durch. + if agency.lexofficeid == "": + month = month + relativedelta(months=1) + next_month = month + relativedelta(months=1) voucher_date = next_month.strftime("%Y-%m-%d") @@ -1575,7 +1590,7 @@ class BillPlanUpdate(UpdateView): # HEADERS CURL headers = { - 'Authorization': 'Bearer 8f9ba01f-9e84-42c7-9548-48c254f14c19', + 'Authorization': 'Bearer ' + settings.LEX_API, 'Content-Type': 'application/json', 'Accept': 'application/json', } @@ -1591,14 +1606,8 @@ class BillPlanUpdate(UpdateView): voucher_date_today = date.today().strftime("%Y-%m-%d") # TODO: Nachgebuchte Mitarbeiter # TODO: Was passiert bei Änderungen der Agenturdaten? - # TODO: Kündigungsmöglichkeit, den Zahlplan zu beenden - # TODO: voucherDate muss HEUTE sein, Leistungszeitraum aber das von der Agenturregistrierung + # DataJSON - ''' - - Bei Beschreibung noch Zeitraum vom XX.XX.XXXX bis XX.XX.XXXX - - ''' monthword = "Monate" if form.cleaned_data['paymentplan'] == "1": monthword = "Monat" @@ -1670,7 +1679,7 @@ class BillPlanUpdate(UpdateView): # HEADERS CURL headers = { - 'Authorization': 'Bearer 8f9ba01f-9e84-42c7-9548-48c254f14c19', + 'Authorization': 'Bearer ' + settings.LEX_API, 'Content-Type': 'application/json', 'Accept': 'application/json', } @@ -1697,7 +1706,19 @@ class BillPlanUpdate(UpdateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context.update({'active_link' : 'dasettings'}) + + # Rechnungsbegin setzen + agency = self.request.user.profile.agency + + month = agency.registerdate + + # Wenn die Agentur noch KEINE Lexoffice-ID hat, dann ist der Freimonat noch nicht durch. + if agency.lexofficeid == "": + month = month + relativedelta(months=1) + + + context.update({'active_link' : 'dasettings', 'start' : month}) + return context
Grundbetrag (inkl. 3 Nutzer)21,00 €