2017-01-15 23:48:09 +00:00
|
|
|
{% extends "cotisations/sidebar.html" %}
|
2017-01-15 23:07:42 +00:00
|
|
|
{% 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 %}
|
|
|
|
|
2016-07-02 13:58:50 +00:00
|
|
|
{% load bootstrap3 %}
|
2016-07-14 11:55:46 +00:00
|
|
|
{% load staticfiles%}
|
2018-04-08 17:41:45 +00:00
|
|
|
{% load i18n %}
|
2016-07-02 13:58:50 +00:00
|
|
|
|
2018-06-23 17:54:20 +00:00
|
|
|
{% block title %}{% trans "Creation and editing of invoices" %}{% endblock %}
|
2016-07-02 13:58:50 +00:00
|
|
|
|
|
|
|
{% block content %}
|
2018-06-23 17:54:20 +00:00
|
|
|
|
2018-07-03 19:38:10 +00:00
|
|
|
{% if title %}
|
2018-06-23 17:54:20 +00:00
|
|
|
<h3>{{ title }}</h3>
|
2018-07-10 16:06:58 +00:00
|
|
|
{% else %}
|
|
|
|
<h3>{% trans "New invoice" %}</h3>
|
2018-07-03 19:38:10 +00:00
|
|
|
{% endif %}
|
2018-07-13 15:52:49 +00:00
|
|
|
{% if max_balance %}
|
2018-06-23 17:54:20 +00:00
|
|
|
<h4>{% blocktrans %}Maximum allowed balance: {{ max_balance }} €{% endblocktrans %}</h4>
|
2018-07-13 15:52:49 +00:00
|
|
|
{% endif %}
|
2018-07-10 16:06:58 +00:00
|
|
|
{% if balance is not None %}
|
|
|
|
<p>
|
2018-06-23 17:54:20 +00:00
|
|
|
{% blocktrans %}Current balance: {{ balance }} €{% endblocktrans %}
|
2018-07-10 16:06:58 +00:00
|
|
|
</p>
|
2018-07-03 19:38:10 +00:00
|
|
|
{% endif %}
|
2018-07-10 16:06:58 +00:00
|
|
|
|
2016-07-02 13:58:50 +00:00
|
|
|
<form class="form" method="post">
|
|
|
|
{% csrf_token %}
|
2018-07-10 16:06:58 +00:00
|
|
|
{% bootstrap_form factureform %}
|
|
|
|
{% if payment_method %}
|
|
|
|
{% bootstrap_form payment_method %}
|
|
|
|
<div id="paymentMethod"></div>
|
|
|
|
{% endif %}
|
2018-04-15 13:34:51 +00:00
|
|
|
{% if articlesformset %}
|
2018-04-11 19:53:54 +00:00
|
|
|
<h3>{% trans "Invoice's articles" %}</h3>
|
|
|
|
<div id="form_set" class="form-group">
|
|
|
|
{{ articlesformset.management_form }}
|
|
|
|
{% for articlesform in articlesformset.forms %}
|
|
|
|
<div class='product_to_sell form-inline'>
|
|
|
|
{% trans "Article" %} :
|
|
|
|
{% bootstrap_form articlesform label_class='sr-only' %}
|
|
|
|
|
|
|
|
<button class="btn btn-danger btn-sm" id="id_form-0-article-remove" type="button">
|
|
|
|
<span class="fa fa-times"></span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
{% endfor %}
|
|
|
|
</div>
|
|
|
|
<input class="btn btn-primary btn-sm" role="button" value="{% trans "Add an article"%}" id="add_one">
|
|
|
|
<p>
|
2018-06-23 17:54:20 +00:00
|
|
|
{% blocktrans %}Total price: <span id="total_price">0,00</span> €{% endblocktrans %}
|
2018-04-11 19:53:54 +00:00
|
|
|
</p>
|
2018-04-15 13:34:51 +00:00
|
|
|
{% endif %}
|
2018-04-08 17:41:45 +00:00
|
|
|
{% bootstrap_button action_name button_type='submit' icon='star' %}
|
2016-07-02 13:58:50 +00:00
|
|
|
</form>
|
2016-07-14 11:55:46 +00:00
|
|
|
|
2018-07-02 19:13:13 +00:00
|
|
|
{% if articlesformset or payment_method%}
|
2018-04-11 19:53:54 +00:00
|
|
|
<script type="text/javascript">
|
2018-07-02 19:13:13 +00:00
|
|
|
{% if articlesformset %}
|
2018-04-11 19:53:54 +00:00
|
|
|
var prices = {};
|
2018-07-13 14:37:33 +00:00
|
|
|
{% for article in articlelist %}
|
2018-04-11 19:53:54 +00:00
|
|
|
prices[{{ article.id|escapejs }}] = {{ article.prix }};
|
|
|
|
{% endfor %}
|
2018-07-02 19:13:13 +00:00
|
|
|
|
2018-04-11 19:53:54 +00:00
|
|
|
var template = `Article :
|
|
|
|
{% bootstrap_form articlesformset.empty_form label_class='sr-only' %}
|
|
|
|
|
|
|
|
<button class="btn btn-danger btn-sm"
|
|
|
|
id="id_form-__prefix__-article-remove" type="button">
|
|
|
|
<span class="fa fa-times"></span>
|
|
|
|
</button>`
|
|
|
|
|
|
|
|
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 ++;
|
|
|
|
var new_article = document.createElement('div');
|
|
|
|
new_article.className = 'product_to_sell form-inline';
|
|
|
|
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);
|
|
|
|
document.getElementById('id_form-' + i.toString() + '-article-remove')
|
|
|
|
.addEventListener("click", function(event) {
|
|
|
|
var article = event.target.parentNode;
|
|
|
|
article.parentNode.removeChild(article);
|
|
|
|
document.getElementById('id_form-TOTAL_FORMS').value --;
|
|
|
|
update_price();
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
update_price();
|
|
|
|
});
|
2018-07-02 19:13:13 +00:00
|
|
|
{% endif %}
|
|
|
|
{% if payment_method.templates %}
|
|
|
|
var TEMPLATES = [
|
|
|
|
"",
|
|
|
|
{% for t in payment_method.templates %}
|
|
|
|
{% if t %}
|
|
|
|
`{% bootstrap_form t %}`,
|
|
|
|
{% else %}
|
|
|
|
"",
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
];
|
|
|
|
function update_payment_method_form(){
|
|
|
|
var method = document.getElementById('paymentMethodSelect').value;
|
|
|
|
if(method==""){
|
|
|
|
method=0;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
method = Number(method);
|
|
|
|
method += 1;
|
|
|
|
}
|
|
|
|
console.log(method);
|
|
|
|
var html = TEMPLATES[method];
|
|
|
|
|
|
|
|
document.getElementById('paymentMethod').innerHTML = html;
|
|
|
|
}
|
|
|
|
document.getElementById("paymentMethodSelect").addEventListener("change", update_payment_method_form);
|
|
|
|
{% endif %}
|
2018-04-11 19:53:54 +00:00
|
|
|
</script>
|
2018-04-15 13:34:51 +00:00
|
|
|
{% endif %}
|
2018-04-11 19:53:54 +00:00
|
|
|
|
2016-07-02 13:58:50 +00:00
|
|
|
{% endblock %}
|
2018-06-23 17:54:20 +00:00
|
|
|
|