diff --git a/kfet/static/kfet/css/kpsul.css b/kfet/static/kfet/css/kpsul.css
index e7950914..ba88e433 100644
--- a/kfet/static/kfet/css/kpsul.css
+++ b/kfet/static/kfet/css/kpsul.css
@@ -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;
diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html
index e064a10c..264422f0 100644
--- a/kfet/templates/kfet/kpsul.html
+++ b/kfet/templates/kfet/kpsul.html
@@ -123,6 +123,7 @@
@@ -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 = '
| | |
';
+ var item_basket_default_html = '
| | | |
';
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
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