Merge branch 'Aufinal/visibilite_stock' into 'k-fet'
K-Psul Articles - Ajout d'une surbrillance pour les articles dont le stock est bas (entre -5 et 5) Panier - Ajout d'indications de stocks sur chaque ligne (stock, warning visuel) - Les ajouts/retraits d'articles déjà dans le panier mettent à jour la ligne associée à celui-ci déjà existante - Les flèches haut/bas permettent de modifier la quantité d'un article Fix #111 See merge request !133
This commit is contained in:
commit
ef864cec32
|
@ -8,7 +8,7 @@ input[type=number]::-webkit-outer-spin-button {
|
||||||
margin: 0;
|
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;
|
background:#fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,7 +252,7 @@ input[type=number]::-webkit-outer-spin-button {
|
||||||
width:100%;
|
width:100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#article_selection input {
|
#article_selection input, #article_selection span {
|
||||||
height:100%;
|
height:100%;
|
||||||
float:left;
|
float:left;
|
||||||
border:0;
|
border:0;
|
||||||
|
@ -263,12 +263,12 @@ input[type=number]::-webkit-outer-spin-button {
|
||||||
font-weight:bold;
|
font-weight:bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
#article_selection input+input {
|
#article_selection input+input #article_selection input+span {
|
||||||
border-right:0;
|
border-right:0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#article_autocomplete {
|
#article_autocomplete {
|
||||||
width:90%;
|
width:80%;
|
||||||
padding-left:10px;
|
padding-left:10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,14 +277,24 @@ input[type=number]::-webkit-outer-spin-button {
|
||||||
text-align:center;
|
text-align:center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#article_stock {
|
||||||
|
width:10%;
|
||||||
|
line-height:38px;
|
||||||
|
text-align:center;
|
||||||
|
}
|
||||||
|
|
||||||
@media (min-width:1200px) {
|
@media (min-width:1200px) {
|
||||||
#article_autocomplete {
|
#article_autocomplete {
|
||||||
width:92%
|
width:84%
|
||||||
}
|
}
|
||||||
|
|
||||||
#article_number {
|
#article_number {
|
||||||
width:8%;
|
width:8%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#article_stock {
|
||||||
|
width:8%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Article data */
|
/* Article data */
|
||||||
|
@ -319,6 +329,10 @@ input[type=number]::-webkit-outer-spin-button {
|
||||||
padding-left:20px;
|
padding-left:20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#articles_data .article.low-stock {
|
||||||
|
background:rgba(236,100,0,0.3);
|
||||||
|
}
|
||||||
|
|
||||||
#articles_data .article:hover {
|
#articles_data .article:hover {
|
||||||
background:rgba(200,16,46,0.3);
|
background:rgba(200,16,46,0.3);
|
||||||
cursor:pointer;
|
cursor:pointer;
|
||||||
|
@ -384,6 +398,11 @@ input[type=number]::-webkit-outer-spin-button {
|
||||||
text-align:right;
|
text-align:right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#basket tr .lowstock {
|
||||||
|
display:none;
|
||||||
|
padding-right:15px;
|
||||||
|
}
|
||||||
|
|
||||||
#basket tr.ui-selected, #basket tr.ui-selecting {
|
#basket tr.ui-selected, #basket tr.ui-selecting {
|
||||||
background-color:rgba(200,16,46,0.6);
|
background-color:rgba(200,16,46,0.6);
|
||||||
color:#FFF;
|
color:#FFF;
|
||||||
|
|
|
@ -123,6 +123,7 @@
|
||||||
<div id="article_selection">
|
<div id="article_selection">
|
||||||
<input type="text" id="article_autocomplete" autocomplete="off">
|
<input type="text" id="article_autocomplete" autocomplete="off">
|
||||||
<input type="number" id="article_number" step="1" min="1">
|
<input type="number" id="article_number" step="1" min="1">
|
||||||
|
<span type="stock" id="article_stock"></span>
|
||||||
<input type="hidden" id="article_id" value="">
|
<input type="hidden" id="article_id" value="">
|
||||||
</div>
|
</div>
|
||||||
<div id="articles_data">
|
<div id="articles_data">
|
||||||
|
@ -616,7 +617,10 @@ $(document).ready(function() {
|
||||||
for (var elem in article) {
|
for (var elem in article) {
|
||||||
article_html.find('.'+elem).text(article[elem])
|
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
|
var category_html = articles_container
|
||||||
.find('#data-category-'+article['category_id']);
|
.find('#data-category-'+article['category_id']);
|
||||||
if (category_html.length == 0) {
|
if (category_html.length == 0) {
|
||||||
|
@ -642,7 +646,7 @@ $(document).ready(function() {
|
||||||
});
|
});
|
||||||
$after.after(article_html);
|
$after.after(article_html);
|
||||||
// Pour l'autocomplétion
|
// 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() {
|
function getArticles() {
|
||||||
|
@ -670,8 +674,9 @@ $(document).ready(function() {
|
||||||
var articleSelect = $('#article_autocomplete');
|
var articleSelect = $('#article_autocomplete');
|
||||||
var articleId = $('#article_id');
|
var articleId = $('#article_id');
|
||||||
var articleNb = $('#article_number');
|
var articleNb = $('#article_number');
|
||||||
// 8:Backspace|9:Tab|13:Enter|46:DEL|112-117:F1-6|119-123:F8-F12
|
var articleStock = $('#article_stock');
|
||||||
var normalKeys = /^(8|9|13|46|112|113|114|115|116|117|119|120|121|122|123)$/;
|
// 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 = [];
|
var articlesList = [];
|
||||||
|
|
||||||
function deleteNonMatching(array, str) {
|
function deleteNonMatching(array, str) {
|
||||||
|
@ -727,6 +732,7 @@ $(document).ready(function() {
|
||||||
if (commit) {
|
if (commit) {
|
||||||
articleId.val(articlesMatch[0][1]);
|
articleId.val(articlesMatch[0][1]);
|
||||||
articleSelect.val(articlesMatch[0][0]);
|
articleSelect.val(articlesMatch[0][0]);
|
||||||
|
articleStock.text('/'+articlesMatch[0][4]);
|
||||||
displayMatchedArticles(articlesList);
|
displayMatchedArticles(articlesList);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -773,10 +779,15 @@ $(document).ready(function() {
|
||||||
return $article.find('.name').text();
|
return $article.find('.name').text();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getArticleStock($article) {
|
||||||
|
return $article.find('.stock').text();
|
||||||
|
}
|
||||||
|
|
||||||
// Sélection des articles à la souris/tactile
|
// Sélection des articles à la souris/tactile
|
||||||
articles_container.on('click', '.article', function() {
|
articles_container.on('click', '.article', function() {
|
||||||
articleId.val(getArticleId($(this)));
|
articleId.val(getArticleId($(this)));
|
||||||
articleSelect.val(getArticleName($(this)));
|
articleSelect.val(getArticleName($(this)));
|
||||||
|
articleStock.text('/'+getArticleStock($(this)));
|
||||||
displayMatchedArticles(articlesList);
|
displayMatchedArticles(articlesList);
|
||||||
goToArticleNb();
|
goToArticleNb();
|
||||||
});
|
});
|
||||||
|
@ -790,6 +801,7 @@ $(document).ready(function() {
|
||||||
addPurchase(articleId.val(), articleNb.val());
|
addPurchase(articleId.val(), articleNb.val());
|
||||||
articleSelect.val('');
|
articleSelect.val('');
|
||||||
articleNb.val('');
|
articleNb.val('');
|
||||||
|
articleStock.text('');
|
||||||
articleSelect.focus();
|
articleSelect.focus();
|
||||||
displayMatchedArticles(articlesList);
|
displayMatchedArticles(articlesList);
|
||||||
return false;
|
return false;
|
||||||
|
@ -809,7 +821,7 @@ $(document).ready(function() {
|
||||||
// Basket
|
// 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 basket_container = $('#basket table');
|
||||||
var arrowKeys = /^(37|38|39|40)$/;
|
var arrowKeys = /^(37|38|39|40)$/;
|
||||||
|
|
||||||
|
@ -827,17 +839,40 @@ $(document).ready(function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function addPurchase(id, nb) {
|
function addPurchase(id, nb) {
|
||||||
|
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 amount_euro = amountEuroPurchase(id, nb).toFixed(2);
|
||||||
var index = addPurchaseToFormset(article_data[1], nb, amount_euro);
|
var index = addPurchaseToFormset(article_data[1], nb, amount_euro);
|
||||||
article_basket_html = $(item_basket_default_html);
|
article_basket_html = $(item_basket_default_html);
|
||||||
article_basket_html
|
article_basket_html
|
||||||
.attr('data-opeindex', index)
|
.attr('data-opeindex', index)
|
||||||
.find('.number').text(nb).end()
|
.find('.number').text('('+nb+'/'+article_data[4]+')').end()
|
||||||
.find('.name').text(article_data[0]).end()
|
.find('.name').text(article_data[0]).end()
|
||||||
.find('.amount').text(amountToUKF(amount_euro, account_data['is_cof'], false));
|
.find('.amount').text(amountToUKF(amount_euro, account_data['is_cof']), false);
|
||||||
basket_container.prepend(article_basket_html);
|
basket_container.prepend(article_basket_html);
|
||||||
|
if (is_low_stock(id, nb))
|
||||||
|
article_basket_html.find('.lowstock')
|
||||||
|
.show();
|
||||||
updateBasketRel();
|
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) {
|
function addDeposit(amount, is_checkout=1) {
|
||||||
var deposit_basket_html = $(item_basket_default_html);
|
var deposit_basket_html = $(item_basket_default_html);
|
||||||
|
@ -871,11 +906,25 @@ $(document).ready(function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on('keydown', function (e) {
|
$(document).on('keydown', function (e) {
|
||||||
if (e.keyCode == 46) {
|
switch(e.which) {
|
||||||
|
case 46:
|
||||||
// DEL (Suppr)
|
// DEL (Suppr)
|
||||||
basket_container.find('.ui-selected').each(function () {
|
basket_container.find('.ui-selected').each(function () {
|
||||||
deleteFromBasket($(this).data('opeindex'));
|
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();
|
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() {
|
function resetBasket() {
|
||||||
basket_container.find('tr').remove();
|
basket_container.find('tr').remove();
|
||||||
mngmt_total_forms = 1;
|
mngmt_total_forms = 1;
|
||||||
|
@ -948,6 +1037,7 @@ $(document).ready(function() {
|
||||||
articleId.val(0);
|
articleId.val(0);
|
||||||
articleSelect.val('');
|
articleSelect.val('');
|
||||||
articleNb.val('');
|
articleNb.val('');
|
||||||
|
articleStock.text('');
|
||||||
displayMatchedArticles(articlesList);
|
displayMatchedArticles(articlesList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1072,7 +1162,14 @@ $(document).ready(function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteFromFormset(opeindex) {
|
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++) {
|
for (var i=0; i<data['articles'].length; i++) {
|
||||||
article = data['articles'][i];
|
article = data['articles'][i];
|
||||||
|
articles_container.find('#data-article-'+article['id'])
|
||||||
|
.addClass('low-stock');
|
||||||
articles_container.find('#data-article-'+article['id']+' .stock')
|
articles_container.find('#data-article-'+article['id']+' .stock')
|
||||||
.text(article['stock']);
|
.text(article['stock']);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue