diff --git a/db.sqlite3 b/db.sqlite3 index e42d6e9..ce6b742 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/mensa_app/templates/mensa_app/bestell_summary.html b/mensa_app/templates/mensa_app/bestell_summary.html new file mode 100644 index 0000000..67c693b --- /dev/null +++ b/mensa_app/templates/mensa_app/bestell_summary.html @@ -0,0 +1,81 @@ + + + + + + Bestell-Zusammenfassung + + + + +
+ +
+
+

Bestell-Check für den {{ target_date|date:"d.m.Y" }}

+ +
+
+ + +
+
+
+
+
Gesamtanzahl Bestellungen
+

{{ total_bestellungen }}

+
+
+
+
+
+
+
Erwarteter Umsatz
+

{{ total_umsatz|floatformat:2 }} €

+
+
+
+
+ + +
+
Details pro Gericht
+
+ + + + + + + + + + + {% for stat in summary_stats %} + + + + + + + {% empty %} + + + + {% endfor %} + +
GerichtKategorieMengeUmsatz
{{ stat.menue__gericht__name }}{{ stat.menue__gericht__kategorie__name }}{{ stat.anzahl }}{{ stat.umsatz|floatformat:2 }} €
Keine Bestellungen für diesen Tag vorhanden.
+
+
+ +
+ ← Zurück zur Speisekarte +
+
+ + + diff --git a/mensa_app/templates/mensa_app/speiseplan.html b/mensa_app/templates/mensa_app/speiseplan.html new file mode 100644 index 0000000..e5918a1 --- /dev/null +++ b/mensa_app/templates/mensa_app/speiseplan.html @@ -0,0 +1,92 @@ + + + + + + Mensa Speiseplan + + + + +
+
+
+ + +
+
+

Speiseplan für den
{{ target_date|date:"d.m.Y" }}

+ +
+ + {% if prev_date %} + « Vorheriger Tag + {% else %} + + {% endif %} + + + Heute + + + {% if next_date %} + Nächster Tag » + {% else %} + + {% endif %} +
+
+
+ + +
+
Tagesmenüs
+
+ + + + + + + + + + {% for menue in menues_day %} + + + + + + {% empty %} + + + + {% endfor %} + +
GerichtKategoriePreis
{{ menue.gericht.name }}{{ menue.gericht.kategorie.name }}{{ menue.preis|floatformat:2 }} €
Keine Tagesmenüs für diesen Tag geplant.
+
+
+ + +
+
Immer verfügbar (Dauerangebote)
+
+
    + {% for gericht in dauerangebote %} +
  • + {{ gericht.name }} + Verfügbar +
  • + {% empty %} +
  • Momentan keine Dauerangebote.
  • + {% endfor %} +
+
+
+ +
+
+
+ + + diff --git a/mensa_app/urls.py b/mensa_app/urls.py index 60835bc..c59a541 100644 --- a/mensa_app/urls.py +++ b/mensa_app/urls.py @@ -1,8 +1,10 @@ from django.urls import path from .views import GerichtListView from .views import SpeiseplanView # Achte auf den neuen Klassennamen! +from .views import BestellSummaryView urlpatterns = [ - path('speisekarte/', GerichtListView.as_view(), name='gericht_list'), + path('speisekarte/', GerichtListView.as_view(), name='speisekarte'), path('speiseplan/', SpeiseplanView.as_view(), name='speiseplan'), + path('bestellungen/summary/', BestellSummaryView.as_view(), name='bestell_summary'), ] diff --git a/mensa_app/views.py b/mensa_app/views.py index 5cb7a01..662af6f 100644 --- a/mensa_app/views.py +++ b/mensa_app/views.py @@ -48,3 +48,54 @@ class SpeiseplanView(TemplateView): context['next_date'] = next_tag.datum.strftime('%Y-%m-%d') if next_tag else None return context + + +from django.views.generic import TemplateView +from django.utils import timezone +from django.db.models import Count, Sum +from datetime import datetime +from .models import Bestellung, SpeiseplanTag, Gericht, Menue + +class BestellSummaryView(TemplateView): + template_name = 'mensa_app/bestell_summary.html' + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + + # 1. Datum aus der URL holen (wie beim Speiseplan) + date_str = self.request.GET. get('datum') + if date_str: + try: + target_date = datetime.strptime(date_str, '%Y-%m-%d').date() + except ValueError: + target_date = timezone.now().date() + else: + target_date = timezone.now().date() + + context['target_date'] = target_date + + # 2. Aggregation: Bestellungen nach Gericht gruppieren + # Wir suchen alle Bestellungen, deren Menü am target_date stattfindet + summary_stats = ( + Bestellung.objects.filter(menue__tag__datum=target_date) + .values('menue__gericht__name', 'menue__gericht__kategorie__name') # Gruppierung nach Name & Kategorie + .annotate( + anzahl=Count('id'), # Wie viele wurden bestellt? + umsatz=Sum('menue__preis') # Was macht das für einen Umsatz? + ) + .order_by('menue__gericht__name') + ) + context['summary_stats'] = summary_stats + + # 3. Pager-Logik (identisch mit dem Speiseplan-View) + prev_tag = SpeiseplanTag.objects.filter(datum__lt=target_date).order_by('-datum').first() + next_tag = SpeiseplanTag.objects.filter(datum__gt=target_date).order_by('datum').first() + + context['prev_date'] = prev_tag.datum.strftime('%Y-%m-%d') if prev_tag else None + context['next_date'] = next_tag.datum.strftime('%Y-%m-%d') if next_tag else None + + # 4. Gesamtzahlen für die Übersicht + context['total_bestellungen'] = Bestellung.objects.filter(menue__tag__datum=target_date).count() + context['total_umsatz'] = Bestellung.objects.filter(menue__tag__datum=target_date).aggregate(Sum('menue__preis'))['menue__preis__sum'] or 0 + + return context