From 42736920056dbdd32724f5b56b68dbd0271dbf31 Mon Sep 17 00:00:00 2001 From: nanoy Date: Sun, 22 Sep 2019 15:32:40 +0200 Subject: [PATCH] Direct reloads --- gestion/templates/gestion/manage.html | 22 +++++++++++-- gestion/views.py | 45 +++++++++++++++++++++++++++ staticfiles/dropdown.css | 28 +++++++++++++++++ staticfiles/dropdown.js | 27 ++++++++++++++++ staticfiles/manage.js | 40 ++++++++++++++++++++++-- templates/base.html | 2 ++ 6 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 staticfiles/dropdown.css create mode 100644 staticfiles/dropdown.js diff --git a/gestion/templates/gestion/manage.html b/gestion/templates/gestion/manage.html index d4f49f6..e64335f 100644 --- a/gestion/templates/gestion/manage.html +++ b/gestion/templates/gestion/manage.html @@ -61,7 +61,6 @@
- Annuler

{{gestion_form}}
@@ -84,7 +83,7 @@ 0€ 0€ 0€ - {% for pm in pay_buttons %} {% endfor %} + {% for pm in pay_buttons %} {% endfor %} Annuler @@ -127,6 +126,25 @@ {% if not cotisations|divisibleby:3 %} {% endif %} + + Rechargements + + + + + + + Bières pression {% for product in bieresPression %} {% if forloop.counter0|divisibleby:3 %} diff --git a/gestion/views.py b/gestion/views.py index 54266df..4faf317 100644 --- a/gestion/views.py +++ b/gestion/views.py @@ -87,9 +87,18 @@ def order(request): menus = json.loads(request.POST["menus"]) listPintes = json.loads(request.POST["listPintes"]) cotisations = json.loads(request.POST['cotisations']) + reloads = json.loads(request.POST['reloads']) gp,_ = GeneralPreferences.objects.get_or_create(pk=1) if (not order) and (not menus) and (not cotisations): raise Exception("Pas de commande.") + if(reloads): + for reload in reloads: + reload_payment_method = get_object_or_404(PaymentMethod, pk=reload["payment_method"]) + reload_amount = Decimal(reload["value"])*Decimal(reload["quantity"]) + reload_entry = Reload(customer=user, amount=reload_amount, PaymentMethod=reload_payment_method, coopeman=request.user) + reload_entry.save() + user.profile.credit += reload_amount + user.save() if(cotisations): for co in cotisations: cotisation = Cotisation.objects.get(pk=co['pk']) @@ -639,6 +648,15 @@ def openKeg(request): keg.stockHold -= 1 keg.is_active = True keg.save() + if keg.pinte: + keg.pinte.is_active = True + keg.pinte.save() + if keg.demi: + keg.demi.is_active = True + keg.demi.save() + if keg.galopin: + keg.galopin.is_active = True + keg.galopin.save() messages.success(request, "Le fut a bien été percuté") return redirect(reverse('gestion:kegsList')) return render(request, "form.html", {"form": form, "form_title":"Percutage d'un fût", "form_button":"Percuter", "form_button_icon": "fill-drip"}) @@ -665,6 +683,15 @@ def openDirectKeg(request, pk): keg.stockHold -= 1 keg.is_active = True keg.save() + if keg.pinte: + keg.pinte.is_active = True + keg.pinte.save() + if keg.demi: + keg.demi.is_active = True + keg.demi.save() + if keg.galopin: + keg.galopin.is_active = True + keg.galopin.save() messages.success(request, "Le fût a bien été percuté") else: messages.error(request, "Il n'y a pas de fût en stock") @@ -686,6 +713,15 @@ def closeKeg(request): kegHistory.save() keg.is_active = False keg.save() + if keg.pinte: + keg.pinte.is_active = False + keg.pinte.save() + if keg.demi: + keg.demi.is_active = False + keg.demi.save() + if keg.galopin: + keg.galopin.is_active = False + keg.galopin.save() messages.success(request, "Le fût a bien été fermé") return redirect(reverse('gestion:kegsList')) return render(request, "form.html", {"form": form, "form_title":"Fermeture d'un fût", "form_button":"Fermer le fût", "form_button_icon": "fill"}) @@ -708,6 +744,15 @@ def closeDirectKeg(request, pk): kegHistory.save() keg.is_active = False keg.save() + if keg.pinte: + keg.pinte.is_active = False + keg.pinte.save() + if keg.demi: + keg.demi.is_active = False + keg.demi.save() + if keg.galopin: + keg.galopin.is_active = False + keg.galopin.save() messages.success(request, "Le fût a bien été fermé") else: messages.error(request, "Le fût n'est pas ouvert") diff --git a/staticfiles/dropdown.css b/staticfiles/dropdown.css new file mode 100644 index 0000000..97b8a3d --- /dev/null +++ b/staticfiles/dropdown.css @@ -0,0 +1,28 @@ +/* The container
- needed to position the dropdown content */ +.dropdown { + position: relative; + display: inline-block; +} + +/* Dropdown Content (Hidden by Default) */ +.dropdown-content { + display: none; + position: absolute; + background-color: #f1f1f1; + min-width: 160px; + box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); + z-index: 1; +} + +/* Links inside the dropdown */ +.dropdown-content a { + color: black; + padding: 12px 16px; + text-decoration: none; + display: block; + cursor: pointer; +} +/* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */ +.show { + display:block; +} \ No newline at end of file diff --git a/staticfiles/dropdown.js b/staticfiles/dropdown.js new file mode 100644 index 0000000..93f4671 --- /dev/null +++ b/staticfiles/dropdown.js @@ -0,0 +1,27 @@ +/* When the user clicks on the button, +toggle between hiding and showing the dropdown content */ +function dropdown(target) { + var dropdowns = document.getElementsByClassName("dropdown-content"); + var i; + for (i = 0; i < dropdowns.length; i++) { + var openDropdown = dropdowns[i]; + if (openDropdown.classList.contains('show')) { + openDropdown.classList.remove('show'); + } + } + document.getElementById(target).classList.toggle("show"); +} + +// Close the dropdown menu if the user clicks outside of it +window.onclick = function(event) { + if (!event.target.matches('.dropbtn')) { + var dropdowns = document.getElementsByClassName("dropdown-content"); + var i; + for (i = 0; i < dropdowns.length; i++) { + var openDropdown = dropdowns[i]; + if (openDropdown.classList.contains('show')) { + openDropdown.classList.remove('show'); + } + } + } +} \ No newline at end of file diff --git a/staticfiles/manage.js b/staticfiles/manage.js index 0efcd3c..aa0a629 100644 --- a/staticfiles/manage.js +++ b/staticfiles/manage.js @@ -2,6 +2,7 @@ total = 0 products = [] menus = [] cotisations = [] +reloads = [] paymentMethod = null balance = 0 username = "" @@ -95,12 +96,33 @@ function add_cotisation(pk, duration, amount){ generate_html(); } +function add_reload(value, payment_method, payment_method_name){ + exist = false; + index = -1; + for(k=0; k < reloads.length; k++){ + if(reloads[k].value == value && reloads[k].payment_method == payment_method){ + exist = true; + index = k; + } + } + if(exist){ + reloads[index].quantity += 1; + }else{ + reloads.push({"value": value, "quantity": 1, "payment_method": payment_method, "payment_method_name": payment_method_name}); + } + generate_html(); +} + function generate_html(){ html = ""; for(k=0;k' + String(cotisation.amount) + ' €' + String(Number((cotisation.quantity * cotisation.amount).toFixed(2))) + ' €'; } + for(k=0;k-' + String(reload.value) + ' €-' + String(Number((reload.quantity * reload.value).toFixed(2))) + ' €'; + } for(k=0;k' + String(product.amount) + ' €' + String(Number((product.quantity * product.amount).toFixed(2))) + ' €'; @@ -109,7 +131,7 @@ function generate_html(){ menu = menus[k] html += '' + menu.name + '' + String(menu.amount) + ' €' + String(Number((menu.quantity * menu.amount).toFixed(2))) + ' €'; } - $("#items").html(html) + $("#items").html(html); updateTotal(); } @@ -124,6 +146,9 @@ function updateTotal(){ for(k=0; k