forked from DGNum/gestioCOF
Merge branch 'k-fet' of git.eleves.ens.fr:cof-geek/gestioCOF into Aufinal/command_interface
This commit is contained in:
commit
61e2fedb08
17 changed files with 28734 additions and 86 deletions
|
@ -10,6 +10,18 @@
|
|||
<script type="text/javascript" src="{% static 'kfet/js/moment-timezone-with-data-2010-2020.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'kfet/js/kfet.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'kfet/js/history.js' %}"></script>
|
||||
{% if account.user == request.user %}
|
||||
<script type="text/javascript" src="{% static 'kfet/js/Chart.bundle.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'kfet/js/statistic.js' %}"></script>
|
||||
<script>
|
||||
jQuery(document).ready(function() {
|
||||
var stat_last = new StatsGroup("{% url 'kfet.account.stat.last' trigramme=account.trigramme %}",
|
||||
$("#stat_last"));
|
||||
var stat_balance = new StatsGroup("{% url 'kfet.account.stat.balance' trigramme=account.trigramme %}",
|
||||
$("#stat_balance"));
|
||||
});
|
||||
</script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block title %}
|
||||
|
@ -51,6 +63,27 @@
|
|||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if account.user == request.user %}
|
||||
<div class="content-right-block content-right-block-transparent">
|
||||
<h2>Statistiques</h2>
|
||||
<div class="row">
|
||||
<div class="col-sm-12 nopadding">
|
||||
<div class="panel-md-margin">
|
||||
<h3>Ma balance</h3>
|
||||
<div id="stat_balance" class"stat-graph"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- /row -->
|
||||
<div class="row">
|
||||
<div class="col-sm-12 nopadding">
|
||||
<div class="panel-md-margin">
|
||||
<h3>Ma consommation</h3>
|
||||
<div id="stat_last" class"stat-graph"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- /row -->
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="content-right-block">
|
||||
<h2>Historique</h2>
|
||||
<div id="history">
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{% extends 'kfet/base.html' %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block title %}Informations sur l'article {{ article }}{% endblock %}
|
||||
{% block content-header-title %}Article - {{ article.name }}{% endblock %}
|
||||
|
@ -76,10 +77,32 @@
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- /row-->
|
||||
</div>
|
||||
<div class="content-right-block content-right-block-transparent">
|
||||
<h2>Statistiques</h2>
|
||||
<div class="row">
|
||||
<div class="col-sm-12 nopadding">
|
||||
<div class="panel-md-margin">
|
||||
<h3>Ventes de {{ article.name }}</h3>
|
||||
<div id="stat_last"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- /row -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_head %}
|
||||
<script type="text/javascript" src="{% static 'kfet/js/Chart.bundle.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'kfet/js/statistic.js' %}"></script>
|
||||
<script>
|
||||
jQuery(document).ready(function() {
|
||||
var stat_last = $("#stat_last");
|
||||
var stat_last_url = "{% url 'kfet.article.stat.last' article.id %}";
|
||||
STAT.get_thing(stat_last_url, stat_last, "Stat non trouvées :(");
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
17
kfet/templates/kfet/home.html
Normal file
17
kfet/templates/kfet/home.html
Normal file
|
@ -0,0 +1,17 @@
|
|||
{% extends "kfet/base.html" %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block title %}Accueil{% endblock %}
|
||||
{% block content-header-title %}Accueil{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-4 col-md-3 col-content-left">
|
||||
</div>
|
||||
<div class="col-sm-8 col-md-9 col-content-right">
|
||||
{% include 'kfet/base_messages.html' %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
|
@ -123,6 +123,7 @@
|
|||
<div id="article_selection">
|
||||
<input type="text" id="article_autocomplete" autocomplete="off">
|
||||
<input type="number" id="article_number" step="1" min="1">
|
||||
<span type="stock" id="article_stock"></span>
|
||||
<input type="hidden" id="article_id" value="">
|
||||
</div>
|
||||
<div id="articles_data">
|
||||
|
@ -221,7 +222,7 @@ $(document).ready(function() {
|
|||
function displayAccountData() {
|
||||
var balance = account_data['trigramme'] != 'LIQ' ? account_data['balance'] : '';
|
||||
if (balance != '')
|
||||
balance = amountToUKF(account_data['balance'], account_data['is_cof']);
|
||||
balance = amountToUKF(account_data['balance'], account_data['is_cof'], true);
|
||||
var is_cof = account_data['trigramme'] ? account_data['is_cof'] : '';
|
||||
if (is_cof !== '')
|
||||
is_cof = is_cof ? '<b>COF</b>' : '<b>Non-COF</b>';
|
||||
|
@ -616,7 +617,10 @@ $(document).ready(function() {
|
|||
for (var elem in article) {
|
||||
article_html.find('.'+elem).text(article[elem])
|
||||
}
|
||||
article_html.find('.price').text(amountToUKF(article['price'], false));
|
||||
if (-5 <= article['stock'] && article['stock'] <= 5) {
|
||||
article_html.addClass('low-stock');
|
||||
}
|
||||
article_html.find('.price').text(amountToUKF(article['price'], false, false)+' UKF');
|
||||
var category_html = articles_container
|
||||
.find('#data-category-'+article['category_id']);
|
||||
if (category_html.length == 0) {
|
||||
|
@ -642,7 +646,7 @@ $(document).ready(function() {
|
|||
});
|
||||
$after.after(article_html);
|
||||
// Pour l'autocomplétion
|
||||
articlesList.push([article['name'],article['id'],article['category_id'],article['price']]);
|
||||
articlesList.push([article['name'],article['id'],article['category_id'],article['price'], article['stock']]);
|
||||
}
|
||||
|
||||
function getArticles() {
|
||||
|
@ -670,8 +674,9 @@ $(document).ready(function() {
|
|||
var articleSelect = $('#article_autocomplete');
|
||||
var articleId = $('#article_id');
|
||||
var articleNb = $('#article_number');
|
||||
// 8:Backspace|9:Tab|13:Enter|46:DEL|112-117:F1-6|119-123:F8-F12
|
||||
var normalKeys = /^(8|9|13|46|112|113|114|115|116|117|119|120|121|122|123)$/;
|
||||
var articleStock = $('#article_stock');
|
||||
// 8:Backspace|9:Tab|13:Enter|38-40:Arrows|46:DEL|112-117:F1-6|119-123:F8-F12
|
||||
var normalKeys = /^(8|9|13|37|38|39|40|46|112|113|114|115|116|117|119|120|121|122|123)$/;
|
||||
var articlesList = [];
|
||||
|
||||
function deleteNonMatching(array, str) {
|
||||
|
@ -727,6 +732,7 @@ $(document).ready(function() {
|
|||
if (commit) {
|
||||
articleId.val(articlesMatch[0][1]);
|
||||
articleSelect.val(articlesMatch[0][0]);
|
||||
articleStock.text('/'+articlesMatch[0][4]);
|
||||
displayMatchedArticles(articlesList);
|
||||
return true;
|
||||
}
|
||||
|
@ -773,10 +779,15 @@ $(document).ready(function() {
|
|||
return $article.find('.name').text();
|
||||
}
|
||||
|
||||
function getArticleStock($article) {
|
||||
return $article.find('.stock').text();
|
||||
}
|
||||
|
||||
// Sélection des articles à la souris/tactile
|
||||
articles_container.on('click', '.article', function() {
|
||||
articleId.val(getArticleId($(this)));
|
||||
articleSelect.val(getArticleName($(this)));
|
||||
articleStock.text('/'+getArticleStock($(this)));
|
||||
displayMatchedArticles(articlesList);
|
||||
goToArticleNb();
|
||||
});
|
||||
|
@ -790,6 +801,7 @@ $(document).ready(function() {
|
|||
addPurchase(articleId.val(), articleNb.val());
|
||||
articleSelect.val('');
|
||||
articleNb.val('');
|
||||
articleStock.text('');
|
||||
articleSelect.focus();
|
||||
displayMatchedArticles(articlesList);
|
||||
return false;
|
||||
|
@ -809,7 +821,7 @@ $(document).ready(function() {
|
|||
// Basket
|
||||
// -----
|
||||
|
||||
var item_basket_default_html = '<tr><td class="amount"></td><td class="number"></td><td class="name"></td></tr>';
|
||||
var item_basket_default_html = '<tr><td class="amount"></td><td class="number"></td><td ><span class="lowstock glyphicon glyphicon-alert"></span></td><td class="name"></td></tr>';
|
||||
var basket_container = $('#basket table');
|
||||
var arrowKeys = /^(37|38|39|40)$/;
|
||||
|
||||
|
@ -827,16 +839,39 @@ $(document).ready(function() {
|
|||
}
|
||||
|
||||
function addPurchase(id, nb) {
|
||||
var amount_euro = amountEuroPurchase(id, nb).toFixed(2);
|
||||
var index = addPurchaseToFormset(article_data[1], nb, amount_euro);
|
||||
article_basket_html = $(item_basket_default_html);
|
||||
article_basket_html
|
||||
.attr('data-opeindex', index)
|
||||
.find('.number').text(nb).end()
|
||||
.find('.name').text(article_data[0]).end()
|
||||
.find('.amount').text(amountToUKF(amount_euro, account_data['is_cof']));
|
||||
basket_container.prepend(article_basket_html);
|
||||
updateBasketRel();
|
||||
var existing = false;
|
||||
formset_container.find('[data-opeindex]').each(function () {
|
||||
var opeindex = $(this).attr('data-opeindex');
|
||||
var article_id = $(this).find('#id_form-'+opeindex+'-article').val();
|
||||
if (article_id == id) {
|
||||
existing = true ;
|
||||
addExistingPurchase(opeindex, nb);
|
||||
}
|
||||
});
|
||||
if (!existing) {
|
||||
var amount_euro = amountEuroPurchase(id, nb).toFixed(2);
|
||||
var index = addPurchaseToFormset(article_data[1], nb, amount_euro);
|
||||
article_basket_html = $(item_basket_default_html);
|
||||
article_basket_html
|
||||
.attr('data-opeindex', index)
|
||||
.find('.number').text('('+nb+'/'+article_data[4]+')').end()
|
||||
.find('.name').text(article_data[0]).end()
|
||||
.find('.amount').text(amountToUKF(amount_euro, account_data['is_cof']), false);
|
||||
basket_container.prepend(article_basket_html);
|
||||
if (is_low_stock(id, nb))
|
||||
article_basket_html.find('.lowstock')
|
||||
.show();
|
||||
updateBasketRel();
|
||||
}
|
||||
}
|
||||
|
||||
function is_low_stock(id, nb) {
|
||||
var i = 0 ;
|
||||
while (i<articlesList.length && id != articlesList[i][1]) i++;
|
||||
article_data = articlesList[i];
|
||||
|
||||
stock = article_data[4] ;
|
||||
return (-5 <= stock - nb && stock - nb <= 5);
|
||||
}
|
||||
|
||||
function addDeposit(amount, is_checkout=1) {
|
||||
|
@ -848,7 +883,7 @@ $(document).ready(function() {
|
|||
.attr('data-opeindex', index)
|
||||
.find('.number').text(amount+"€").end()
|
||||
.find('.name').text(text).end()
|
||||
.find('.amount').text(amountToUKF(amount, account_data['is_cof']));
|
||||
.find('.amount').text(amountToUKF(amount, account_data['is_cof'], false));
|
||||
basket_container.prepend(deposit_basket_html);
|
||||
updateBasketRel();
|
||||
}
|
||||
|
@ -861,7 +896,7 @@ $(document).ready(function() {
|
|||
.attr('data-opeindex', index)
|
||||
.find('.number').text(amount+"€").end()
|
||||
.find('.name').text('Retrait').end()
|
||||
.find('.amount').text(amountToUKF(amount, account_data['is_cof']));
|
||||
.find('.amount').text(amountToUKF(amount, account_data['is_cof'], false));
|
||||
basket_container.prepend(withdraw_basket_html);
|
||||
updateBasketRel();
|
||||
}
|
||||
|
@ -871,11 +906,25 @@ $(document).ready(function() {
|
|||
});
|
||||
|
||||
$(document).on('keydown', function (e) {
|
||||
if (e.keyCode == 46) {
|
||||
// DEL (Suppr)
|
||||
basket_container.find('.ui-selected').each(function () {
|
||||
deleteFromBasket($(this).data('opeindex'));
|
||||
});
|
||||
switch(e.which) {
|
||||
case 46:
|
||||
// DEL (Suppr)
|
||||
basket_container.find('.ui-selected').each(function () {
|
||||
deleteFromBasket($(this).data('opeindex'));
|
||||
});
|
||||
break;
|
||||
case 38:
|
||||
// Arrow up
|
||||
basket_container.find('.ui-selected').each(function () {
|
||||
addExistingPurchase($(this).data('opeindex'), 1);
|
||||
});
|
||||
break;
|
||||
case 40:
|
||||
// Arrow down
|
||||
basket_container.find('.ui-selected').each(function () {
|
||||
addExistingPurchase($(this).data('opeindex'), -1);
|
||||
});
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -903,7 +952,7 @@ $(document).ready(function() {
|
|||
var amount = $(this).find('#id_form-'+opeindex+'-amount');
|
||||
if (!deleted && type == "purchase")
|
||||
amount.val(amountEuroPurchase(article_id, article_nb));
|
||||
basket_container.find('[data-opeindex='+opeindex+'] .amount').text(amountToUKF(amount.val(), account_data['is_cof']));
|
||||
basket_container.find('[data-opeindex='+opeindex+'] .amount').text(amountToUKF(amount.val(), account_data['is_cof'], false));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -922,9 +971,9 @@ $(document).ready(function() {
|
|||
basketrel_html += '<div>Sur 20€: '+ (20-amount).toFixed(2) +' €</div>';
|
||||
} else if (account_data['trigramme'] != '' && !isBasketEmpty()) {
|
||||
var amount = getAmountBasket();
|
||||
var amountUKF = amountToUKF(amount, account_data['is_cof']);
|
||||
var amountUKF = amountToUKF(amount, account_data['is_cof'], false);
|
||||
var newBalance = account_data['balance'] + amount;
|
||||
var newBalanceUKF = amountToUKF(newBalance, account_data['is_cof']);
|
||||
var newBalanceUKF = amountToUKF(newBalance, account_data['is_cof'], true);
|
||||
basketrel_html += '<div>Total: '+amountUKF+'</div>';
|
||||
basketrel_html += '<div>Nouveau solde: '+newBalanceUKF+'</div>';
|
||||
if (newBalance < 0)
|
||||
|
@ -939,6 +988,46 @@ $(document).ready(function() {
|
|||
updateBasketRel();
|
||||
}
|
||||
|
||||
function addExistingPurchase(opeindex, nb) {
|
||||
var type = formset_container.find("#id_form-"+opeindex+"-type").val();
|
||||
var id = formset_container.find("#id_form-"+opeindex+"-article").val();
|
||||
var nb_before = formset_container.find("#id_form-"+opeindex+"-article_nb").val();
|
||||
var nb_after = parseInt(nb_before) + parseInt(nb);
|
||||
var amountEuro_after = amountEuroPurchase(id, nb_after);
|
||||
var amountUKF_after = amountToUKF(amountEuro_after, account_data['is_cof']);
|
||||
|
||||
if (type == 'purchase') {
|
||||
if (nb_after == 0) {
|
||||
deleteFromBasket(opeindex);
|
||||
} else if (nb_after > 0 && nb_after <= 25) {
|
||||
if (nb_before > 0) {
|
||||
var article_html = basket_container.find('[data-opeindex='+opeindex+']');
|
||||
article_html.find('.amount').text(amountUKF_after).end()
|
||||
.find('.number').text('('+nb_after+'/'+article_data[4]+')').end() ;
|
||||
|
||||
} else {
|
||||
article_html = $(item_basket_default_html);
|
||||
article_html
|
||||
.attr('data-opeindex', opeindex)
|
||||
.find('.number').text('('+nb_after+'/'+article_data[4]+')').end()
|
||||
.find('.name').text(article_data[0]).end()
|
||||
.find('.amount').text(amountUKF_after);
|
||||
basket_container.prepend(article_basket_html);
|
||||
|
||||
}
|
||||
|
||||
if (is_low_stock(id, nb_after))
|
||||
article_html.find('.lowstock')
|
||||
.show();
|
||||
else
|
||||
article_html.find('.lowstock')
|
||||
.hide();
|
||||
updateExistingFormset(opeindex, nb_after, amountEuro_after);
|
||||
updateBasketRel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function resetBasket() {
|
||||
basket_container.find('tr').remove();
|
||||
mngmt_total_forms = 1;
|
||||
|
@ -948,6 +1037,7 @@ $(document).ready(function() {
|
|||
articleId.val(0);
|
||||
articleSelect.val('');
|
||||
articleNb.val('');
|
||||
articleStock.text('');
|
||||
displayMatchedArticles(articlesList);
|
||||
}
|
||||
|
||||
|
@ -1072,7 +1162,14 @@ $(document).ready(function() {
|
|||
}
|
||||
|
||||
function deleteFromFormset(opeindex) {
|
||||
formset_container.find('#id_form-'+opeindex+'-DELETE').prop('checked', true);
|
||||
updateExistingFormset(opeindex, 0, '0.00');
|
||||
}
|
||||
|
||||
function updateExistingFormset(opeindex, nb, amount) {
|
||||
formset_container
|
||||
.find('#id_form-'+opeindex+'-amount').val((parseFloat(amount)).toFixed(2)).end()
|
||||
.find('#id_form-'+opeindex+'-article_nb').val(nb).end()
|
||||
.find('#id_form-'+opeindex+'-DELETE').prop('checked', !nb);
|
||||
}
|
||||
|
||||
// -----
|
||||
|
@ -1251,6 +1348,8 @@ $(document).ready(function() {
|
|||
}
|
||||
for (var i=0; i<data['articles'].length; i++) {
|
||||
article = data['articles'][i];
|
||||
articles_container.find('#data-article-'+article['id'])
|
||||
.addClass('low-stock');
|
||||
articles_container.find('#data-article-'+article['id']+' .stock')
|
||||
.text(article['stock']);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue