add dialog to show accounting data

This commit is contained in:
Robert Einsle 2017-03-11 20:20:25 +01:00
parent 4669416a78
commit ab6d1fa07e
4 changed files with 96 additions and 1 deletions

View File

@ -0,0 +1,48 @@
{% extends 'billard/base.html' %}
{% load display_client %}
{% block title %}Accounting Data{% endblock %}
{% block content %}
{% if not locations|length_is:"1" %}
<form action="accounting" method="post" id="location-form">
{% csrf_token %}
<div id="location-selector" class="alert">
<select class="form-control" form="location-form" name="location-selector" id="location-select">
{% for loc in locations %}
<option value="{{ loc.id }}"{% if loc.id == location_id %} selected{% endif %}>{{ loc.code }} - {{ loc.name }}</option>
{% endfor %}
</select>
</div>
</form>
{% endif %}
<div class="alert alert-success" role="alert">Gesamt-Summe: {{ acc_sum }}</div>
<table class="table">
<tr>
<th>Start-Datum:</th>
<th>Stop-Datum:</th>
<th>Preis Normal:</th>
<th>Preis Happy Hour:</th>
<th>Preis gesamt:</th>
</tr>
{% for acc in accounting %}
<tr>
<td>{{ acc.time_from }}</td>
<td>{{ acc.time_to }}</td>
<td>{{ acc.prize_normal }}</td>
<td>{{ acc.prize_hh }}</td>
<td>{{ acc.prize }}</td>
</tr>
{% endfor %}
</table>
<form action="accounting" method="post" id="accounting">
{% csrf_token %}
<input type="hidden" name="location-selector" value="{{ location_id }}">
<input type="hidden" name="accountings" value="{{ acc_ids }}">
<button type="submit" class="btn btn-default">Abrechnen</button>
</form>
{% endblock %}

View File

@ -29,6 +29,7 @@
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="{% ifequal request.path '/billard/' %}active{% endifequal %}"><a href="{% url "carom_index" %}">Tische</a></li>
<li class="{% ifequal request.path '/billard/accounting' %}active{% endifequal %}"><a href="{% url "accounting" %}">Abrechnung</a></li>
{% if user.is_superuser %}
<li class="{% ifequal request.path '/logout/' %}active{% endifequal %}"><a href="/admin/">Administration</a></li>
{% endif %}

View File

@ -10,6 +10,7 @@ urlpatterns = [
url(r'^(?P<pk>[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<pk>[0-9]+)$', views.accountmodalconfirmview, name="accountmodalconfirm")
]

View File

@ -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,51 @@ 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': 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']
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':