diff --git a/app/stiftung/views.py b/app/stiftung/views.py index 3362bb9..0658362 100644 --- a/app/stiftung/views.py +++ b/app/stiftung/views.py @@ -1200,6 +1200,73 @@ def destinataer_update(request, pk): destinataer = get_object_or_404(Destinataer, pk=pk) if request.method == "POST": form = DestinataerForm(request.POST, instance=destinataer) + + # Handle AJAX requests + if request.headers.get('X-Requested-With') == 'XMLHttpRequest': + if form.is_valid(): + try: + destinataer = form.save() + + # Auto-create a Destinatärunterstützung if conditions are met + if ( + destinataer.aktiv + and destinataer.unterstuetzung_bestaetigt + and destinataer.standard_konto + and destinataer.vierteljaehrlicher_betrag + and destinataer.vierteljaehrlicher_betrag > 0 + ): + from decimal import Decimal + from stiftung.models import DestinataerUnterstuetzung + + heute = timezone.now().date() + beschreibung = f"Vierteljährliche Vorauszahlung für {destinataer.get_full_name()}" + # ensure only one upcoming planned entry; update if one exists + existing = ( + DestinataerUnterstuetzung.objects.filter( + destinataer=destinataer, status="geplant" + ) + .order_by("faellig_am") + .first() + ) + if existing: + existing.konto = destinataer.standard_konto + existing.betrag = Decimal(destinataer.vierteljaehrlicher_betrag) + existing.faellig_am = heute + existing.beschreibung = beschreibung + existing.save() + else: + DestinataerUnterstuetzung.objects.create( + destinataer=destinataer, + konto=destinataer.standard_konto, + betrag=Decimal(destinataer.vierteljaehrlicher_betrag), + faellig_am=heute, + status="geplant", + beschreibung=beschreibung, + ) + + return JsonResponse({ + 'success': True, + 'message': f'Destinatär "{destinataer.get_full_name()}" wurde erfolgreich aktualisiert.' + }) + + except Exception as e: + return JsonResponse({ + 'success': False, + 'error': f'Fehler beim Speichern: {str(e)}' + }) + else: + # Return form errors for AJAX requests + errors = [] + for field, field_errors in form.errors.items(): + for error in field_errors: + errors.append(f'{form[field].label}: {error}') + + return JsonResponse({ + 'success': False, + 'error': 'Formular enthält Fehler: ' + '; '.join(errors) + }) + + # Handle regular form submission if form.is_valid(): destinataer = form.save() try: diff --git a/app/templates/stiftung/destinataer_detail.html b/app/templates/stiftung/destinataer_detail.html index cc9ce91..fe462bc 100644 --- a/app/templates/stiftung/destinataer_detail.html +++ b/app/templates/stiftung/destinataer_detail.html @@ -17,9 +17,18 @@ Neue Förderung - + + + + + + Zurück zur Liste @@ -29,178 +38,429 @@
- -
-
-
- Persönliche Informationen -
-
-
-
-
-

Vorname: {{ destinataer.vorname }}

-

Nachname: {{ destinataer.nachname }}

- {% if destinataer.geburtsdatum %} -

Geburtsdatum: {{ destinataer.geburtsdatum|date:"d.m.Y" }}

- {% endif %} -

Familienzweig: - {{ destinataer.get_familienzweig_display }} -

-
-
-

Status: - {% if destinataer.aktiv %} - Aktiv - {% else %} - Inaktiv - {% endif %} -

-

Berufsgruppe: - {{ destinataer.get_berufsgruppe_display }} -

+ +
+ {% csrf_token %} + + +
+
+
+ Persönliche Informationen +
+
+
+
+
+ +

+ Vorname: + {{ destinataer.vorname }} + +

+ + +

+ Nachname: + {{ destinataer.nachname }} + +

+ + +

+ Geburtsdatum: + + {% if destinataer.geburtsdatum %} + {{ destinataer.geburtsdatum|date:"d.m.Y" }} + {% else %} + Nicht angegeben + {% endif %} + + +

+ + +

+ Familienzweig: + + {{ destinataer.get_familienzweig_display }} + + +

+
+
+ +

+ Status: + + {% if destinataer.aktiv %} + Aktiv + {% else %} + Inaktiv + {% endif %} + +

+

+ + +

+ Berufsgruppe: + + {{ destinataer.get_berufsgruppe_display }} + + +

+
-
- -
-
-
- Kontaktinformationen -
-
-
-
-
- {% if destinataer.email %} -

E-Mail: {{ destinataer.email }}

- {% endif %} - {% if destinataer.telefon %} -

Telefon: {{ destinataer.telefon }}

- {% endif %} + +
+
+
+ Kontaktinformationen +
+
+
+
+
+ +

+ E-Mail: + + {% if destinataer.email %} + {{ destinataer.email }} + {% else %} + Nicht angegeben + {% endif %} + + +

+ + +

+ Telefon: + + {% if destinataer.telefon %} + {{ destinataer.telefon }} + {% else %} + Nicht angegeben + {% endif %} + + +

+
+
+ +

+ IBAN: + + {% if destinataer.iban %} + {{ destinataer.iban }} + {% else %} + Nicht angegeben + {% endif %} + + +

+
-
- {% if destinataer.iban %} -

IBAN: {{ destinataer.iban }}

- {% endif %} + + +
+
+

+ Adresse: + + {% if destinataer.adresse %} +
{{ destinataer.adresse|linebreaks }} + {% else %} + Nicht angegeben + {% endif %} +
+ +

+
- {% if destinataer.strasse or destinataer.plz or destinataer.ort %} -

Adresse:
- {% if destinataer.strasse %}{{ destinataer.strasse }}{% endif %} - {% if destinataer.plz or destinataer.ort %}
{% endif %} - {% if destinataer.plz %}{{ destinataer.plz }}{% endif %} - {% if destinataer.plz and destinataer.ort %} {% endif %} - {% if destinataer.ort %}{{ destinataer.ort }}{% endif %} +

+ + +
+
+
+ Berufliche Informationen +
+
+
+
+
+ +

+ Ausbildungsstand: + + {% if destinataer.ausbildungsstand %} + {{ destinataer.ausbildungsstand }} + {% else %} + Nicht angegeben + {% endif %} + + +

+ + +

+ Institution/Organisation: + + {% if destinataer.institution %} + {{ destinataer.institution }} + {% else %} + Nicht angegeben + {% endif %} + + +

+
+
+ +

+ Projektbeschreibung: + + {% if destinataer.projekt_beschreibung %} +
{{ destinataer.projekt_beschreibung|linebreaks }} + {% else %} + Nicht angegeben + {% endif %} +
+ +

+
+
+
+
+ + +
+
+
+ Finanzielle Informationen +
+
+
+
+
+ +

+ Jährliches Einkommen: + + {% if destinataer.jaehrliches_einkommen %} + €{{ destinataer.jaehrliches_einkommen|floatformat:2 }} + {% else %} + Nicht angegeben + {% endif %} + + +

+ + +

+ Vermögen: + + {% if destinataer.vermoegen %} + €{{ destinataer.vermoegen|floatformat:2 }} + {% else %} + Nicht angegeben + {% endif %} + + +

+ + +

+ Haushaltsgröße: + + {% if destinataer.haushaltsgroesse %} + {{ destinataer.haushaltsgroesse }} + {% else %} + Nicht angegeben + {% endif %} + + +

+
+
+ +

+ Finanzielle Notlage: + + {% if destinataer.finanzielle_notlage %} + + Ja + + {% else %} + + Nein + + {% endif %} + +

+

+ + +

+ Vierteljährlicher Betrag: + + {% if destinataer.vierteljaehrlicher_betrag %} + €{{ destinataer.vierteljaehrlicher_betrag|floatformat:2 }} + {% else %} + Nicht angegeben + {% endif %} + + +

+ + +

+ Unterstützung bestätigt: + + {% if destinataer.unterstuetzung_bestaetigt %} + Ja + {% else %} + Nein + {% endif %} + +

+

+ + +

+ Standardkonto: + + {% if destinataer.standard_konto %} + {{ destinataer.standard_konto }} + {% else %} + Nicht angegeben + {% endif %} + + +

+
+
+
+
+ + +
+
+
+ Studiennachweis & Voraussetzungen +
+
+
+
+
+ +

+ Abkömmling gem. Satzung: + + {% if destinataer.ist_abkoemmling %} + Ja + {% else %} + Nein + {% endif %} + +

+

+ + +

