mirror of
https://github.com/nanoy42/coope
synced 2024-11-21 19:03:12 +00:00
Direct reloads
This commit is contained in:
parent
ed60e58002
commit
4273692005
6 changed files with 160 additions and 4 deletions
|
@ -61,7 +61,6 @@
|
|||
</header>
|
||||
<div class="row uniform">
|
||||
<div class="12u$">
|
||||
<a class="button small" href=""><i class="fa fa-times"></i> Annuler</a><br><br>
|
||||
{{gestion_form}}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -84,7 +83,7 @@
|
|||
<td id="balance">0€</td>
|
||||
<td id="totalAmount">0€</td>
|
||||
<td id="totalAfter">0€</td>
|
||||
<td>{% for pm in pay_buttons %}<button class="btn small pay_button" data-payment="{{pm.pk}}"><i class="fa fa-{{pm.icon}}"></i> {{pm.name}}</button> {% endfor %}</td>
|
||||
<td>{% for pm in pay_buttons %}<button class="btn small pay_button" data-payment="{{pm.pk}}"><i class="fa fa-{{pm.icon}}"></i> {{pm.name}}</button> {% endfor %} <a class="button small" href="" tooltip="lol"><i class="fa fa-times"></i> Annuler</a></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
@ -127,6 +126,25 @@
|
|||
{% if not cotisations|divisibleby:3 %}
|
||||
</tr>
|
||||
{% endif %}
|
||||
<tr style="text-align:center; font-weight:bold;">
|
||||
<td colspan="1">Rechargements</td>
|
||||
<td>
|
||||
<div class="dropdown">
|
||||
<button onclick="dropdown('myDropdown1')" class="dropbtn small">Rechargement 1€</button>
|
||||
<div id="myDropdown1" class="dropdown-content">
|
||||
{% for pm in pay_buttons %}{% if not pm.affect_balance%}<a class="reload" data-payment="{{pm.pk}}" data-payment-name="{{pm.name}}" target="1"><i class="fa fa-{{pm.icon}}"></i> {{pm.name}}</a> {% endif %}{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div class="dropdown">
|
||||
<button onclick="dropdown('myDropdown2')" class="dropbtn small" target="myDropdown2">Rechargement 10€</button>
|
||||
<div id="myDropdown2" class="dropdown-content">
|
||||
{% for pm in pay_buttons %}{% if not pm.affect_balance%}<a class="reload" data-payment="{{pm.pk}}" data-payment-name="{{pm.name}}" target="10"><i class="fa fa-{{pm.icon}}"></i> {{pm.name}}</a> {% endif %}{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr style="text-align:center; font-weight:bold;"><td colspan="4">Bières pression</td></tr>
|
||||
{% for product in bieresPression %}
|
||||
{% if forloop.counter0|divisibleby:3 %}
|
||||
|
|
|
@ -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")
|
||||
|
|
28
staticfiles/dropdown.css
Normal file
28
staticfiles/dropdown.css
Normal file
|
@ -0,0 +1,28 @@
|
|||
/* The container <div> - 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;
|
||||
}
|
27
staticfiles/dropdown.js
Normal file
27
staticfiles/dropdown.js
Normal file
|
@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<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<reloads.length;k++){
|
||||
reload = reloads[k];
|
||||
html += '<tr><td>Rechargement ' + String(reload.payment_method_name) + " " + String(reload.value) + ' €</td><td>-' + String(reload.value) + ' €</td><td><input type="number" data-target="' + String(k) + '" onChange="updateReloadInput(this)" value="' + String(reload.quantity) + '"/></td><td>-' + String(Number((reload.quantity * reload.value).toFixed(2))) + ' €</td></tr>';
|
||||
}
|
||||
for(k=0;k<products.length;k++){
|
||||
product = products[k]
|
||||
html += '<tr><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>';
|
||||
|
@ -109,7 +131,7 @@ function generate_html(){
|
|||
menu = menus[k]
|
||||
html += '<tr><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();
|
||||
}
|
||||
|
||||
|
@ -124,6 +146,9 @@ function updateTotal(){
|
|||
for(k=0; k<cotisations.length;k++){
|
||||
total += cotisations[k].quantity * cotisations[k].amount;
|
||||
}
|
||||
for(k=0; k<reloads.length;k++){
|
||||
total -= reloads[k].quantity * reloads[k].value;
|
||||
}
|
||||
$("#totalAmount").text(String(Number(total.toFixed(2))) + "€")
|
||||
totalAfter = balance - total
|
||||
$("#totalAfter").text(String(Number(totalAfter.toFixed(2))) + "€")
|
||||
|
@ -150,6 +175,13 @@ function updateCotisationInput(a){
|
|||
generate_html();
|
||||
}
|
||||
|
||||
function updateReloadInput(a){
|
||||
quantity = parseInt(a.value);
|
||||
k = parseInt(a.getAttribute("data-target"));
|
||||
reloads[k].quantity = quantity;
|
||||
generate_html();
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
$(".cotisation-hidden").hide();
|
||||
get_config();
|
||||
|
@ -166,6 +198,10 @@ $(document).ready(function(){
|
|||
cotisation = get_cotisation($(this).attr('target'));
|
||||
});
|
||||
|
||||
$(".reload").click(function(){
|
||||
add_reload(parseInt($(this).attr('target')), parseInt($(this).attr('data-payment')), $(this).attr('data-payment-name'));
|
||||
})
|
||||
|
||||
$("#id_client").on('change', function(){
|
||||
id_user = $("#id_client").val();
|
||||
$.get("/users/getUser/" + id_user, function(data){
|
||||
|
@ -206,7 +242,7 @@ $(document).ready(function(){
|
|||
}
|
||||
}
|
||||
}
|
||||
$.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){
|
||||
$.post("order", {"user":id_user, "paymentMethod": $(this).attr('data-payment'), "order_length": products.length + menus.length + cotisations.length + reloads.length, "order": JSON.stringify(products), "amount": total, "menus": JSON.stringify(menus), "listPintes": JSON.stringify(listPintes), "cotisations": JSON.stringify(cotisations), "reloads": JSON.stringify(reloads)}, function(data){
|
||||
alert(data);
|
||||
location.reload();
|
||||
}).fail(function(data){
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
<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="stylesheet" href="{% static 'css/main.css' %}" />
|
||||
<link rel="stylesheet" href="{% static 'dropdown.css' %}" />
|
||||
{% block extra_css %}{% 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">
|
||||
|
@ -55,5 +56,6 @@
|
|||
}
|
||||
</script>
|
||||
{% endif %}
|
||||
<script src="{% static 'dropdown.js' %}"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue