diff --git a/core/static/core/style.css b/core/static/core/style.css index 6e5c8408..7ddf614f 100644 --- a/core/static/core/style.css +++ b/core/static/core/style.css @@ -152,7 +152,6 @@ td { vertical-align: top; overflow: hidden; text-overflow: ellipsis; - max-width: 0; } td>ul { margin-top: 0px; @@ -165,7 +164,9 @@ tbody>tr:nth-child(even) { } tbody>tr:hover { background: yellow; - width: 100%; +} +tbody>tr.highlight { + background: orange; } .tool-bar { overflow: auto; diff --git a/core/templates/core/user_stats.jinja b/core/templates/core/user_stats.jinja index bf1333d6..69692ff1 100644 --- a/core/templates/core/user_stats.jinja +++ b/core/templates/core/user_stats.jinja @@ -14,6 +14,12 @@

La Gommette: {{ total_gommette_time }}

{% endif %} +
+

{% trans %}Buyings{% endtrans %}

+

Foyer: {{ total_foyer_buyings }} €

+

MDE: {{ total_mde_buyings }} €

+

La Gommette: {{ total_gommette_buyings }} €

+
{% endblock %} diff --git a/core/views/user.py b/core/views/user.py index 522fbce7..bead071f 100644 --- a/core/views/user.py +++ b/core/views/user.py @@ -20,6 +20,7 @@ import logging from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, TabedViewMixin from core.views.forms import RegisteringForm, UserPropForm, UserProfileForm, LoginForm from core.models import User, SithFile +from subscription.models import Subscription def login(request): """ @@ -189,10 +190,17 @@ class UserStatsView(UserTabsMixin, CanViewMixin, DetailView): foyer = Counter.objects.filter(name="Foyer").first() mde = Counter.objects.filter(name="MDE").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_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_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 class UserMiniView(CanViewMixin, DetailView): diff --git a/counter/templates/counter/counter_list.jinja b/counter/templates/counter/counter_list.jinja index ca3ca699..195d1175 100644 --- a/counter/templates/counter/counter_list.jinja +++ b/counter/templates/counter/counter_list.jinja @@ -15,6 +15,7 @@ {{ c }} - {% if user.can_edit(c) %} {% trans %}Edit{% endtrans %} - + {% trans %}Stats{% endtrans %} - {% endif %} {% if user.is_owner(c) %} {% trans %}Props{% endtrans %} @@ -29,6 +30,7 @@ {{ c }} - {% if user.can_edit(c) %} {% trans %}Edit{% endtrans %} - + {% trans %}Stats{% endtrans %} - {% endif %} {% if user.is_owner(c) %} {% trans %}Props{% endtrans %} @@ -43,6 +45,7 @@ {{ c }} - {% if user.can_edit(c) %} {% trans %}Edit{% endtrans %} - + {% trans %}Stats{% endtrans %} - {% endif %} {% if user.is_owner(c) %} {% trans %}Props{% endtrans %} diff --git a/counter/templates/counter/stats.jinja b/counter/templates/counter/stats.jinja new file mode 100644 index 00000000..0907a955 --- /dev/null +++ b/counter/templates/counter/stats.jinja @@ -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 %} +

{% trans counter_name=counter %}{{ counter_name }} stats{% endtrans %}

+

{% trans counter_name=counter.name %}Top 100 {{ counter_name }}{% endtrans %}

+ + + + + + + + + + + + + {% for r in top %} + {% set customer=Customer.objects.filter(user__id=r.customer__user).first() %} + {% if customer.user == user %} + + {% else %} + + {% endif %} + + + + + + + + {% endfor %} + +
{% trans %}Nb{% endtrans %}{% trans %}User{% endtrans %}{% trans %}Promo{% endtrans %}{% trans %}Clubs{% endtrans %}{% trans %}Total{% endtrans %}{% trans %}Percentage{% endtrans %}
{{ loop.index }}{{ customer.user.get_display_name() }}{{ customer.user.promo or '' }} + {% for m in customer.user.membership.filter(club__parent=None, end_date=None).all() %} + {{ m.club.name }} + {% endfor %} + {{ r.selling_sum }} €{{ '%.2f'|format(100 * r.selling_sum / total_sellings) }}
+{% endblock %} + + + diff --git a/counter/urls.py b/counter/urls.py index 2516a0de..72d12a0f 100644 --- a/counter/urls.py +++ b/counter/urls.py @@ -7,6 +7,7 @@ urlpatterns = [ url(r'^(?P[0-9]+)/click/(?P[0-9]+)$', CounterClick.as_view(), name='click'), url(r'^(?P[0-9]+)/cash_summary$', CounterCashSummaryView.as_view(), name='cash_summary'), url(r'^(?P[0-9]+)/activity$', CounterActivityView.as_view(), name='activity'), + url(r'^(?P[0-9]+)/stats$', CounterStatView.as_view(), name='stats'), url(r'^(?P[0-9]+)/login$', CounterLogin.as_view(), name='login'), url(r'^(?P[0-9]+)/logout$', CounterLogout.as_view(), name='logout'), url(r'^admin/(?P[0-9]+)$', CounterEditView.as_view(), name='admin'), diff --git a/counter/views.py b/counter/views.py index cc0e36aa..650f0715 100644 --- a/counter/views.py +++ b/counter/views.py @@ -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.forms import SelectUser, LoginForm from core.models import User -from subscription.models import Subscriber +from subscription.models import Subscriber, Subscription from subscription.views import get_subscriber from counter.models import Counter, Customer, Product, Selling, Refilling, ProductType, CashRegisterSummary, CashRegisterSummaryItem +from accounting.models import CurrencyField class GetUserForm(forms.Form): """ @@ -693,6 +694,36 @@ class CounterActivityView(DetailView): pk_url_kwarg = "counter_id" 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): """Display a list of cash summaries""" model = CashRegisterSummary