Rajoute des indications de stocks #437

Merged
lstephan merged 17 commits from Aufinal/visibilite_stock into k-fet 2017-02-13 16:43:41 +01:00
2 changed files with 144 additions and 26 deletions

View file

@ -8,7 +8,7 @@ input[type=number]::-webkit-outer-spin-button {
margin: 0;
}
#account, #checkout, input, #history, #basket, #basket_rel, #previous_op, #articles_data {
#account, #checkout, #article_selection, #history, #basket, #basket_rel, #previous_op, #articles_data {
background:#fff;
}
@ -252,7 +252,7 @@ input[type=number]::-webkit-outer-spin-button {
width:100%;
}
#article_selection input {
#article_selection input, #article_selection span {
height:100%;
float:left;
border:0;
@ -263,12 +263,12 @@ input[type=number]::-webkit-outer-spin-button {
font-weight:bold;
}
#article_selection input+input {
#article_selection input+input #article_selection input+span {
border-right:0;
}
#article_autocomplete {
width:90%;
width:80%;
padding-left:10px;
}
@ -277,14 +277,24 @@ input[type=number]::-webkit-outer-spin-button {
text-align:center;
}
#article_stock {
width:10%;
line-height:38px;
text-align:center;
}
@media (min-width:1200px) {
#article_autocomplete {
width:92%
width:84%
}
#article_number {
width:8%;
}
#article_stock {
width:8%;
}
}
/* Article data */
@ -319,6 +329,10 @@ input[type=number]::-webkit-outer-spin-button {
padding-left:20px;
}
#articles_data .article.low-stock {
background:rgba(236,100,0,0.3);
}
#articles_data .article:hover {
background:rgba(200,16,46,0.3);
cursor:pointer;
@ -384,6 +398,11 @@ input[type=number]::-webkit-outer-spin-button {
text-align:right;
}
#basket tr .lowstock {
display:none;
padding-right:15px;
}
#basket tr.ui-selected, #basket tr.ui-selecting {
background-color:rgba(200,16,46,0.6);
color:#FFF;

View file

@ -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">
@ -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, 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'], false));
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) {
@ -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;
}
});
@ -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']);
}