mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
Add top 100 to counters
This commit is contained in:
parent
6aaeb7cdc9
commit
35d811317c
@ -152,7 +152,6 @@ td {
|
|||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
max-width: 0;
|
|
||||||
}
|
}
|
||||||
td>ul {
|
td>ul {
|
||||||
margin-top: 0px;
|
margin-top: 0px;
|
||||||
@ -165,7 +164,9 @@ tbody>tr:nth-child(even) {
|
|||||||
}
|
}
|
||||||
tbody>tr:hover {
|
tbody>tr:hover {
|
||||||
background: yellow;
|
background: yellow;
|
||||||
width: 100%;
|
}
|
||||||
|
tbody>tr.highlight {
|
||||||
|
background: orange;
|
||||||
}
|
}
|
||||||
.tool-bar {
|
.tool-bar {
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
|
@ -14,6 +14,12 @@
|
|||||||
<p>La Gommette: {{ total_gommette_time }}</p>
|
<p>La Gommette: {{ total_gommette_time }}</p>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
<div>
|
||||||
|
<h3>{% trans %}Buyings{% endtrans %}</h3>
|
||||||
|
<p>Foyer: {{ total_foyer_buyings }} €</p>
|
||||||
|
<p>MDE: {{ total_mde_buyings }} €</p>
|
||||||
|
<p>La Gommette: {{ total_gommette_buyings }} €</p>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ import logging
|
|||||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin
|
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin
|
||||||
from core.views.forms import RegisteringForm, UserPropForm, UserProfileForm, LoginForm
|
from core.views.forms import RegisteringForm, UserPropForm, UserProfileForm, LoginForm
|
||||||
from core.models import User, SithFile
|
from core.models import User, SithFile
|
||||||
|
from subscription.models import Subscription
|
||||||
|
|
||||||
def login(request):
|
def login(request):
|
||||||
"""
|
"""
|
||||||
@ -189,10 +190,17 @@ class UserStatsView(UserTabsMixin, CanViewMixin, DetailView):
|
|||||||
foyer = Counter.objects.filter(name="Foyer").first()
|
foyer = Counter.objects.filter(name="Foyer").first()
|
||||||
mde = Counter.objects.filter(name="MDE").first()
|
mde = Counter.objects.filter(name="MDE").first()
|
||||||
gommette = Counter.objects.filter(name="La Gommette").first()
|
gommette = Counter.objects.filter(name="La Gommette").first()
|
||||||
|
semester_start=Subscription.compute_start(d=date.today(), duration=3)
|
||||||
kwargs['total_perm_time'] = sum([p.end-p.start for p in self.object.permanencies.all()], timedelta())
|
kwargs['total_perm_time'] = sum([p.end-p.start for p in self.object.permanencies.all()], timedelta())
|
||||||
kwargs['total_foyer_time'] = sum([p.end-p.start for p in self.object.permanencies.filter(counter=foyer)], timedelta())
|
kwargs['total_foyer_time'] = sum([p.end-p.start for p in self.object.permanencies.filter(counter=foyer)], timedelta())
|
||||||
kwargs['total_mde_time'] = sum([p.end-p.start for p in self.object.permanencies.filter(counter=mde)], timedelta())
|
kwargs['total_mde_time'] = sum([p.end-p.start for p in self.object.permanencies.filter(counter=mde)], timedelta())
|
||||||
kwargs['total_gommette_time'] = sum([p.end-p.start for p in self.object.permanencies.filter(counter=gommette)], timedelta())
|
kwargs['total_gommette_time'] = sum([p.end-p.start for p in self.object.permanencies.filter(counter=gommette)], timedelta())
|
||||||
|
kwargs['total_foyer_buyings'] = sum([b.unit_price*b.quantity for b in
|
||||||
|
self.object.customer.buyings.filter(counter=foyer, date__gte=semester_start)])
|
||||||
|
kwargs['total_mde_buyings'] = sum([b.unit_price*b.quantity for b in self.object.customer.buyings.filter(counter=mde,
|
||||||
|
date__gte=semester_start)])
|
||||||
|
kwargs['total_gommette_buyings'] = sum([b.unit_price*b.quantity for b in
|
||||||
|
self.object.customer.buyings.filter(counter=gommette, date__gte=semester_start)])
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
class UserMiniView(CanViewMixin, DetailView):
|
class UserMiniView(CanViewMixin, DetailView):
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
<a href="{{ url('eboutic:main') }}">{{ c }}</a> -
|
<a href="{{ url('eboutic:main') }}">{{ c }}</a> -
|
||||||
{% if user.can_edit(c) %}
|
{% if user.can_edit(c) %}
|
||||||
<a href="{{ url('counter:admin', counter_id=c.id) }}">{% trans %}Edit{% endtrans %}</a> -
|
<a href="{{ url('counter:admin', counter_id=c.id) }}">{% trans %}Edit{% endtrans %}</a> -
|
||||||
|
<a href="{{ url('counter:stats', counter_id=c.id) }}">{% trans %}Stats{% endtrans %}</a> -
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if user.is_owner(c) %}
|
{% if user.is_owner(c) %}
|
||||||
<a href="{{ url('counter:prop_admin', counter_id=c.id) }}">{% trans %}Props{% endtrans %}</a>
|
<a href="{{ url('counter:prop_admin', counter_id=c.id) }}">{% trans %}Props{% endtrans %}</a>
|
||||||
@ -29,6 +30,7 @@
|
|||||||
<a href="{{ url('counter:details', counter_id=c.id) }}">{{ c }}</a> -
|
<a href="{{ url('counter:details', counter_id=c.id) }}">{{ c }}</a> -
|
||||||
{% if user.can_edit(c) %}
|
{% if user.can_edit(c) %}
|
||||||
<a href="{{ url('counter:admin', counter_id=c.id) }}">{% trans %}Edit{% endtrans %}</a> -
|
<a href="{{ url('counter:admin', counter_id=c.id) }}">{% trans %}Edit{% endtrans %}</a> -
|
||||||
|
<a href="{{ url('counter:stats', counter_id=c.id) }}">{% trans %}Stats{% endtrans %}</a> -
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if user.is_owner(c) %}
|
{% if user.is_owner(c) %}
|
||||||
<a href="{{ url('counter:prop_admin', counter_id=c.id) }}">{% trans %}Props{% endtrans %}</a>
|
<a href="{{ url('counter:prop_admin', counter_id=c.id) }}">{% trans %}Props{% endtrans %}</a>
|
||||||
@ -43,6 +45,7 @@
|
|||||||
<a href="{{ url('counter:details', counter_id=c.id) }}">{{ c }}</a> -
|
<a href="{{ url('counter:details', counter_id=c.id) }}">{{ c }}</a> -
|
||||||
{% if user.can_edit(c) %}
|
{% if user.can_edit(c) %}
|
||||||
<a href="{{ url('counter:admin', counter_id=c.id) }}">{% trans %}Edit{% endtrans %}</a> -
|
<a href="{{ url('counter:admin', counter_id=c.id) }}">{% trans %}Edit{% endtrans %}</a> -
|
||||||
|
<a href="{{ url('counter:stats', counter_id=c.id) }}">{% trans %}Stats{% endtrans %}</a> -
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if user.is_owner(c) %}
|
{% if user.is_owner(c) %}
|
||||||
<a href="{{ url('counter:prop_admin', counter_id=c.id) }}">{% trans %}Props{% endtrans %}</a>
|
<a href="{{ url('counter:prop_admin', counter_id=c.id) }}">{% trans %}Props{% endtrans %}</a>
|
||||||
|
47
counter/templates/counter/stats.jinja
Normal file
47
counter/templates/counter/stats.jinja
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
{% extends "core/base.jinja" %}
|
||||||
|
{% from 'core/macros.jinja' import user_profile_link %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
{% trans counter_name=counter %}{{ counter_name }} stats{% endtrans %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h3>{% trans counter_name=counter %}{{ counter_name }} stats{% endtrans %}</h3>
|
||||||
|
<h4>{% trans counter_name=counter.name %}Top 100 {{ counter_name }}{% endtrans %}</h4>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<td>{% trans %}Nb{% endtrans %}</td>
|
||||||
|
<td>{% trans %}User{% endtrans %}</td>
|
||||||
|
<td>{% trans %}Promo{% endtrans %}</td>
|
||||||
|
<td>{% trans %}Clubs{% endtrans %}</td>
|
||||||
|
<td>{% trans %}Total{% endtrans %}</td>
|
||||||
|
<td>{% trans %}Percentage{% endtrans %}</td>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for r in top %}
|
||||||
|
{% set customer=Customer.objects.filter(user__id=r.customer__user).first() %}
|
||||||
|
{% if customer.user == user %}
|
||||||
|
<tr class="highlight">
|
||||||
|
{% else %}
|
||||||
|
<tr>
|
||||||
|
{% endif %}
|
||||||
|
<td>{{ loop.index }}</td>
|
||||||
|
<td>{{ customer.user.get_display_name() }}</td>
|
||||||
|
<td>{{ customer.user.promo or '' }}</td>
|
||||||
|
<td>
|
||||||
|
{% for m in customer.user.membership.filter(club__parent=None, end_date=None).all() %}
|
||||||
|
{{ m.club.name }}
|
||||||
|
{% endfor %}
|
||||||
|
</td>
|
||||||
|
<td>{{ r.selling_sum }} €</td>
|
||||||
|
<td>{{ '%.2f'|format(100 * r.selling_sum / total_sellings) }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -7,6 +7,7 @@ urlpatterns = [
|
|||||||
url(r'^(?P<counter_id>[0-9]+)/click/(?P<user_id>[0-9]+)$', CounterClick.as_view(), name='click'),
|
url(r'^(?P<counter_id>[0-9]+)/click/(?P<user_id>[0-9]+)$', CounterClick.as_view(), name='click'),
|
||||||
url(r'^(?P<counter_id>[0-9]+)/cash_summary$', CounterCashSummaryView.as_view(), name='cash_summary'),
|
url(r'^(?P<counter_id>[0-9]+)/cash_summary$', CounterCashSummaryView.as_view(), name='cash_summary'),
|
||||||
url(r'^(?P<counter_id>[0-9]+)/activity$', CounterActivityView.as_view(), name='activity'),
|
url(r'^(?P<counter_id>[0-9]+)/activity$', CounterActivityView.as_view(), name='activity'),
|
||||||
|
url(r'^(?P<counter_id>[0-9]+)/stats$', CounterStatView.as_view(), name='stats'),
|
||||||
url(r'^(?P<counter_id>[0-9]+)/login$', CounterLogin.as_view(), name='login'),
|
url(r'^(?P<counter_id>[0-9]+)/login$', CounterLogin.as_view(), name='login'),
|
||||||
url(r'^(?P<counter_id>[0-9]+)/logout$', CounterLogout.as_view(), name='logout'),
|
url(r'^(?P<counter_id>[0-9]+)/logout$', CounterLogout.as_view(), name='logout'),
|
||||||
url(r'^admin/(?P<counter_id>[0-9]+)$', CounterEditView.as_view(), name='admin'),
|
url(r'^admin/(?P<counter_id>[0-9]+)$', CounterEditView.as_view(), name='admin'),
|
||||||
|
@ -20,9 +20,10 @@ from ajax_select import make_ajax_form, make_ajax_field
|
|||||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, TabedViewMixin
|
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, TabedViewMixin
|
||||||
from core.views.forms import SelectUser, LoginForm
|
from core.views.forms import SelectUser, LoginForm
|
||||||
from core.models import User
|
from core.models import User
|
||||||
from subscription.models import Subscriber
|
from subscription.models import Subscriber, Subscription
|
||||||
from subscription.views import get_subscriber
|
from subscription.views import get_subscriber
|
||||||
from counter.models import Counter, Customer, Product, Selling, Refilling, ProductType, CashRegisterSummary, CashRegisterSummaryItem
|
from counter.models import Counter, Customer, Product, Selling, Refilling, ProductType, CashRegisterSummary, CashRegisterSummaryItem
|
||||||
|
from accounting.models import CurrencyField
|
||||||
|
|
||||||
class GetUserForm(forms.Form):
|
class GetUserForm(forms.Form):
|
||||||
"""
|
"""
|
||||||
@ -693,6 +694,36 @@ class CounterActivityView(DetailView):
|
|||||||
pk_url_kwarg = "counter_id"
|
pk_url_kwarg = "counter_id"
|
||||||
template_name = 'counter/activity.jinja'
|
template_name = 'counter/activity.jinja'
|
||||||
|
|
||||||
|
class CounterStatView(DetailView):
|
||||||
|
"""
|
||||||
|
Show the bar stats
|
||||||
|
"""
|
||||||
|
model = Counter
|
||||||
|
pk_url_kwarg = "counter_id"
|
||||||
|
template_name = 'counter/stats.jinja'
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
""" Add stats to the context """
|
||||||
|
from django.db.models import Sum, Case, When, F, DecimalField
|
||||||
|
kwargs = super(CounterStatView, self).get_context_data(**kwargs)
|
||||||
|
kwargs['Customer'] = Customer
|
||||||
|
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'),
|
||||||
|
output_field=CurrencyField()))['total_sellings']
|
||||||
|
kwargs['top'] = Selling.objects.values('customer__user').annotate(
|
||||||
|
selling_sum=Sum(
|
||||||
|
Case(When(counter=self.object,
|
||||||
|
date__gte=semester_start,
|
||||||
|
unit_price__gt=0,
|
||||||
|
then=F('unit_price')*F('quantity')),
|
||||||
|
output_field=CurrencyField()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).exclude(selling_sum=None).order_by('-selling_sum').all()[:100]
|
||||||
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
class CashSummaryListView(CanEditPropMixin, CounterTabsMixin, ListView):
|
class CashSummaryListView(CanEditPropMixin, CounterTabsMixin, ListView):
|
||||||
"""Display a list of cash summaries"""
|
"""Display a list of cash summaries"""
|
||||||
model = CashRegisterSummary
|
model = CashRegisterSummary
|
||||||
|
Loading…
Reference in New Issue
Block a user