mirror of
https://framagit.org/la-chariotte/la-chariotte.git
synced 2025-05-02 20:01:51 +02:00
Fix total price when making order
This commit is contained in:
parent
322a99d5c8
commit
7a371d1b18
1 changed files with 180 additions and 165 deletions
|
@ -17,7 +17,8 @@
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
<div class="column is-8">
|
<div class="column is-8">
|
||||||
<p class="title">{{ grouped_order }}</p>
|
<p class="title">{{ grouped_order }}</p>
|
||||||
{% if grouped_order.description %}<p class="formatted-text">{{ grouped_order.description }}</p>{% endif %}
|
{% if grouped_order.description %}
|
||||||
|
<p class="formatted-text">{{ grouped_order.description }}</p>{% endif %}
|
||||||
{% if not user.is_authenticated %}
|
{% if not user.is_authenticated %}
|
||||||
<p><span class="has-text-dark is-italic">Vous êtes l'organisateur·ice ?</span>
|
<p><span class="has-text-dark is-italic">Vous êtes l'organisateur·ice ?</span>
|
||||||
<a href="{% url 'order:grouped_order_overview' grouped_order.code %}">
|
<a href="{% url 'order:grouped_order_overview' grouped_order.code %}">
|
||||||
|
@ -27,13 +28,17 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="column">
|
<div class="column">
|
||||||
{% if grouped_order.place %}
|
{% if grouped_order.place %}
|
||||||
<p><i class="fa fa-map-pin mr-3" aria-label="Lieu" title="Lieu" aria-hidden="true"></i>{{ grouped_order.place }}</p>
|
<p><i class="fa fa-map-pin mr-3" aria-label="Lieu" title="Lieu"
|
||||||
|
aria-hidden="true"></i>{{ grouped_order.place }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<p><i class="fa fa-calendar-check-o mr-3" aria-label="Date limite de commande" title="Date limite de commande" aria-hidden="true"></i>
|
<p><i class="fa fa-calendar-check-o mr-3" aria-label="Date limite de commande"
|
||||||
|
title="Date limite de commande" aria-hidden="true"></i>
|
||||||
Commandes avant le {{ grouped_order.deadline }}
|
Commandes avant le {{ grouped_order.deadline }}
|
||||||
</p>
|
</p>
|
||||||
<p><i class="fa fa-truck mr-3" aria-label="Date de livraison" title="Date de livraison" aria-hidden="true"></i>
|
<p><i class="fa fa-truck mr-3" aria-label="Date de livraison" title="Date de livraison"
|
||||||
Livraison le {{ grouped_order.delivery_date }}{% if grouped_order.delivery_slot %}, {{ grouped_order.delivery_slot }}{% endif %}
|
aria-hidden="true"></i>
|
||||||
|
Livraison le {{ grouped_order.delivery_date }}{% if grouped_order.delivery_slot %},
|
||||||
|
{{ grouped_order.delivery_slot }}{% endif %}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{% if user == grouped_order.orga %}
|
{% if user == grouped_order.orga %}
|
||||||
|
@ -42,7 +47,8 @@
|
||||||
</a>
|
</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>Organisateur·ice : {{ grouped_order.orga }}</p>
|
<p>Organisateur·ice : {{ grouped_order.orga }}</p>
|
||||||
<a class="button is-light" href="mailto:{{ grouped_order.orga.username }}">Contacter l'organisateur·ice</a>
|
<a class="button is-light" href="mailto:{{ grouped_order.orga.username }}">Contacter
|
||||||
|
l'organisateur·ice</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -52,7 +58,8 @@
|
||||||
<!-- Boite à messages -->
|
<!-- Boite à messages -->
|
||||||
{% if not grouped_order.is_to_be_delivered %}
|
{% if not grouped_order.is_to_be_delivered %}
|
||||||
<p>
|
<p>
|
||||||
<strong>Cette commande groupée est terminée</strong>, la livraison a eu lieu le {{ grouped_order.deadline }}.
|
<strong>Cette commande groupée est terminée</strong>, la livraison a eu lieu
|
||||||
|
le {{ grouped_order.deadline }}.
|
||||||
</p>
|
</p>
|
||||||
{% elif not grouped_order.is_open %}
|
{% elif not grouped_order.is_open %}
|
||||||
<p>
|
<p>
|
||||||
|
@ -60,7 +67,8 @@
|
||||||
{% if user == grouped_order.orga %}
|
{% if user == grouped_order.orga %}
|
||||||
En tant qu'organisateur·ice, vous pouvez encore commander jusqu'à la date de livraison.
|
En tant qu'organisateur·ice, vous pouvez encore commander jusqu'à la date de livraison.
|
||||||
{% else %}
|
{% else %}
|
||||||
Si vous aviez commandé, rendez-vous le {{ grouped_order.delivery_date }} pour récupérer vos produits !
|
Si vous aviez commandé, rendez-vous le {{ grouped_order.delivery_date }} pour récupérer vos produits
|
||||||
|
!
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -86,17 +94,20 @@
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<td>{{ item.name }}</td>
|
<td>{{ item.name }}</td>
|
||||||
<td>{{ item.price }} €</td>
|
<td>{{ item.price }} €</td>
|
||||||
<td><input name="quantity_{{ item.id }}" size="4" type="number" value="0" min="0" {% if item.get_remaining_nb == 0 %}disabled{% endif %}></input>
|
<td><input name="quantity_{{ item.id }}" size="4" type="number" value="0" min="0"
|
||||||
|
{% if item.get_remaining_nb == 0 %}disabled{% endif %}></input>
|
||||||
{% if item.get_remaining_nb is not null %}
|
{% if item.get_remaining_nb is not null %}
|
||||||
<span class="is-italic mini-title">
|
<span class="is-italic mini-title">
|
||||||
{% if item.get_remaining_nb == 0 %}Produit épuisé
|
{% if item.get_remaining_nb == 0 %}Produit épuisé
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ item.get_remaining_nb }} {% if item.get_remaining_nb == 1 %}disponible{% else %}disponibles{% endif %}</span>
|
{{ item.get_remaining_nb }} {% if item.get_remaining_nb == 1 %}disponible{% else %}disponibles
|
||||||
|
{% endif %}</span>
|
||||||
{% endif %}{% endif %}</td>
|
{% endif %}{% endif %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<tr>
|
<tr>
|
||||||
<td></td><td></td>
|
<td></td>
|
||||||
|
<td></td>
|
||||||
<td><strong>Total : <span class="total">0</span> €</strong></td>
|
<td><strong>Total : <span class="total">0</span> €</strong></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -115,13 +126,15 @@
|
||||||
<p>{{ item.price }} €</p>
|
<p>{{ item.price }} €</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer-item">
|
<div class="card-footer-item">
|
||||||
<td><input name="quantity_{{ item.id }}" size="4" type="number" value="0" min="0" {% if item.get_remaining_nb == 0 %}disabled{% endif %}>
|
<td><input name="quantity_{{ item.id }}" size="4" type="number" value="0"
|
||||||
|
min="0" {% if item.get_remaining_nb == 0 %}disabled{% endif %}>
|
||||||
</input></td>
|
</input></td>
|
||||||
{% if item.get_remaining_nb is not null %}
|
{% if item.get_remaining_nb is not null %}
|
||||||
<span class="is-italic mini-title">
|
<span class="is-italic mini-title">
|
||||||
{% if item.get_remaining_nb == 0 %}Produit épuisé
|
{% if item.get_remaining_nb == 0 %}Produit épuisé
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ item.get_remaining_nb }} {% if item.get_remaining_nb == 1 %}disponible{% else %}disponibles{% endif %}</span>
|
{{ item.get_remaining_nb }} {% if item.get_remaining_nb == 1 %}disponible{% else %}disponibles
|
||||||
|
{% endif %}</span>
|
||||||
{% endif %}{% endif %}
|
{% endif %}{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -138,15 +151,19 @@
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<p><label for="first_name">Prénom : </label>
|
<p><label for="first_name">Prénom : </label>
|
||||||
<input id="first_name" type="text" name="first_name" placeholder="Votre prénom" value="{{ author.first_name }}" required></p>
|
<input id="first_name" type="text" name="first_name" placeholder="Votre prénom"
|
||||||
|
value="{{ author.first_name }}" required></p>
|
||||||
<p><label for="first_name">Nom : </label>
|
<p><label for="first_name">Nom : </label>
|
||||||
<input id="last_name" type="text" name="last_name" placeholder="Votre nom" value="{{ author.last_name }}" required></p>
|
<input id="last_name" type="text" name="last_name" placeholder="Votre nom"
|
||||||
|
value="{{ author.last_name }}" required></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<p><label for="phone">Numéro de téléphone :</label>
|
<p><label for="phone">Numéro de téléphone :</label>
|
||||||
<input id="phone" type="tel" pattern="[0-9]{10}" placeholder="0601020304" name="phone" value="{{ author.phone }}" required></p>
|
<input id="phone" type="tel" pattern="[0-9]{10}" placeholder="0601020304" name="phone"
|
||||||
|
value="{{ author.phone }}" required></p>
|
||||||
<p><label for="email">Adresse mail : </label>
|
<p><label for="email">Adresse mail : </label>
|
||||||
<input id="email" type="email" placeholder="exemple@mail.fr" name="email" value="{{ author.email }}" required></p>
|
<input id="email" type="email" placeholder="exemple@mail.fr" name="email"
|
||||||
|
value="{{ author.email }}" required></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<p><label for="note">Note à l'organisateur·ice</label>
|
<p><label for="note">Note à l'organisateur·ice</label>
|
||||||
|
@ -165,23 +182,21 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
{% block extra_js %}
|
{% block extra_js %}
|
||||||
// Compute total price whenever a value in input is modified
|
// Compute total price whenever a value in input is modified
|
||||||
document.getElementById("inputs-parent").addEventListener("change", function() {
|
document.getElementById("inputs-parent").addEventListener("change", function () {
|
||||||
var inputs = document.getElementsByTagName("input");
|
var inputs = [...document.getElementsByTagName("input")].filter(input => input.getAttribute("name").indexOf("quantity_") === 0); //filter the inputs to get the quantity inputs only
|
||||||
total_price = 0;
|
total_price = 0;
|
||||||
for(let input of inputs){
|
for (let input of inputs) {
|
||||||
input_name = input.getAttribute("name");
|
input_name = input.getAttribute("name");
|
||||||
if(input_name.indexOf("quantity_")==0){ // get the quantities inputs only
|
|
||||||
item_id = input_name.split("_")[1];
|
item_id = input_name.split("_")[1];
|
||||||
prices = {{ prices_dict | safe }};
|
prices = {{ prices_dict | safe }};
|
||||||
total_price += prices[item_id] * input.value;
|
total_price = Number((total_price + Number((prices[item_id] * input.value).toFixed(2))).toFixed(2)); //Limit precision to 2 digits for each added part and for the total
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[].forEach.call(document.getElementsByClassName('total'), function (el) {
|
[].forEach.call(document.getElementsByClassName('total'), function (el) {
|
||||||
el.innerHTML = total_price;
|
el.innerHTML = total_price;
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue