mirror of
https://github.com/nanoy42/coope
synced 2024-11-22 03:13:12 +00:00
commit
d94676d5ec
9 changed files with 186 additions and 30 deletions
|
@ -38,6 +38,7 @@ INSTALLED_APPS = [
|
|||
'dal',
|
||||
'dal_select2',
|
||||
'simple_history',
|
||||
'django_tex',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
@ -68,6 +69,14 @@ TEMPLATES = [
|
|||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
'NAME': 'tex',
|
||||
'BACKEND': 'django_tex.engine.TeXEngine',
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'environment': 'gestion.environment.my_environment',
|
||||
}
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'coopeV3.wsgi.application'
|
||||
|
|
12
gestion/environment.py
Normal file
12
gestion/environment.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from django_tex.environment import environment
|
||||
|
||||
def latex_safe(value):
|
||||
return str(value).replace('_', '\_').replace('$', '\$').replace('&', '\&').replace('#', '\#').replace('{', '\{').replace('}','\}')
|
||||
|
||||
|
||||
def my_environment(**options):
|
||||
env = environment(**options)
|
||||
env.filters.update({
|
||||
'latex_safe': latex_safe
|
||||
})
|
||||
return env
|
|
@ -67,3 +67,7 @@ class PinteForm(forms.Form):
|
|||
ids = forms.CharField(widget=forms.Textarea, label="Numéros", help_text="Numéros séparés par un espace. Laissez vide pour utiliser le range.", required=False)
|
||||
begin = forms.IntegerField(label="Début", help_text="Début du range", required=False)
|
||||
end = forms.IntegerField(label="Fin", help_text="Fin du range", required=False)
|
||||
|
||||
class GenerateReleveForm(forms.Form):
|
||||
begin = forms.DateTimeField(label="Date de début")
|
||||
end = forms.DateTimeField(label="Date de fin")
|
71
gestion/templates/gestion/releve.tex
Normal file
71
gestion/templates/gestion/releve.tex
Normal file
|
@ -0,0 +1,71 @@
|
|||
\documentclass[11pt,a4paper]{article}
|
||||
\usepackage[utf8]{inputenc}
|
||||
\usepackage[french]{babel}
|
||||
\usepackage[T1]{fontenc}
|
||||
\usepackage{amsmath}
|
||||
\usepackage{amsfonts}
|
||||
\usepackage{amssymb}
|
||||
\usepackage{graphicx}
|
||||
\usepackage{eurosym}
|
||||
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
|
||||
\usepackage{tabularx}
|
||||
\usepackage{longtable}
|
||||
\usepackage{tabu}
|
||||
\author{Généré par CoopeV3}
|
||||
\title{Relevé Coopé Technopôle Metz}
|
||||
\begin{document}
|
||||
\maketitle
|
||||
\section{Informations générales}
|
||||
\begin{longtabu}{|X|X|X|}
|
||||
\hline
|
||||
\multicolumn{2}{|c|}{Généré le } & \textbf{ {{- now | date('d/m/Y H:i:s') -}} }\\
|
||||
\hline
|
||||
Infos & De & \textbf{ {{- begin | date('d/m/Y H:i:s')-}} } \\
|
||||
\cline{2-3} & À & \textbf{ {{- end | date('d/m/Y H:i:s') -}} }\\
|
||||
\hline
|
||||
Estimations & Espèces & \textbf{ {{- value_especes | latex_safe -}} \euro{}} \\
|
||||
\cline{2-3} & Lydia & \textbf{ {{- value_lydia | latex_safe -}} \euro{}} \\
|
||||
\cline{2-3} & Chèques & \textbf{ {{- value_cheque | latex_safe -}} \euro{}} \\
|
||||
\hline
|
||||
\end{longtabu}
|
||||
\section{Transactions}
|
||||
\begin{longtabu}{|c|X|X|X|X|X|}
|
||||
\hline
|
||||
\# & Date & Client & Montant & Moyen de paiement & Produit (Qté) \\
|
||||
\hline
|
||||
{% for consumption in consumptions %}
|
||||
{{consumption.pk}} & {{consumption.date | date('d/m/Y H:i:s')}} & {{consumption.customer.first_name|latex_safe}} {{consumption.customer.last_name|latex_safe}} & {{consumption.amount}} \euro{} & {{consumption.paymentMethod}} & {{consumption.product}} (x{{consumption.quantity}})\\
|
||||
\hline
|
||||
{% endfor %}
|
||||
\end{longtabu}
|
||||
\section{Rechargements}
|
||||
\begin{longtabu}{|c|X|X|X|X|}
|
||||
\hline
|
||||
\# & Date & Client & Montant & Moyen de paiement \\
|
||||
\hline
|
||||
{% for reload in reloads %}
|
||||
{{reload.pk}} & {{ reload.date | date('d/m/Y H:i:s')}} & {{reload.customer.first_name | latex_safe}} {{reload.customer.last_name | latex_safe}} & {{ reload.amount }} \euro{} & {{reload.PaymentMethod}} \\
|
||||
\hline
|
||||
{% endfor %}
|
||||
\end{longtabu}
|
||||
\section{Remboursement}
|
||||
\begin{longtabu}{|c|X|X|X|}
|
||||
\hline
|
||||
\# & Date & Client & Montant\\
|
||||
\hline
|
||||
{% for refund in refunds %}
|
||||
{{refund.pk}} & {{ refund.date | date('d/m/Y H:i:s')}} & {{refund.customer.first_name|latex_safe}} {{refund.customer.last_name|latex_safe}} & {{ refund.amount }} \euro{}\\
|
||||
\hline
|
||||
{% endfor %}
|
||||
\end{longtabu}
|
||||
\section{Cotisations}
|
||||
\begin{longtabu}{|c|X|X|X|X|X|}
|
||||
\hline
|
||||
\# & Date & Client & Montant & Durée & Moyen de paiement \\
|
||||
\hline
|
||||
{% for cot in cotisations %}
|
||||
{{cot.pk}} & {{ cot.paymentDate | date('d/m/Y H:i:s')}} & {{cot.user.first_name|latex_safe}} {{cot.user.last_name|latex_safe}} & {{cot.amount}} \euro{} & {{cot.duration}} jours & {{cot.paymentMethod}} \\
|
||||
\hline
|
||||
{% endfor %}
|
||||
\end{longtabu}
|
||||
\end{document}
|
|
@ -44,4 +44,5 @@ urlpatterns = [
|
|||
path('kegs-active-autocomplete', views.KegActiveAutocomplete.as_view(), name="kegs-active-autocomplete"),
|
||||
path('menus-autcomplete', views.MenusAutocomplete.as_view(), name="menus-autocomplete"),
|
||||
path('cancelReload/<int:pk>', views.cancel_reload, name="cancelReload"),
|
||||
path('gen_releve', views.gen_releve, name="gen_releve"),
|
||||
]
|
|
@ -8,15 +8,19 @@ from django.contrib.auth.decorators import login_required, permission_required
|
|||
from django.utils import timezone
|
||||
from django.http import HttpResponseRedirect
|
||||
|
||||
from coopeV3.acl import active_required, acl_or
|
||||
from django_tex.views import render_to_pdf
|
||||
|
||||
from coopeV3.acl import active_required, acl_or, admin_required
|
||||
|
||||
import simplejson as json
|
||||
from dal import autocomplete
|
||||
from decimal import *
|
||||
import datetime
|
||||
|
||||
from .forms import ReloadForm, RefundForm, ProductForm, KegForm, MenuForm, GestionForm, SearchMenuForm, SearchProductForm, SelectPositiveKegForm, SelectActiveKegForm, PinteForm
|
||||
from .models import Product, Menu, Keg, ConsumptionHistory, KegHistory, Consumption, MenuHistory, Pinte, Reload
|
||||
from .forms import ReloadForm, RefundForm, ProductForm, KegForm, MenuForm, GestionForm, SearchMenuForm, SearchProductForm, SelectPositiveKegForm, SelectActiveKegForm, PinteForm, GenerateReleveForm
|
||||
from .models import Product, Menu, Keg, ConsumptionHistory, KegHistory, Consumption, MenuHistory, Pinte, Reload, Refund
|
||||
from preferences.models import PaymentMethod, GeneralPreferences
|
||||
from users.models import CotisationHistory
|
||||
|
||||
@active_required
|
||||
@login_required
|
||||
|
@ -1018,3 +1022,51 @@ def pintes_user_list(request):
|
|||
pks = [x.pk for x in User.objects.all() if x.profile.nb_pintes > 0]
|
||||
users = User.objects.filter(pk__in=pks)
|
||||
return render(request, "gestion/pintes_user_list.html", {"users": users})
|
||||
|
||||
@active_required
|
||||
@login_required
|
||||
@admin_required
|
||||
def gen_releve(request):
|
||||
form = GenerateReleveForm(request.POST or None)
|
||||
if form.is_valid():
|
||||
begin, end = form.cleaned_data['begin'], form.cleaned_data['end']
|
||||
consumptions = ConsumptionHistory.objects.filter(date__gte=begin).filter(date__lte=end).order_by('-date')
|
||||
reloads = Reload.objects.filter(date__gt=begin).filter(date__lt=end).order_by('-date')
|
||||
refunds = Refund.objects.filter(date__gt=begin).filter(date__lt=end).order_by('-date')
|
||||
cotisations = CotisationHistory.objects.filter(paymentDate__gt=begin).filter(paymentDate__lt=end).order_by('-paymentDate')
|
||||
especes = PaymentMethod.objects.get(name="Espèces")
|
||||
lydia = PaymentMethod.objects.get(name="Lydia")
|
||||
cheque = PaymentMethod.objects.get(name="Chèque")
|
||||
value_especes = 0
|
||||
value_lydia = 0
|
||||
value_cheque = 0
|
||||
for consumption in consumptions:
|
||||
pm = consumption.paymentMethod
|
||||
if pm == especes:
|
||||
value_especes += consumption.amount
|
||||
elif pm == lydia:
|
||||
value_lydia += consumption.amount
|
||||
elif pm == cheque:
|
||||
value_cheque += consumption.amount
|
||||
for reload in reloads:
|
||||
pm = reload.PaymentMethod
|
||||
if pm == especes:
|
||||
value_especes += reload.amount
|
||||
elif pm == lydia:
|
||||
value_lydia += reload.amount
|
||||
elif pm == cheque:
|
||||
value_cheque += reload.amount
|
||||
for refund in refunds:
|
||||
value_especes -= refund.amount
|
||||
for cot in cotisations:
|
||||
pm = cot.paymentMethod
|
||||
if pm == especes:
|
||||
value_especes += cot.amount
|
||||
elif pm == lydia:
|
||||
value_lydia += cot.amount
|
||||
elif pm == cheque:
|
||||
value_cheque += cot.amount
|
||||
now = datetime.datetime.now()
|
||||
return render_to_pdf(request, 'gestion/releve.tex', {"consumptions": consumptions, "reloads": reloads, "refunds": refunds, "cotisations": cotisations, "begin": begin, "end": end, "now": now, "value_especes": value_especes, "value_lydia": value_lydia, "value_cheque": value_cheque}, filename="releve.pdf")
|
||||
else:
|
||||
return render(request, "form.html", {"form": form, "form_title": "Génération d'un relevé", "form_button": "Générer"})
|
||||
|
|
|
@ -4,3 +4,4 @@ pytz==2018.5
|
|||
simplejson==3.16.0
|
||||
docutils==0.14
|
||||
django-simple-history==2.5.1
|
||||
jinja2==2.10
|
|
@ -25,6 +25,11 @@
|
|||
<a href="{% url 'preferences:generalPreferences' %}">Admin</a>
|
||||
</span>
|
||||
{% endif %}
|
||||
{% if request.user.is_staff %}
|
||||
<span class="tabulation2">
|
||||
<a href="{% url 'gestion:gen_releve' %}">Comptabilité</a>
|
||||
</span>
|
||||
{% endif %}
|
||||
{% if perms.preferences.view_cotisation %}
|
||||
<span class="tabulation2">
|
||||
<a href="{% url 'preferences:cotisationsIndex' %}">Cotisations</a>
|
||||
|
|
|
@ -169,4 +169,5 @@ def str_user(self):
|
|||
fin = "Non adhérent"
|
||||
return self.username + " (" + self.first_name + " " + self.last_name + ", " + str(self.profile.balance) + "€, " + fin + ")"
|
||||
|
||||
|
||||
User.add_to_class("__str__", str_user)
|
Loading…
Reference in a new issue