@@ -99,16 +100,30 @@ $(document).ready(function() {
});
/*
- * Remove warning if .finished is unchecked
+ * Remove warning and update stock
*/
+ function update_stock($line) {
+ $line.removeClass('inventory_modified');
+ $line.find('.inventory_update').hide();
+
+ var old_stock = +$line.find('.current_stock').text()
+ var stock_diff = +$line.find('.stock_diff').text();
+ $line.find('.current_stock').text(old_stock + stock_diff);
+ $line.find('.stock_diff').text('');
+
+ var id = $line.find('input[type="hidden"]').val();
+ conflicts = conflicts.filter(item => item != id);
+ }
+
$('.finished input').change(function() {
- if (!$(this).is(":checked")) {
- var $line = $(this).closest('tr');
- var id = $line.find('input[type="hidden"]').val();
- $(this).closest('tr').removeClass('inventory_modified');
- conflicts = conflicts.filter(item => item != id);
- }
+ var $line = $(this).closest('tr');
+ update_stock($line);
+ });
+
+ $('.inventory_update button').click(function() {
+ var $line = $(this).closest('tr');
+ update_stock($line);
});
@@ -127,9 +142,20 @@ $(document).ready(function() {
var data = $.extend({}, websocket_msg_default, JSON.parse(e.data));
for (let article of data['articles']) {
var $line = $('input[value="'+article.id+'"]').parent();
- if ($line.find('.finished input').prop("checked")) {
+ if ($line.find('.finished input').is(":checked")) {
conflicts.push(article.id);
+ //Display warning
$line.addClass('inventory_modified');
+
+ //Realigning input and displaying update button
+ $line.find('.inventory_update').show();
+
+ //Displaying stock changes
+ var stock = $line.find('.current_stock').text();
+ $line.find('.stock_diff').text(article.stock - stock);
+ } else {
+ // If we haven't counted the article yet, we simply update the expected stock
+ $line.find('.current_stock').text(article.stock);
}
}
}
@@ -144,8 +170,10 @@ $(document).ready(function() {
content += "Conflits possibles :"
content += '
';
for (let id of conflicts) {
- var name = $('input[value="'+id+'"]').siblings('.name').text();
- content += '
'+name+'
';
+ var $line = $('input[value="'+id+'"]').closest('tr');
+ var name = $line.find('.name').text();
+ var stock_diff = $line.find('.stock_diff').text();
+ content += '