+ Studiennachweis erforderlich: + + {% if destinataer.studiennachweis_erforderlich %} + Ja + {% else %} + Nein + {% endif %} + +

+

+
+
+ +

+ Letzter Nachweis: + + {% if destinataer.letzter_studiennachweis %} + {{ destinataer.letzter_studiennachweis|date:"d.m.Y" }} + {% else %} + Nicht angegeben + {% endif %} + + +

+
+
+
+
+ + +
+
+
+ Notizen +
+
+
+

+ + {% if destinataer.notizen %} + {{ destinataer.notizen|linebreaks }} + {% else %} + Keine Notizen vorhanden + {% endif %} + +

- {% endif %} -
-
- - -
-
-
- Berufliche Informationen -
-
-
-
-
- {% if destinataer.ausbildungsstand %} -

Ausbildungsstand: {{ destinataer.ausbildungsstand }}

- {% endif %} - {% if destinataer.institution %} -

Institution/Organisation: {{ destinataer.institution }}

- {% endif %} -
-
- {% if destinataer.projekt_beschreibung %} -

Projektbeschreibung:
{{ destinataer.projekt_beschreibung|linebreaks }}

- {% endif %} -
-
- - -
-
-
- Finanzielle Informationen -
-
-
-
-
- {% if destinataer.jaehrliches_einkommen %} -

Jährliches Einkommen: €{{ destinataer.jaehrliches_einkommen|floatformat:2 }}

- {% endif %} - {% if destinataer.monatliche_bezuege %} -

Monatliche Bezüge: €{{ destinataer.monatliche_bezuege|floatformat:2 }}

- {% endif %} - {% if destinataer.vermoegen %} -

Vermögen: €{{ destinataer.vermoegen|floatformat:2 }}

- {% endif %} -
-
-

Finanzielle Notlage: - {% if destinataer.finanzielle_notlage %} - - Ja - - {% else %} - - Nein - - {% endif %} -

- {% if destinataer.vierteljaehrlicher_betrag %} -

Vierteljährlicher Betrag: €{{ destinataer.vierteljaehrlicher_betrag|floatformat:2 }}

- {% endif %} -

Unterstützung bestätigt: - {% if destinataer.unterstuetzung_bestaetigt %} - Ja - {% else %} - Nein - {% endif %} -

- {% if destinataer.standard_konto %} -

Standardkonto: {{ destinataer.standard_konto }}

- {% endif %} -
-
-
-
- - -
-
-
- Studiennachweis & Voraussetzungen -
-
-
-
-
-

Abkömmling gem. Satzung: - {% if destinataer.ist_abkoemmling %}Ja{% else %}Nein{% endif %} -

-

Haushaltsgröße: {{ destinataer.haushaltsgroesse }}

-
-
-

Studiennachweis erforderlich: - {% if destinataer.studiennachweis_erforderlich %}Ja{% else %}Nein{% endif %} -

- {% if destinataer.letzter_studiennachweis %} -

Letzter Nachweis: {{ destinataer.letzter_studiennachweis|date:"d.m.Y" }}

- {% endif %} -
-
-
-
+ {% if foerderungen %} @@ -513,4 +773,200 @@
+{% endblock %} + +{% block javascript %} + + + {% endblock %} diff --git a/app/templates/stiftung/destinataer_form.html b/app/templates/stiftung/destinataer_form.html index 1afa52a..5608b12 100644 --- a/app/templates/stiftung/destinataer_form.html +++ b/app/templates/stiftung/destinataer_form.html @@ -28,382 +28,428 @@ Destinatär-Daten
-
+
+ + +
{% csrf_token %} -
-
-
- Persönliche Informationen -
+
+

+ + Persönliche Informationen +

