Commit c48449cd authored by Skia's avatar Skia

Add barman stats

parent dcd0c1fe
......@@ -222,6 +222,7 @@ tbody>tr:hover {
}
.highlight {
background: orange;
font-weight: bold;
}
.tool-bar {
overflow: auto;
......
......@@ -43,6 +43,56 @@
{% endfor %}
</tbody>
</table>
<h4>{% trans counter_name=counter.name %}Top 100 barman {{ counter_name }}{% endtrans %}</h4>
<table>
<thead>
<tr>
<td>{% trans %}Nb{% endtrans %}</td>
<td>{% trans %}User{% endtrans %}</td>
<td>{% trans %}Time{% endtrans %}</td>
</tr>
</thead>
<tbody>
{% for r in top_barman_semester %}
{% set u=User.objects.filter(id=r.user).first() %}
{% if u == user %}
<tr class="highlight">
{% else %}
<tr>
{% endif %}
<td>{{ loop.index }}</td>
<td>{{ u.get_display_name() }}</td>
<td>{{ r.perm_sum }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<h4>{% trans counter_name=counter.name %}Top 100 barman {{ counter_name }} (all semesters){% endtrans %}</h4>
<table>
<thead>
<tr>
<td>{% trans %}Nb{% endtrans %}</td>
<td>{% trans %}User{% endtrans %}</td>
<td>{% trans %}Time{% endtrans %}</td>
</tr>
</thead>
<tbody>
{% for r in top_barman %}
{% set u=User.objects.filter(id=r.user).first() %}
{% if u == user %}
<tr class="highlight">
{% else %}
<tr>
{% endif %}
<td>{{ loop.index }}</td>
<td>{{ u.get_display_name() }}</td>
<td>{{ r.perm_sum }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}
......
......@@ -11,7 +11,7 @@ from django.utils import timezone
from django import forms
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from django.db import DataError, transaction
from django.db import DataError, transaction, models
import re
import pytz
......@@ -23,7 +23,8 @@ from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMi
from core.views.forms import SelectUser, LoginForm, SelectDate, SelectDateTime
from core.models import User
from subscription.models import Subscription
from counter.models import Counter, Customer, Product, Selling, Refilling, ProductType, CashRegisterSummary, CashRegisterSummaryItem, Eticket
from counter.models import Counter, Customer, Product, Selling, Refilling, ProductType, \
CashRegisterSummary, CashRegisterSummaryItem, Eticket, Permanency
from accounting.models import CurrencyField
class GetUserForm(forms.Form):
......@@ -866,6 +867,7 @@ class CounterStatView(DetailView, CanEditMixin):
from django.db.models import Sum, Case, When, F, DecimalField
kwargs = super(CounterStatView, self).get_context_data(**kwargs)
kwargs['Customer'] = Customer
kwargs['User'] = User
semester_start = Subscription.compute_start(d=date.today(), duration=3)
kwargs['total_sellings'] = Selling.objects.filter(date__gte=semester_start,
counter=self.object).aggregate(total_sellings=Sum(F('quantity')*F('unit_price'),
......@@ -880,6 +882,28 @@ class CounterStatView(DetailView, CanEditMixin):
)
)
).exclude(selling_sum=None).order_by('-selling_sum').all()[:100]
kwargs['top_barman'] = Permanency.objects.values('user').annotate(
perm_sum=Sum(
Case(When(counter=self.object,
end__gt=datetime(year=1999, month=1, day=1),
then=F('end')-F('start')),
output_field=models.DateTimeField()
)
)
).exclude(perm_sum=None).order_by('-perm_sum').all()[:100]
kwargs['top_barman_semester'] = Permanency.objects.values('user').annotate(
perm_sum=Sum(
Case(When(counter=self.object,
start__gt=semester_start,
end__gt=datetime(year=1999, month=1, day=1),
then=F('end')-F('start')),
output_field=models.DateTimeField()
)
)
).exclude(perm_sum=None).order_by('-perm_sum').all()[:100]
kwargs['sith_date']=settings.SITH_START_DATE[0]
kwargs['semester_start']=semester_start
return kwargs
def dispatch(self, request, *args, **kwargs):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment