3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-10-05 19:12:09 +00:00

Ajout des stats

This commit is contained in:
Yoann Pétri 2019-05-03 23:27:11 +02:00
parent 6cb0982261
commit 33f6073f8d
4 changed files with 194 additions and 2 deletions

View file

@ -0,0 +1,146 @@
{% extends 'base.html' %}
{% block entete %}Stats{% endblock %}
{% block navbar%}
<ul>
<li><a href="#first">Stats association</a></li>
<li><a href="#second">Stats produits et catégories</a></li>
<li><a href="#third">Stats moyens de paiments et cotisations</a></li>
</ul>
{% endblock %}
{% block content %}
<section id="first" class="main">
<header class="major">
<h2>Stats association</h2>
</header>
<div class="table-wrapper">
<table>
<thead>
<tr>
<th>Champ</th>
<th>Valeur</th>
</tr>
</thead>
<tbody>
<tr>
<td>Nombre d'adhérents</td>
<td>{{adherents|length}}</td>
</tr>
<tr>
<td>Nombre de comptes</td>
<td>{{users.count}}</td>
</tr>
<tr>
<td>Nombre de transactions</td>
<td>{{transactions.count}}</td>
</tr>
<tr>
<td>Somme des soldes positifs</td>
<td>{{sum_positive_balance}}</td>
</tr>
<tr>
<td>Somme des soldes positifs et négatifs</td>
<td>{{sum_balance}}</td>
</tr>
<tr>
<td>Nombre d'écoles</td>
<td>{{schools.count}}</td>
</tr>
<tr>
<td>Nombre de groupes</td>
<td>{{groups.count}}</td>
</tr>
{% for group in groups %}
<tr>
<td>Nombre dans le groupe {{group}}</td>
<td>{{group.user_set.count}}</td>
</tr>
{% endfor %}
<tr>
<td>Nombre d'admins</td>
<td>{{admins.count}}</td>
</tr>
<tr>
<td>Nombre de superusers</td>
<td>{{superusers.count}}</td>
</tr>
<tr>
<td>Nombre 8</td>
<td>8</td>
</tr>
</tbody>
</table>
</div>
</section>
<section id="second" class="main">
<header class="major">
<h2>Stats produits et catégories</h2>
</header>
<div class="table-wrapper">
<table>
<thead>
<tr>
<th>Champ</th>
<th>Valeur</th>
</tr>
</thead>
<tbody>
<tr>
<td>Nombre de catégories</td>
<td>{{categories.count}}</td>
</tr>
<tr>
<td>Nombre de catégories affichées</td>
<td>{{categories_shown.count}}</td>
</tr>
<tr>
<td>Nombre de produits</td>
<td>{{products.count}}</td>
</tr>
<tr>
<td>Nombre de produits actifs</td>
<td>{{active_products.count}}</td>
</tr>
<tr>
<td>Nombre de fûts actifs</td>
<td>{{active_kegs.count}}</td>
</tr>
<tr>
<td>Nombre de menus</td>
<td>{{menus.count}}</td>
</tr>
</tbody>
</table>
</div>
</section>
<section id="third" class="main">
<header class="major">
<h2>Stats moyens de paiement et cotisations</h2>
</header>
<div class="table-wrapper">
<table>
<thead>
<tr>
<th>Champ</th>
<th>Valeur</th>
</tr>
</thead>
<tbody>
<tr>
<td>Nombre de moyens de paiement</td>
<td>{{payment_methods.count}}</td>
</tr>
<tr>
<td>Nombre de types de cotisations</td>
<td>{{cotisations.count}}</td>
</tr>
{% for cotisation in cotisations %}
<tr>
<td>Nombre de {{cotisation}}</td>
<td>{{cotisation.cotisationhistory_set.count}}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</section>
{% endblock %}

View file

@ -52,4 +52,5 @@ urlpatterns = [
path('categoryProfile/<int:pk>', views.categoryProfile, name="categoryProfile"),
path('categoriesList', views.categoriesList, name="categoriesList"),
path('categories-autocomplete', views.CategoriesAutocomplete.as_view(), name="categories-autocomplete"),
path('stats', views.stats, name="stats"),
]

View file

@ -2,7 +2,7 @@ from django.shortcuts import render, redirect, get_object_or_404
from django.contrib import messages
from django.urls import reverse
from django.http import HttpResponse, Http404
from django.contrib.auth.models import User
from django.contrib.auth.models import User, Group
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.decorators import login_required, permission_required
from django.utils import timezone
@ -20,6 +20,7 @@ from decimal import *
from .forms import ReloadForm, RefundForm, ProductForm, KegForm, MenuForm, GestionForm, SearchMenuForm, SearchProductForm, SelectPositiveKegForm, SelectActiveKegForm, PinteForm, GenerateReleveForm, CategoryForm, SearchCategoryForm
from .models import Product, Menu, Keg, ConsumptionHistory, KegHistory, Consumption, MenuHistory, Pinte, Reload, Refund, Category
from users.models import School
from preferences.models import PaymentMethod, GeneralPreferences, Cotisation
from users.models import CotisationHistory
@ -955,4 +956,45 @@ class CategoriesAutocomplete(autocomplete.Select2QuerySetView):
qs = Category.objects.all()
if self.q:
qs = qs.filter(name__icontains=self.q)
return qs
return qs
@active_required
@login_required
@admin_required
def stats(request):
users = User.objects.all()
adherents = [x for x in users if x.profile.is_adherent]
transactions = ConsumptionHistory.objects.all()
categories = Category.objects.all()
categories_shown = Category.objects.exclude(order=0)
products = Product.objects.all()
active_products = Product.objects.filter(is_active=True)
active_kegs = Keg.objects.filter(is_active=True)
sum_positive_balance = sum([x.profile.balance for x in users if x.profile.balance > 0])
sum_balance = sum([x.profile.balance for x in users])
schools = School.objects.all()
groups = Group.objects.all()
admins = User.objects.filter(is_staff=True)
superusers = User.objects.filter(is_superuser=True)
menus = Menu.objects.all()
payment_methods = PaymentMethod.objects.all()
cotisations = Cotisation.objects.all()
return render(request, "gestion/stats.html", {
"users": users,
"adherents": adherents,
"transactions": transactions,
"categories": categories,
"categories_shown": categories_shown,
"products": products,
"active_products": active_products,
"active_kegs": active_kegs,
"sum_positive_balance": sum_positive_balance,
"sum_balance": sum_balance,
"schools": schools,
"groups": groups,
"admins": admins,
"superusers": superusers,
"menus": menus,
"payment_methods": payment_methods,
"cotisations": cotisations,
})

View file

@ -30,6 +30,9 @@
</span>
{% endif %}
{% if request.user.is_staff %}
<span class="tabulation2">
<i class="fa fa-chart-bar"></i> <a href="{% url 'gestion:stats' %}">Stats</a>
</span>
<span class="tabulation2">
<i class="fa fa-business-time"></i> <a href="{% url 'gestion:gen_releve' %}">Comptabilité</a>
</span>