+
+
+ + {{ form.vorname }} + {% if form.vorname.errors %} +
+ {% for error in form.vorname.errors %} + {{ error }} + {% endfor %} +
+ {% endif %} +
+
+ + {{ form.nachname }} + {% if form.nachname.errors %} +
+ {% for error in form.nachname.errors %} + {{ error }} + {% endfor %} +
+ {% endif %} +
+
+ + {{ form.geburtsdatum }} + {% if form.geburtsdatum.errors %} +
+ {% for error in form.geburtsdatum.errors %} + {{ error }} + {% endfor %} +
+ {% endif %} +
+
+ + {{ form.familienzweig }} + {% if form.familienzweig.errors %} +
+ {% for error in form.familienzweig.errors %} + {{ error }} + {% endfor %} +
+ {% endif %} +
- -
- - {{ form.vorname }} - {% if form.vorname.errors %} -
- {% for error in form.vorname.errors %} - {{ error }} - {% endfor %} -
- {% endif %} - {% if form.vorname.help_text %} -
{{ form.vorname.help_text }}
- {% endif %} -
- -
- - {{ form.nachname }} - {% if form.nachname.errors %} -
- {% for error in form.nachname.errors %} - {{ error }} - {% endfor %} -
- {% endif %} - {% if form.nachname.help_text %} -
{{ form.nachname.help_text }}
- {% endif %} -
- -
- - {{ form.geburtsdatum }} - {% if form.geburtsdatum.errors %} -
- {% for error in form.geburtsdatum.errors %} - {{ error }} - {% endfor %} -
- {% endif %} - {% if form.geburtsdatum.help_text %} -
{{ form.geburtsdatum.help_text }}
- {% endif %} -
- -
- - {{ form.familienzweig }} - {% if form.familienzweig.errors %} -
- {% for error in form.familienzweig.errors %} - {{ error }} - {% endfor %} -
- {% endif %} - {% if form.familienzweig.help_text %} -
{{ form.familienzweig.help_text }}
- {% endif %} -
-
-
-
-
- Kontaktinformationen -
-
- -
- - {{ form.email }} - {% if form.email.errors %} -
- {% for error in form.email.errors %} - {{ error }} - {% endfor %} -
- {% endif %} - {% if form.email.help_text %} -
{{ form.email.help_text }}
- {% endif %} -
- -
- - {{ form.telefon }} - {% if form.telefon.errors %} -
- {% for error in form.telefon.errors %} - {{ error }} - {% endfor %} -
- {% endif %} - {% if form.telefon.help_text %} -
{{ form.telefon.help_text }}
- {% endif %} -
- -
- - {{ form.iban }} - {% if form.iban.errors %} -
- {% for error in form.iban.errors %} - {{ error }} - {% endfor %} -
- {% endif %} - {% if form.iban.help_text %} -
{{ form.iban.help_text }}
- {% endif %} -
- -
- - {{ form.adresse }} - {% if form.adresse.errors %} -
- {% for error in form.adresse.errors %} - {{ error }} - {% endfor %} -
- {% endif %} - {% if form.adresse.help_text %} -
{{ form.adresse.help_text }}
- {% endif %} -
-
- - -
-
-
- Berufliche Informationen -
-
- -
- - {{ form.berufsgruppe }} - {% if form.berufsgruppe.errors %} -
- {% for error in form.berufsgruppe.errors %} - {{ error }} - {% endfor %} -
- {% endif %} - {% if form.berufsgruppe.help_text %} -
{{ form.berufsgruppe.help_text }}
- {% endif %} -
- -
- - {{ form.ausbildungsstand }} - {% if form.ausbildungsstand.errors %} -
- {% for error in form.ausbildungsstand.errors %} - {{ error }} - {% endfor %} -
- {% endif %} - {% if form.ausbildungsstand.help_text %} -
{{ form.ausbildungsstand.help_text }}
- {% endif %} -
- -
- - {{ form.institution }} - {% if form.institution.errors %} -
- {% for error in form.institution.errors %} - {{ error }} - {% endfor %} -
- {% endif %} - {% if form.institution.help_text %} -
{{ form.institution.help_text }}
- {% endif %} -
- -
- - {{ form.projekt_beschreibung }} - {% if form.projekt_beschreibung.errors %} -
- {% for error in form.projekt_beschreibung.errors %} - {{ error }} - {% endfor %} -
- {% endif %} - {% if form.projekt_beschreibung.help_text %} -
{{ form.projekt_beschreibung.help_text }}
- {% endif %} -
-
- - -
-
-
- Finanzielle Informationen -
-
- -
- - {{ form.jaehrliches_einkommen }} - {% if form.jaehrliches_einkommen.errors %} -
- {% for error in form.jaehrliches_einkommen.errors %} - {{ error }} - {% endfor %} -
- {% endif %} - {% if form.jaehrliches_einkommen.help_text %} -
{{ form.jaehrliches_einkommen.help_text }}
- {% endif %} -
- -
-
- {{ form.finanzielle_notlage }} -