diff --git a/billard/templates/billard/accounting.html b/billard/templates/billard/accounting.html
new file mode 100644
index 0000000..112beae
--- /dev/null
+++ b/billard/templates/billard/accounting.html
@@ -0,0 +1,48 @@
+{% extends 'billard/base.html' %}
+{% load display_client %}
+
+{% block title %}Accounting Data{% endblock %}
+
+{% block content %}
+{% if not locations|length_is:"1" %}
+
+{% endif %}
+
+ Gesamt-Summe: {{ acc_sum }}
+
+
+
+ Start-Datum: |
+ Stop-Datum: |
+ Preis Normal: |
+ Preis Happy Hour: |
+ Preis gesamt: |
+
+{% for acc in accounting %}
+
+ {{ acc.time_from }} |
+ {{ acc.time_to }} |
+ {{ acc.prize_normal }} |
+ {{ acc.prize_hh }} |
+ {{ acc.prize }} |
+
+{% endfor %}
+
+
+
+
+{% endblock %}
diff --git a/billard/templates/billard/base.html b/billard/templates/billard/base.html
index 0665e45..efe6f2d 100644
--- a/billard/templates/billard/base.html
+++ b/billard/templates/billard/base.html
@@ -29,6 +29,7 @@
- Tische
+ - Abrechnung
{% if user.is_superuser %}
- Administration
{% endif %}
diff --git a/billard/urls.py b/billard/urls.py
index 5f22fdc..c61e51c 100644
--- a/billard/urls.py
+++ b/billard/urls.py
@@ -10,6 +10,7 @@ urlpatterns = [
url(r'^(?P[0-9]+)/$', views.LocationDataDetailView.as_view(), name='detail'),
url(r'api/v1/', include(router.urls)),
url(r'process_locationdata', views.process_locationdata, name='process_locationdata'),
+ url(r'accounting', views.accounting, name='accounting'),
url(r'accountmodal$', views.accountmodalview, name='accountmodal'),
url(r'accoutmodal/confirm/(?P[0-9]+)$', views.accountmodalconfirmview, name="accountmodalconfirm")
]
diff --git a/billard/views.py b/billard/views.py
index b0384b3..6382667 100644
--- a/billard/views.py
+++ b/billard/views.py
@@ -6,7 +6,7 @@ from django.shortcuts import render, redirect
from django.views import generic
from django.views.generic.detail import DetailView
from django.contrib.auth.decorators import login_required
-from django.db.models import Min
+from django.db.models import Min, Sum
from django.http import HttpResponse
@@ -53,6 +53,54 @@ def accountmodalconfirmview(request, pk):
return redirect('carom_index')
+@login_required
+def accounting(request):
+ if request.method == 'GET':
+ template = 'billard/accounting.html'
+ loc = None
+ min_loc = Location.objects.filter(users__id=request.user.id).aggregate(Min('id'))['id__min']
+ if 'loc' in request.GET:
+ loc = request.GET['loc']
+ if not Location.objects.filter(users__id=request.user.id).filter(id=loc).exists():
+ resp = redirect('accounting')
+ if min_loc is not None:
+ resp['Location'] += '?loc={}'.format(str(min_loc))
+ request.session['loc'] = str(min_loc)
+ return resp
+ else:
+ return render(request, accounting)
+ if loc is None:
+ loc = min_loc
+ locations = Location.objects.filter(users__id=request.user.id).order_by('code')
+ acc = Accounting.objects.filter(billed=False).exclude(time_to__isnull=True).\
+ filter(desk__client__location_id=loc).order_by('-time_from')
+ acc_sum = acc.aggregate(Sum('prize'))
+ acc_ids = list()
+ for a in acc:
+ acc_ids.append(a.id)
+
+ context = {
+ 'location_id': int(loc),
+ 'locations': locations,
+ 'accounting': acc,
+ 'acc_ids': ','.join(str(e) for e in acc_ids),
+ }
+ if acc_sum['prize__sum'] is None:
+ context['acc_sum'] = 0
+ else:
+ context['acc_sum'] = acc_sum['prize__sum']
+ return render(request, template_name=template, context=context)
+ if request.method == 'POST':
+ loc = request.POST['location-selector']
+ if 'accountings' in request.POST:
+ acc_ids = request.POST['accountings'].split(',')
+ Accounting.objects.filter(id__in=acc_ids).update(billed=True)
+ request.session['loc'] = str(loc)
+ resp = redirect('accounting')
+ resp['Location'] += '?loc={}'.format(str(loc))
+ return resp
+
+
@login_required
def index(request):
if request.method == 'GET':