diff --git a/JOURNAL.md b/JOURNAL.md index eb0b5aa..99a7ea1 100644 --- a/JOURNAL.md +++ b/JOURNAL.md @@ -1063,4 +1063,35 @@ Die Session-Daten werden erst gefüllt, wenn der License Server API implementier - ✅ Select2 Dropdown mit Suchfunktion - ✅ Neue/bestehende Kunden können ausgewählt werden - ✅ E-Mail-Duplikate werden verhindert -- ✅ Sowohl Einzellizenz als auch Batch unterstützt \ No newline at end of file +- ✅ Sowohl Einzellizenz als auch Batch unterstützt + +## 2025-01-06: Automatische Ablaufdatum-Berechnung + +**Problem:** +- Manuelles Eingeben von Start- und Enddatum war umständlich +- Fehleranfällig bei der Datumseingabe +- Nicht intuitiv für Standard-Laufzeiten + +**Lösung:** +1. **Frontend-Änderungen:** + - Startdatum + Laufzeit (Zahl) + Einheit (Tage/Monate/Jahre) + - Ablaufdatum wird automatisch berechnet und angezeigt (read-only) + - Standard: 1 Jahr Laufzeit voreingestellt +2. **Backend-Validierung:** + - Server-seitige Berechnung zur Sicherheit + - Verwendung von `python-dateutil` für korrekte Monats-/Jahresberechnungen +3. **Benutzerfreundlichkeit:** + - Sofortige Neuberechnung bei Änderungen + - Visuelle Hervorhebung des berechneten Datums + +**Änderungen:** +- `index.html`: Laufzeit-Eingabe statt Ablaufdatum +- `batch_form.html`: Laufzeit-Eingabe statt Ablaufdatum +- `app.py`: Datum-Berechnung in `/create` und `/batch` Routes +- `requirements.txt`: `python-dateutil` hinzugefügt + +**Status:** +- ✅ Automatische Berechnung funktioniert +- ✅ Frontend zeigt berechnetes Datum sofort an +- ✅ Backend validiert die Berechnung +- ✅ Standardwert (1 Jahr) voreingestellt \ No newline at end of file diff --git a/v2_adminpanel/app.py b/v2_adminpanel/app.py index 558254b..ff1756b 100644 --- a/v2_adminpanel/app.py +++ b/v2_adminpanel/app.py @@ -1015,7 +1015,26 @@ def create_license(): license_key = request.form["license_key"].upper() # Immer Großbuchstaben license_type = request.form["license_type"] valid_from = request.form["valid_from"] - valid_until = request.form["valid_until"] + + # Berechne valid_until basierend auf Laufzeit + duration = int(request.form.get("duration", 1)) + duration_type = request.form.get("duration_type", "years") + + from datetime import datetime, timedelta + from dateutil.relativedelta import relativedelta + + start_date = datetime.strptime(valid_from, "%Y-%m-%d") + + if duration_type == "days": + end_date = start_date + timedelta(days=duration) + elif duration_type == "months": + end_date = start_date + relativedelta(months=duration) + else: # years + end_date = start_date + relativedelta(years=duration) + + # Ein Tag abziehen, da der Starttag mitgezählt wird + end_date = end_date - timedelta(days=1) + valid_until = end_date.strftime("%Y-%m-%d") # Validiere License Key Format if not validate_license_key(license_key): @@ -1110,7 +1129,26 @@ def batch_licenses(): license_type = request.form["license_type"] quantity = int(request.form["quantity"]) valid_from = request.form["valid_from"] - valid_until = request.form["valid_until"] + + # Berechne valid_until basierend auf Laufzeit + duration = int(request.form.get("duration", 1)) + duration_type = request.form.get("duration_type", "years") + + from datetime import datetime, timedelta + from dateutil.relativedelta import relativedelta + + start_date = datetime.strptime(valid_from, "%Y-%m-%d") + + if duration_type == "days": + end_date = start_date + timedelta(days=duration) + elif duration_type == "months": + end_date = start_date + relativedelta(months=duration) + else: # years + end_date = start_date + relativedelta(years=duration) + + # Ein Tag abziehen, da der Starttag mitgezählt wird + end_date = end_date - timedelta(days=1) + valid_until = end_date.strftime("%Y-%m-%d") # Sicherheitslimit if quantity < 1 or quantity > 100: diff --git a/v2_adminpanel/requirements.txt b/v2_adminpanel/requirements.txt index 342f0e3..1dc87d9 100644 --- a/v2_adminpanel/requirements.txt +++ b/v2_adminpanel/requirements.txt @@ -8,3 +8,4 @@ openpyxl cryptography apscheduler requests +python-dateutil diff --git a/v2_adminpanel/templates/batch_form.html b/v2_adminpanel/templates/batch_form.html index ee0caa9..23165ac 100644 --- a/v2_adminpanel/templates/batch_form.html +++ b/v2_adminpanel/templates/batch_form.html @@ -66,14 +66,28 @@ -
+
-
+
+ + +
+ +
+ + +
+ +
- +
@@ -111,15 +125,47 @@