mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-30 00:22:25 +00:00
140 lines
5.1 KiB
HTML
140 lines
5.1 KiB
HTML
{% extends "cotisations/sidebar.html" %}
|
|
{% comment %}
|
|
Re2o est un logiciel d'administration développé initiallement au rezometz. Il
|
|
se veut agnostique au réseau considéré, de manière à être installable en
|
|
quelques clics.
|
|
|
|
Copyright © 2017 Gabriel Détraz
|
|
Copyright © 2017 Goulven Kermarec
|
|
Copyright © 2017 Augustin Lemesle
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
{% endcomment %}
|
|
|
|
{% load bootstrap3 %}
|
|
{% load staticfiles%}
|
|
|
|
{% block title %}Création et modification de factures{% endblock %}
|
|
|
|
{% block content %}
|
|
{% bootstrap_form_errors factureform %}
|
|
|
|
<form class="form" method="post">
|
|
{% csrf_token %}
|
|
<h3>Nouvelle facture</h3>
|
|
{% bootstrap_form factureform %}
|
|
{{ venteform.management_form }}
|
|
<!-- TODO: FIXME to include data-type="check" for right option in id_cheque select -->
|
|
<h3>Articles de la facture</h3>
|
|
<div id="form_set">
|
|
{% for form in venteform.forms %}
|
|
<div class='product_to_sell'>
|
|
<p>
|
|
{{ form.as_table }}
|
|
</p>
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
<p>
|
|
<input class="btn btn-primary btn-sm" role="button" value="Ajouter un article" id="add_one">
|
|
</p>
|
|
<p>
|
|
Prix total : <span id="total_price">0,00</span> €
|
|
</p>
|
|
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
|
|
</form>
|
|
|
|
<script type="text/javascript">
|
|
|
|
var prices = {};
|
|
{% for article in articlelist %}
|
|
prices[{{ article.id|escapejs }}] = {{ article.prix }};
|
|
{% endfor %}
|
|
|
|
var template = `<p>{{ venteform.empty_form.as_table }}</p>`;
|
|
|
|
function add_article(){
|
|
// Index start at 0 => new_index = number of items
|
|
var new_index =
|
|
document.getElementsByClassName('product_to_sell').length;
|
|
document.getElementById('id_form-TOTAL_FORMS').value =
|
|
parseInt(document.getElementById('id_form-TOTAL_FORMS').value) + 1;
|
|
var new_article = document.createElement('div');
|
|
new_article.className = 'product_to_sell';
|
|
new_article.innerHTML = template.replace(/__prefix__/g, new_index);
|
|
document.getElementById('form_set')
|
|
.appendChild(new_article);
|
|
add_listenner_for_id(new_index);
|
|
}
|
|
|
|
function update_price(){
|
|
var price = 0;
|
|
var product_count =
|
|
document.getElementsByClassName('product_to_sell').length;
|
|
var article, article_price, quantity;
|
|
for (i = 0; i < product_count; ++i){
|
|
article = document.getElementById(
|
|
'id_form-' + i.toString() + '-article').value;
|
|
if (article == '') {
|
|
continue;
|
|
}
|
|
article_price = prices[article];
|
|
quantity = document.getElementById(
|
|
'id_form-' + i.toString() + '-quantity').value;
|
|
price += article_price * quantity;
|
|
}
|
|
document.getElementById('total_price').innerHTML =
|
|
price.toFixed(2).toString().replace('.', ',');
|
|
}
|
|
|
|
function add_listenner_for_id(i){
|
|
document.getElementById('id_form-' + i.toString() + '-article')
|
|
.addEventListener("change", update_price, true);
|
|
document.getElementById('id_form-' + i.toString() + '-article')
|
|
.addEventListener("onkeypress", update_price, true);
|
|
document.getElementById('id_form-' + i.toString() + '-quantity')
|
|
.addEventListener("change", update_price, true);
|
|
}
|
|
|
|
function set_cheque_info_visibility(){
|
|
var visible = document.getElementById("id_paiement").value == document.getElementById("id_paiement").getAttribute('data-cheque');
|
|
p = document.getElementById("id_paiement")
|
|
console.log(p);
|
|
var display = 'none';
|
|
if (visible) {
|
|
display = 'block';
|
|
}
|
|
document.getElementById("id_cheque").parentNode.style.display = display;
|
|
document.getElementById("id_banque").parentNode.style.display = display;
|
|
}
|
|
|
|
// Add events manager when DOM is fully loaded
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
document.getElementById("add_one")
|
|
.addEventListener("click", add_article, true);
|
|
var product_count =
|
|
document.getElementsByClassName('product_to_sell').length;
|
|
for (i = 0; i < product_count; ++i){
|
|
add_listenner_for_id(i);
|
|
}
|
|
document.getElementById("id_paiement")
|
|
.addEventListener("change", set_cheque_info_visibility, true);
|
|
set_cheque_info_visibility();
|
|
update_price();
|
|
});
|
|
|
|
</script>
|
|
|
|
{% endblock %}
|