mirror of
https://framagit.org/la-chariotte/la-chariotte.git
synced 2025-05-02 11:52:27 +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="column is-8">
|
||||
<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 %}
|
||||
<p><span class="has-text-dark is-italic">Vous êtes l'organisateur·ice ?</span>
|
||||
<a href="{% url 'order:grouped_order_overview' grouped_order.code %}">
|
||||
|
@ -27,13 +28,17 @@
|
|||
</div>
|
||||
<div class="column">
|
||||
{% 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 %}
|
||||
<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 }}
|
||||
</p>
|
||||
<p><i class="fa fa-truck mr-3" aria-label="Date de livraison" title="Date de livraison" aria-hidden="true"></i>
|
||||
Livraison le {{ grouped_order.delivery_date }}{% if grouped_order.delivery_slot %}, {{ grouped_order.delivery_slot }}{% endif %}
|
||||
<p><i class="fa fa-truck mr-3" aria-label="Date de livraison" title="Date de livraison"
|
||||
aria-hidden="true"></i>
|
||||
Livraison le {{ grouped_order.delivery_date }}{% if grouped_order.delivery_slot %},
|
||||
{{ grouped_order.delivery_slot }}{% endif %}
|
||||
</p>
|
||||
|
||||
{% if user == grouped_order.orga %}
|
||||
|
@ -42,7 +47,8 @@
|
|||
</a>
|
||||
{% else %}
|
||||
<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 %}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -52,7 +58,8 @@
|
|||
<!-- Boite à messages -->
|
||||
{% if not grouped_order.is_to_be_delivered %}
|
||||
<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>
|
||||
{% elif not grouped_order.is_open %}
|
||||
<p>
|
||||
|
@ -60,7 +67,8 @@
|
|||
{% if user == grouped_order.orga %}
|
||||
En tant qu'organisateur·ice, vous pouvez encore commander jusqu'à la date de livraison.
|
||||
{% 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 %}
|
||||
</p>
|
||||
{% endif %}
|
||||
|
@ -86,17 +94,20 @@
|
|||
{% csrf_token %}
|
||||
<td>{{ item.name }}</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 %}
|
||||
<span class="is-italic mini-title">
|
||||
{% if item.get_remaining_nb == 0 %}Produit épuisé
|
||||
{% 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>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<tr>
|
||||
<td></td><td></td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
<td><strong>Total : <span class="total">0</span> €</strong></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
@ -115,13 +126,15 @@
|
|||
<p>{{ item.price }} €</p>
|
||||
</div>
|
||||
<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>
|
||||
{% if item.get_remaining_nb is not null %}
|
||||
<span class="is-italic mini-title">
|
||||
{% if item.get_remaining_nb == 0 %}Produit épuisé
|
||||
{% 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 %}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -138,15 +151,19 @@
|
|||
<div class="columns">
|
||||
<div class="column">
|
||||
<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>
|
||||
<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 class="column">
|
||||
<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>
|
||||
<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>
|
||||
<p><label for="note">Note à l'organisateur·ice</label>
|
||||
|
@ -165,23 +182,21 @@
|
|||
{% endblock %}
|
||||
|
||||
<script>
|
||||
{% block extra_js %}
|
||||
// Compute total price whenever a value in input is modified
|
||||
document.getElementById("inputs-parent").addEventListener("change", function() {
|
||||
var inputs = document.getElementsByTagName("input");
|
||||
{% block extra_js %}
|
||||
// Compute total price whenever a value in input is modified
|
||||
document.getElementById("inputs-parent").addEventListener("change", function () {
|
||||
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;
|
||||
for(let input of inputs){
|
||||
for (let input of inputs) {
|
||||
input_name = input.getAttribute("name");
|
||||
if(input_name.indexOf("quantity_")==0){ // get the quantities inputs only
|
||||
item_id = input_name.split("_")[1];
|
||||
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) {
|
||||
el.innerHTML = total_price;
|
||||
})
|
||||
});
|
||||
{% endblock %}
|
||||
});
|
||||
{% endblock %}
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue