mirror of
https://github.com/nanoy42/coope
synced 2024-11-22 11:23:11 +00:00
Proprification de order et easy_cotis
This commit is contained in:
parent
cf038ae493
commit
424da8261c
8 changed files with 221 additions and 100 deletions
|
@ -115,6 +115,19 @@
|
||||||
<div class="boutonProduit">
|
<div class="boutonProduit">
|
||||||
<table>
|
<table>
|
||||||
<tbody class="actions" id="bouton Produit">
|
<tbody class="actions" id="bouton Produit">
|
||||||
|
<tr class="cotisation-hidden" style="text-align:center; font-weight:bold;"><td colspan="4">Cotisations</td></tr>
|
||||||
|
{% for cotisation in cotisations %}
|
||||||
|
{% if forloop.counter0|divisibleby:4 %}
|
||||||
|
<tr class="cotisation-hidden" style="text-align:center">
|
||||||
|
{% endif %}
|
||||||
|
<td class="cotisation-hidden"><button class="cotisation" target="{{cotisation.pk}}">Cotisation {{cotisation.duration}} jours ({{cotisation.amount}} €)</button></td>
|
||||||
|
{% if forloop.counter|divisibleby:4 %}
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% if not bieresPression|divisibleby:4 %}
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
<tr style="text-align:center; font-weight:bold;"><td colspan="4">Bières pression</td></tr>
|
<tr style="text-align:center; font-weight:bold;"><td colspan="4">Bières pression</td></tr>
|
||||||
{% for product in bieresPression %}
|
{% for product in bieresPression %}
|
||||||
{% if forloop.counter0|divisibleby:4 %}
|
{% if forloop.counter0|divisibleby:4 %}
|
||||||
|
|
224
gestion/views.py
224
gestion/views.py
|
@ -7,19 +7,20 @@ from django.views.decorators.csrf import csrf_exempt
|
||||||
from django.contrib.auth.decorators import login_required, permission_required
|
from django.contrib.auth.decorators import login_required, permission_required
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
|
from django.db import transaction
|
||||||
|
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from django_tex.views import render_to_pdf
|
from django_tex.views import render_to_pdf
|
||||||
|
|
||||||
from coopeV3.acl import active_required, acl_or, admin_required
|
from coopeV3.acl import active_required, acl_or, admin_required
|
||||||
|
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
from dal import autocomplete
|
from dal import autocomplete
|
||||||
from decimal import *
|
from decimal import *
|
||||||
import datetime
|
|
||||||
|
|
||||||
from .forms import ReloadForm, RefundForm, ProductForm, KegForm, MenuForm, GestionForm, SearchMenuForm, SearchProductForm, SelectPositiveKegForm, SelectActiveKegForm, PinteForm, GenerateReleveForm
|
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 .models import Product, Menu, Keg, ConsumptionHistory, KegHistory, Consumption, MenuHistory, Pinte, Reload, Refund
|
||||||
from preferences.models import PaymentMethod, GeneralPreferences
|
from preferences.models import PaymentMethod, GeneralPreferences, Cotisation
|
||||||
from users.models import CotisationHistory
|
from users.models import CotisationHistory
|
||||||
|
|
||||||
@active_required
|
@active_required
|
||||||
|
@ -77,6 +78,7 @@ def manage(request):
|
||||||
menus = Menu.objects.filter(is_active=True)
|
menus = Menu.objects.filter(is_active=True)
|
||||||
kegs = Keg.objects.filter(is_active=True)
|
kegs = Keg.objects.filter(is_active=True)
|
||||||
gp, _ = GeneralPreferences.objects.get_or_create(pk=1)
|
gp, _ = GeneralPreferences.objects.get_or_create(pk=1)
|
||||||
|
cotisations = Cotisation.objects.all()
|
||||||
floating_buttons = gp.floating_buttons
|
floating_buttons = gp.floating_buttons
|
||||||
for keg in kegs:
|
for keg in kegs:
|
||||||
if(keg.pinte):
|
if(keg.pinte):
|
||||||
|
@ -97,6 +99,7 @@ def manage(request):
|
||||||
"menus": menus,
|
"menus": menus,
|
||||||
"pay_buttons": pay_buttons,
|
"pay_buttons": pay_buttons,
|
||||||
"floating_buttons": floating_buttons,
|
"floating_buttons": floating_buttons,
|
||||||
|
"cotisations": cotisations
|
||||||
})
|
})
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
|
@ -107,90 +110,135 @@ def order(request):
|
||||||
"""
|
"""
|
||||||
Process the given order. Called by a js/JQuery script.
|
Process the given order. Called by a js/JQuery script.
|
||||||
"""
|
"""
|
||||||
if("user" not in request.POST or "paymentMethod" not in request.POST or "amount" not in request.POST or "order" not in request.POST):
|
error_message = "Impossible d'effectuer la transaction. Toute opération abandonnée. Veuillez contacter le président ou le trésorier"
|
||||||
return HttpResponse("Erreur du POST")
|
try:
|
||||||
else:
|
with transaction.atomic():
|
||||||
user = get_object_or_404(User, pk=request.POST['user'])
|
if("user" not in request.POST or "paymentMethod" not in request.POST or "amount" not in request.POST or "order" not in request.POST):
|
||||||
paymentMethod = get_object_or_404(PaymentMethod, pk=request.POST['paymentMethod'])
|
raise Exception("Erreur du post")
|
||||||
amount = Decimal(request.POST['amount'])
|
|
||||||
order = json.loads(request.POST["order"])
|
|
||||||
menus = json.loads(request.POST["menus"])
|
|
||||||
listPintes = json.loads(request.POST["listPintes"])
|
|
||||||
gp,_ = GeneralPreferences.objects.get_or_create(pk=1)
|
|
||||||
if (not order) and (not menus):
|
|
||||||
return HttpResponse("Pas de commande")
|
|
||||||
adherentRequired = False
|
|
||||||
for o in order:
|
|
||||||
product = get_object_or_404(Product, pk=o["pk"])
|
|
||||||
adherentRequired = adherentRequired or product.adherentRequired
|
|
||||||
for m in menus:
|
|
||||||
menu = get_object_or_404(Menu, pk=m["pk"])
|
|
||||||
adherentRequired = adherentRequired or menu.adherent_required
|
|
||||||
if(adherentRequired and not user.profile.is_adherent):
|
|
||||||
return HttpResponse("N'est pas adhérent et devrait l'être")
|
|
||||||
# Partie un peu complexe : je libère toutes les pintes de la commande, puis je test
|
|
||||||
# s'il a trop de pintes non rendues, puis je réalloue les pintes
|
|
||||||
for pinte in listPintes:
|
|
||||||
allocate(pinte, None)
|
|
||||||
if(gp.lost_pintes_allowed and user.profile.nb_pintes >= gp.lost_pintes_allowed):
|
|
||||||
return HttpResponse("Impossible de réaliser la commande : l'utilisateur a perdu trop de pintes.")
|
|
||||||
for pinte in listPintes:
|
|
||||||
allocate(pinte, user)
|
|
||||||
if(paymentMethod.affect_balance):
|
|
||||||
if(user.profile.balance < amount):
|
|
||||||
return HttpResponse("Solde inférieur au prix de la commande")
|
|
||||||
else:
|
else:
|
||||||
user.profile.debit += amount
|
user = get_object_or_404(User, pk=request.POST['user'])
|
||||||
user.save()
|
paymentMethod = get_object_or_404(PaymentMethod, pk=request.POST['paymentMethod'])
|
||||||
for o in order:
|
amount = Decimal(request.POST['amount'])
|
||||||
product = get_object_or_404(Product, pk=o["pk"])
|
order = json.loads(request.POST["order"])
|
||||||
quantity = int(o["quantity"])
|
menus = json.loads(request.POST["menus"])
|
||||||
if(product.category == Product.P_PRESSION):
|
listPintes = json.loads(request.POST["listPintes"])
|
||||||
keg = get_object_or_404(Keg, pinte=product)
|
cotisations = json.loads(request.POST['cotisations'])
|
||||||
if(not keg.is_active):
|
gp,_ = GeneralPreferences.objects.get_or_create(pk=1)
|
||||||
return HttpResponse("Une erreur inconnue s'est produite. Veuillez contacter le trésorier ou le président")
|
if (not order) and (not menus) and (not cotisations):
|
||||||
kegHistory = get_object_or_404(KegHistory, keg=keg, isCurrentKegHistory=True)
|
error_message = "Pas de commande"
|
||||||
kegHistory.quantitySold += Decimal(quantity * 0.5)
|
raise Exception(error_message)
|
||||||
kegHistory.amountSold += Decimal(quantity * product.amount)
|
if(cotisations):
|
||||||
kegHistory.save()
|
for co in cotisations:
|
||||||
elif(product.category == Product.D_PRESSION):
|
cotisation = Cotisation.objects.get(pk=co['pk'])
|
||||||
keg = get_object_or_404(Keg, demi=product)
|
for i in range(co['quantity']):
|
||||||
if(not keg.is_active):
|
cotisation_history = CotisationHistory(cotisation=cotisation)
|
||||||
return HttpResponse("Une erreur inconnue s'est produite. Veuillez contacter le trésorier ou le président")
|
if(paymentMethod.affect_balance):
|
||||||
kegHistory = get_object_or_404(KegHistory, keg=keg, isCurrentKegHistory=True)
|
if(user.profile.balance >= cotisation_history.cotisation.amount):
|
||||||
kegHistory.quantitySold += Decimal(quantity * 0.25)
|
user.profile.debit += cotisation_history.cotisation.amount
|
||||||
kegHistory.amountSold += Decimal(quantity * product.amount)
|
else:
|
||||||
kegHistory.save()
|
error_message = "Solde insuffisant"
|
||||||
elif(product.category == Product.G_PRESSION):
|
raise Exception(error_message)
|
||||||
keg = get_object_or_404(Keg, galopin=product)
|
cotisation_history.user = user
|
||||||
if(not keg.is_active):
|
cotisation_history.coopeman = request.user
|
||||||
return HttpResponse("Une erreur inconnue s'est produite. Veuillez contacter le trésorier ou le président")
|
cotisation_history.amount = cotisation.amount
|
||||||
kegHistory = get_object_or_404(KegHistory, keg=keg, isCurrentKegHistory=True)
|
cotisation_history.duration = cotisation.duration
|
||||||
kegHistory.quantitySold += Decimal(quantity * 0.125)
|
cotisation_history.paymentMethod = paymentMethod
|
||||||
kegHistory.amountSold += Decimal(quantity * product.amount)
|
if(user.profile.cotisationEnd and user.profile.cotisationEnd > timezone.now()):
|
||||||
kegHistory.save()
|
cotisation_history.endDate = user.profile.cotisationEnd + timedelta(days=cotisation.duration)
|
||||||
else:
|
else:
|
||||||
if(product.stockHold > 0):
|
cotisation_history.endDate = timezone.now() + timedelta(days=cotisation.duration)
|
||||||
product.stockHold -= 1
|
user.profile.cotisationEnd = cotisation_history.endDate
|
||||||
product.save()
|
user.save()
|
||||||
consumption, _ = Consumption.objects.get_or_create(customer=user, product=product)
|
cotisation_history.save()
|
||||||
consumption.quantity += quantity
|
adherentRequired = False
|
||||||
consumption.save()
|
for o in order:
|
||||||
ch = ConsumptionHistory(customer=user, quantity=quantity, paymentMethod=paymentMethod, product=product, amount=Decimal(quantity*product.amount), coopeman=request.user)
|
product = get_object_or_404(Product, pk=o["pk"])
|
||||||
ch.save()
|
adherentRequired = adherentRequired or product.adherentRequired
|
||||||
for m in menus:
|
for m in menus:
|
||||||
menu = get_object_or_404(Menu, pk=m["pk"])
|
menu = get_object_or_404(Menu, pk=m["pk"])
|
||||||
quantity = int(m["quantity"])
|
adherentRequired = adherentRequired or menu.adherent_required
|
||||||
mh = MenuHistory(customer=user, quantity=quantity, paymentMethod=paymentMethod, menu=menu, amount=int(quantity*menu.amount), coopeman=request.user)
|
if(adherentRequired and not user.profile.is_adherent):
|
||||||
mh.save()
|
error_message = "N'est pas adhérent et devrait l'être."
|
||||||
for article in menu.articles.all():
|
raise Exception(error_message)
|
||||||
consumption, _ = Consumption.objects.get_or_create(customer=user, product=article)
|
# Partie un peu complexe : je libère toutes les pintes de la commande, puis je test
|
||||||
consumption.quantity += quantity
|
# s'il a trop de pintes non rendues, puis je réalloue les pintes
|
||||||
consumption.save()
|
for pinte in listPintes:
|
||||||
if(article.stockHold > 0):
|
allocate(pinte, None)
|
||||||
article.stockHold -= 1
|
if(gp.use_pinte_monitoring and gp.lost_pintes_allowed and user.profile.nb_pintes >= gp.lost_pintes_allowed):
|
||||||
article.save()
|
error_message = "Impossible de réaliser la commande : l'utilisateur a perdu trop de pintes."
|
||||||
return HttpResponse("La commande a bien été effectuée")
|
raise Exception(error_message)
|
||||||
|
for pinte in listPintes:
|
||||||
|
allocate(pinte, user)
|
||||||
|
if(paymentMethod.affect_balance):
|
||||||
|
if(user.profile.balance < amount):
|
||||||
|
error_message = "Solde inférieur au prix de la commande"
|
||||||
|
raise Exception(error_message)
|
||||||
|
else:
|
||||||
|
user.profile.debit += amount
|
||||||
|
user.save()
|
||||||
|
for o in order:
|
||||||
|
product = get_object_or_404(Product, pk=o["pk"])
|
||||||
|
quantity = int(o["quantity"])
|
||||||
|
if(product.category == Product.P_PRESSION):
|
||||||
|
keg = get_object_or_404(Keg, pinte=product)
|
||||||
|
if(not keg.is_active):
|
||||||
|
raise Exception("Fût non actif")
|
||||||
|
kegHistory = get_object_or_404(KegHistory, keg=keg, isCurrentKegHistory=True)
|
||||||
|
kegHistory.quantitySold += Decimal(quantity * 0.5)
|
||||||
|
kegHistory.amountSold += Decimal(quantity * product.amount)
|
||||||
|
kegHistory.save()
|
||||||
|
elif(product.category == Product.D_PRESSION):
|
||||||
|
keg = get_object_or_404(Keg, demi=product)
|
||||||
|
if(not keg.is_active):
|
||||||
|
raise Exception("Fût non actif")
|
||||||
|
kegHistory = get_object_or_404(KegHistory, keg=keg, isCurrentKegHistory=True)
|
||||||
|
kegHistory.quantitySold += Decimal(quantity * 0.25)
|
||||||
|
kegHistory.amountSold += Decimal(quantity * product.amount)
|
||||||
|
kegHistory.save()
|
||||||
|
elif(product.category == Product.G_PRESSION):
|
||||||
|
keg = get_object_or_404(Keg, galopin=product)
|
||||||
|
if(not keg.is_active):
|
||||||
|
raise Exception("Fût non actif")
|
||||||
|
kegHistory = get_object_or_404(KegHistory, keg=keg, isCurrentKegHistory=True)
|
||||||
|
kegHistory.quantitySold += Decimal(quantity * 0.125)
|
||||||
|
kegHistory.amountSold += Decimal(quantity * product.amount)
|
||||||
|
kegHistory.save()
|
||||||
|
else:
|
||||||
|
if(product.stockHold > 0):
|
||||||
|
product.stockHold -= 1
|
||||||
|
product.save()
|
||||||
|
consumption, _ = Consumption.objects.get_or_create(customer=user, product=product)
|
||||||
|
consumption.quantity += quantity
|
||||||
|
consumption.save()
|
||||||
|
ch = ConsumptionHistory(customer=user, quantity=quantity, paymentMethod=paymentMethod, product=product, amount=Decimal(quantity*product.amount), coopeman=request.user)
|
||||||
|
ch.save()
|
||||||
|
if(user.profile.balance > Decimal(product.amount * quantity)):
|
||||||
|
user.profile.debit += Decimal(product.amount*quantity)
|
||||||
|
else:
|
||||||
|
error_message = "Solde insuffisant"
|
||||||
|
raise Exception(error_message)
|
||||||
|
for m in menus:
|
||||||
|
menu = get_object_or_404(Menu, pk=m["pk"])
|
||||||
|
quantity = int(m["quantity"])
|
||||||
|
mh = MenuHistory(customer=user, quantity=quantity, paymentMethod=paymentMethod, menu=menu, amount=int(quantity*menu.amount), coopeman=request.user)
|
||||||
|
mh.save()
|
||||||
|
if(user.profile.balance > Decimal(menu.amount * quantity)):
|
||||||
|
user.profile.debit += Decimal(menu.amount*quantity)
|
||||||
|
else:
|
||||||
|
error_message = "Solde insuffisant"
|
||||||
|
raise Exception(error_message)
|
||||||
|
for article in menu.articles.all():
|
||||||
|
consumption, _ = Consumption.objects.get_or_create(customer=user, product=article)
|
||||||
|
consumption.quantity += quantity
|
||||||
|
consumption.save()
|
||||||
|
if(article.stockHold > 0):
|
||||||
|
article.stockHold -= 1
|
||||||
|
article.save()
|
||||||
|
return HttpResponse("La commande a bien été effectuée")
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
print("test")
|
||||||
|
return HttpResponse(error_message)
|
||||||
|
|
||||||
@active_required
|
@active_required
|
||||||
@login_required
|
@login_required
|
||||||
|
@ -899,7 +947,7 @@ def get_menu(request, pk):
|
||||||
for article in menu.articles:
|
for article in menu.articles:
|
||||||
if article.category == Product.P_PRESSION:
|
if article.category == Product.P_PRESSION:
|
||||||
nb_pintes +=1
|
nb_pintes +=1
|
||||||
data = json.dumps({"pk": menu.pk, "barcode" : menu.barcode, "name": menu.name, "amount" : menu.amount, needQuantityButton: False, "nb_pintes": nb_pintes})
|
data = json.dumps({"pk": menu.pk, "barcode" : menu.barcode, "name": menu.name, "amount" : menu.amount, "needQuantityButton": False, "nb_pintes": nb_pintes})
|
||||||
return HttpResponse(data, content_type='application/json')
|
return HttpResponse(data, content_type='application/json')
|
||||||
|
|
||||||
class MenusAutocomplete(autocomplete.Select2QuerySetView):
|
class MenusAutocomplete(autocomplete.Select2QuerySetView):
|
||||||
|
@ -1074,7 +1122,7 @@ def gen_releve(request):
|
||||||
value_lydia += cot.amount
|
value_lydia += cot.amount
|
||||||
elif pm == cheque:
|
elif pm == cheque:
|
||||||
value_cheque += cot.amount
|
value_cheque += cot.amount
|
||||||
now = datetime.datetime.now()
|
now = 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")
|
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:
|
else:
|
||||||
return render(request, "form.html", {"form": form, "form_title": "Génération d'un relevé", "form_button": "Générer", "form_button_icon": "file-pdf"})
|
return render(request, "form.html", {"form": form, "form_title": "Génération d'un relevé", "form_button": "Générer", "form_button_icon": "file-pdf"})
|
||||||
|
|
|
@ -15,4 +15,5 @@ urlpatterns = [
|
||||||
path('deletePaymentMethod/<int:pk>', views.deletePaymentMethod, name="deletePaymentMethod"),
|
path('deletePaymentMethod/<int:pk>', views.deletePaymentMethod, name="deletePaymentMethod"),
|
||||||
path('inactive', views.inactive, name="inactive"),
|
path('inactive', views.inactive, name="inactive"),
|
||||||
path('getConfig', views.get_config, name="getConfig"),
|
path('getConfig', views.get_config, name="getConfig"),
|
||||||
]
|
path('getCotisation/<int:pk>', views.get_cotisation, name="getCotisation")
|
||||||
|
,]
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import json
|
import simplejson as json
|
||||||
|
|
||||||
from django.shortcuts import render, redirect, get_object_or_404
|
from django.shortcuts import render, redirect, get_object_or_404
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
@ -135,6 +135,19 @@ def deleteCotisation(request,pk):
|
||||||
messages.success(request, message)
|
messages.success(request, message)
|
||||||
return redirect(reverse('preferences:cotisationsIndex'))
|
return redirect(reverse('preferences:cotisationsIndex'))
|
||||||
|
|
||||||
|
@active_required
|
||||||
|
@login_required
|
||||||
|
@permission_required('preferences.view_cotisation')
|
||||||
|
def get_cotisation(request, pk):
|
||||||
|
"""
|
||||||
|
Get a cotisation by pk
|
||||||
|
|
||||||
|
``pk``
|
||||||
|
The primary key of the cotisation
|
||||||
|
"""
|
||||||
|
cotisation = get_object_or_404(Cotisation, pk=pk)
|
||||||
|
data = json.dumps({"pk": cotisation.pk, "duration": cotisation.duration, "amount" : cotisation.amount, "needQuantityButton": False})
|
||||||
|
return HttpResponse(data, content_type='application/json')
|
||||||
|
|
||||||
########## Payment Methods ##########
|
########## Payment Methods ##########
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
total = 0
|
total = 0
|
||||||
products = []
|
products = []
|
||||||
menus = []
|
menus = []
|
||||||
|
cotisations = []
|
||||||
paymentMethod = null
|
paymentMethod = null
|
||||||
balance = 0
|
balance = 0
|
||||||
username = ""
|
username = ""
|
||||||
id = 0
|
id_user = 0
|
||||||
listPintes = []
|
listPintes = []
|
||||||
nbPintes = 0;
|
nbPintes = 0;
|
||||||
use_pinte_monitoring = false;
|
use_pinte_monitoring = false;
|
||||||
|
@ -29,9 +30,15 @@ function get_menu(id){
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_cotisation(id){
|
||||||
|
res = $.get("../preferences/getCotisation/" + id, function(data){
|
||||||
|
add_cotisation(data.pk, "", data.duration, data.amount, data.needQuantityButton);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function add_product(pk, barcode, name, amount, needQuantityButton){
|
function add_product(pk, barcode, name, amount, needQuantityButton){
|
||||||
exist = false
|
exist = false
|
||||||
index = -1
|
index = -1;
|
||||||
for(k=0;k < products.length; k++){
|
for(k=0;k < products.length; k++){
|
||||||
if(products[k].pk == pk){
|
if(products[k].pk == pk){
|
||||||
exist = true
|
exist = true
|
||||||
|
@ -71,15 +78,36 @@ function add_menu(pk, barcode, name, amount){
|
||||||
generate_html();
|
generate_html();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function add_cotisation(pk, barcode, duration, amount){
|
||||||
|
exist = false;
|
||||||
|
index = -1;
|
||||||
|
for(k=0; k < cotisations.length; k++){
|
||||||
|
if(cotisations[k].pk == pk){
|
||||||
|
exist = true;
|
||||||
|
index = k;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(exist){
|
||||||
|
cotisations[index].quantity += 1;
|
||||||
|
}else{
|
||||||
|
cotisations.push({"pk": pk, "barcode": barcode, "duration": duration, "amount": amount, "quantity":1});
|
||||||
|
}
|
||||||
|
generate_html();
|
||||||
|
}
|
||||||
|
|
||||||
function generate_html(){
|
function generate_html(){
|
||||||
html = "";
|
html = "";
|
||||||
|
for(k=0;k<cotisations.length;k++){
|
||||||
|
cotisation = cotisations[k];
|
||||||
|
html += '<tr><td></td><td>Cotisation ' + String(cotisation.duration) + ' jours</td><td>' + String(cotisation.amount) + ' €</td><td><input type="number" data-target="' + String(k) + '" onChange="updateCotisationInput(this)" value="' + String(cotisation.quantity) + '"/></td><td>' + String(Number((cotisation.quantity * cotisation.amount).toFixed(2))) + ' €</td></tr>';
|
||||||
|
}
|
||||||
for(k=0;k<products.length;k++){
|
for(k=0;k<products.length;k++){
|
||||||
product = products[k]
|
product = products[k]
|
||||||
html += '<tr><td>' + product.barcode + '</td><td>' + product.name + '</td><td>' + String(product.amount) + '</td><td><input type="number" data-target="' + String(k) + '" onChange="updateInput(this)" value="' + String(product.quantity) + '"/></td><td>' + String(Number((product.quantity * product.amount).toFixed(2))) + '</td></tr>';
|
html += '<tr><td>' + product.barcode + '</td><td>' + product.name + '</td><td>' + String(product.amount) + ' €</td><td><input type="number" data-target="' + String(k) + '" onChange="updateInput(this)" value="' + String(product.quantity) + '"/></td><td>' + String(Number((product.quantity * product.amount).toFixed(2))) + ' €</td></tr>';
|
||||||
}
|
}
|
||||||
for(k=0; k<menus.length;k++){
|
for(k=0; k<menus.length;k++){
|
||||||
menu = menus[k]
|
menu = menus[k]
|
||||||
html += '<tr><td>' + menu.barcode + '</td><td>' + menu.name + '</td><td>' + String(menu.amount) + '</td><td><input type="number" data-target="' + String(k) + '" onChange="updateMenuInput(this)" value="' + String(menu.quantity) + '"/></td><td>' + String(Number((menu.quantity * menu.amount).toFixed(2))) + '</td></tr>';
|
html += '<tr><td>' + menu.barcode + '</td><td>' + menu.name + '</td><td>' + String(menu.amount) + ' €</td><td><input type="number" data-target="' + String(k) + '" onChange="updateMenuInput(this)" value="' + String(menu.quantity) + '"/></td><td>' + String(Number((menu.quantity * menu.amount).toFixed(2))) + ' €</td></tr>';
|
||||||
}
|
}
|
||||||
$("#items").html(html)
|
$("#items").html(html)
|
||||||
updateTotal();
|
updateTotal();
|
||||||
|
@ -93,6 +121,9 @@ function updateTotal(){
|
||||||
for(k=0; k<menus.length;k++){
|
for(k=0; k<menus.length;k++){
|
||||||
total += menus[k].quantity * menus[k].amount;
|
total += menus[k].quantity * menus[k].amount;
|
||||||
}
|
}
|
||||||
|
for(k=0; k<cotisations.length;k++){
|
||||||
|
total += cotisations[k].quantity * cotisations[k].amount;
|
||||||
|
}
|
||||||
$("#totalAmount").text(String(Number(total.toFixed(2))) + "€")
|
$("#totalAmount").text(String(Number(total.toFixed(2))) + "€")
|
||||||
totalAfter = balance - total
|
totalAfter = balance - total
|
||||||
$("#totalAfter").text(String(Number(totalAfter.toFixed(2))) + "€")
|
$("#totalAfter").text(String(Number(totalAfter.toFixed(2))) + "€")
|
||||||
|
@ -112,7 +143,15 @@ function updateMenuInput(a){
|
||||||
generate_html();
|
generate_html();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateCotisationInput(a){
|
||||||
|
quantity = parseInt(a.value);
|
||||||
|
k = parseInt(a.getAttribute("data-target"));
|
||||||
|
cotisations[k].quantity = quantity;
|
||||||
|
generate_html();
|
||||||
|
}
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
|
$(".cotisation-hidden").hide();
|
||||||
get_config();
|
get_config();
|
||||||
|
|
||||||
$(".product").click(function(){
|
$(".product").click(function(){
|
||||||
|
@ -123,12 +162,20 @@ $(document).ready(function(){
|
||||||
menu = get_menu($(this).attr('target'));
|
menu = get_menu($(this).attr('target'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(".cotisation").click(function(){
|
||||||
|
cotisation = get_cotisation($(this).attr('target'));
|
||||||
|
});
|
||||||
|
|
||||||
$("#id_client").on('change', function(){
|
$("#id_client").on('change', function(){
|
||||||
id = $("#id_client").val();
|
id_user = $("#id_client").val();
|
||||||
$.get("/users/getUser/" + id, function(data){
|
$.get("/users/getUser/" + id_user, function(data){
|
||||||
balance = data.balance;
|
balance = data.balance;
|
||||||
username = data.username;
|
username = data.username;
|
||||||
|
is_adherent = data.is_adherent;
|
||||||
$("#balance").html(balance + "€");
|
$("#balance").html(balance + "€");
|
||||||
|
if(!is_adherent){
|
||||||
|
$(".cotisation-hidden").show();
|
||||||
|
}
|
||||||
updateTotal();
|
updateTotal();
|
||||||
}).fail(function(){
|
}).fail(function(){
|
||||||
alert("Une erreur inconnue est survenue");
|
alert("Une erreur inconnue est survenue");
|
||||||
|
@ -159,7 +206,7 @@ $(document).ready(function(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$.post("order", {"user":id, "paymentMethod": $(this).attr('data-payment'), "order_length": products.length + menus.length, "order": JSON.stringify(products), "amount": total, "menus": JSON.stringify(menus), "listPintes": JSON.stringify(listPintes)}, function(data){
|
$.post("order", {"user":id_user, "paymentMethod": $(this).attr('data-payment'), "order_length": products.length + menus.length + cotisations.length, "order": JSON.stringify(products), "amount": total, "menus": JSON.stringify(menus), "listPintes": JSON.stringify(listPintes), "cotisations": JSON.stringify(cotisations)}, function(data){
|
||||||
alert(data);
|
alert(data);
|
||||||
location.reload();
|
location.reload();
|
||||||
}).fail(function(data){
|
}).fail(function(data){
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
<link rel="icon" sizes="32x32" href="{% static 'favicon32.ico' %}" type="image/x-icon">
|
<link rel="icon" sizes="32x32" href="{% static 'favicon32.ico' %}" type="image/x-icon">
|
||||||
<link rel="icon" sizes="96x96" href="{% static 'favicon96.ico' %}" type="image/x-icon">
|
<link rel="icon" sizes="96x96" href="{% static 'favicon96.ico' %}" type="image/x-icon">
|
||||||
<link rel="stylesheet" href="{% static 'css/main.css' %}" />
|
<link rel="stylesheet" href="{% static 'css/main.css' %}" />
|
||||||
<script src="{% static 'jquery.js' %}"></script>
|
|
||||||
{% block extra_css %}{% endblock %}
|
{% block extra_css %}{% endblock %}
|
||||||
{% block extra_script %}{% endblock %}
|
{% block extra_script %}{% endblock %}
|
||||||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
|
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{% load static %}
|
{% load static %}
|
||||||
{% load users_extra %}
|
{% load users_extra %}
|
||||||
{% block entete %}{% if self %}Mon Profil{% else %}Profil de {{user}}{% endif %}{%endblock%}
|
{% block entete %}{% if self %}Mon Profil{% else %}Profil de {{user}}{% endif %}{%endblock%}
|
||||||
|
{% block extra_script %}<script src="{% static 'jquery.js' %}"></script>{% endblock %}
|
||||||
{% block navbar %}
|
{% block navbar %}
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#first">{% if self %}Mes informations {% else %} Informations {% endif %}</a>
|
<li><a href="#first">{% if self %}Mes informations {% else %} Informations {% endif %}</a>
|
||||||
|
|
|
@ -413,7 +413,7 @@ def getUser(request, pk):
|
||||||
The pk of the user
|
The pk of the user
|
||||||
"""
|
"""
|
||||||
user = get_object_or_404(User, pk=pk)
|
user = get_object_or_404(User, pk=pk)
|
||||||
data = json.dumps({"username": user.username, "balance": user.profile.balance})
|
data = json.dumps({"username": user.username, "balance": user.profile.balance, "is_adherent": user.profile.is_adherent})
|
||||||
return HttpResponse(data, content_type='application/json')
|
return HttpResponse(data, content_type='application/json')
|
||||||
|
|
||||||
@active_required
|
@active_required
|
||||||
|
|
Loading…
Reference in a new issue