gestioCOF/kfet/templates/kfet/inventory_create.html

207 lines
6.9 KiB
HTML
Raw Normal View History

{% extends 'kfet/base.html' %}
{% load staticfiles %}
2017-03-31 11:07:37 -03:00
{% load widget_tweaks %}
{% block extra_head %}
<script type="text/javascript" src="{% static 'kfet/js/reconnecting-websocket.js' %}"></script>
<script type="text/javascript" src="{% static 'kfet/js/jquery-confirm.js' %}"></script>
{% endblock %}
{% block title %}Nouvel inventaire{% endblock %}
{% block content-header-title %}Nouvel inventaire{% endblock %}
{% block content %}
{% include 'kfet/base_messages.html' %}
2017-03-28 23:47:41 -03:00
<div class="content-center">
<div>
<form id='inventoryform' action="" method="post">
2017-03-28 23:47:41 -03:00
<table class="table text-center">
<thead>
<tr>
2017-03-28 23:47:41 -03:00
<td>Article</td>
<td>Quantité par caisse</td>
<td>Stock Théorique</td>
<td>Caisses en réserve</td>
<td>Caisses en arrière</td>
<td>Vrac</td>
<td>Stock total</td>
2017-03-29 20:43:48 -03:00
<td>Compte terminé</td>
</tr>
2017-03-28 23:47:41 -03:00
</thead>
<tbody>
{% for form in formset %}
{% ifchanged form.category %}
<tr class='section'>
<td>{{ form.category_name }}</td>
2017-03-29 20:43:48 -03:00
<td colspan="7"></td>
2017-03-28 23:47:41 -03:00
</tr>
{% endifchanged %}
<tr>
{{ form.article }}
2017-03-29 20:43:48 -03:00
<td class='name'>{{ form.name }}</td>
2017-03-30 13:30:55 -03:00
<td class='box_capacity'>{{ form.box_capacity }}</td>
<td><span class='current_stock'>{{ form.stock_old }}</span><span class='stock_diff'></span></td>
2017-03-29 20:43:48 -03:00
<td class='box_cellar'>
2017-03-28 23:47:41 -03:00
<div class='col-md-2'></div>
<div class='col-md-8'>
2017-03-30 13:30:55 -03:00
<input type='number' class='form-control' step='1'>
2017-03-28 23:47:41 -03:00
</div>
</td>
2017-03-29 20:43:48 -03:00
<td class='box_bar'>
2017-03-31 09:50:37 -03:00
<div class='col-md-offset-2 col-md-8'><input type='number' class='form-control' step='1'></div>
2017-03-28 23:47:41 -03:00
</td>
2017-03-29 20:43:48 -03:00
<td class='misc'>
2017-03-31 09:50:37 -03:00
<div class='col-md-offset-2 col-md-8'><input type='number' class='form-control' step='1'></div>
2017-03-28 23:47:41 -03:00
</td>
2017-03-29 20:43:48 -03:00
<td class='stock_new'>
2017-03-31 11:07:37 -03:00
<div class='col-md-offset-2 col-md-8'>{{ form.stock_new | attr:"readonly"| add_class:"form-control" }}</div>
2017-03-30 13:31:16 -03:00
<div class='col-md-2 inventory_update'><button type='button' class='btn-sm btn-primary'>MàJ</button></div>
2017-03-28 23:47:41 -03:00
</td>
2017-03-30 13:30:55 -03:00
<td class='finished'><input type='checkbox' class='form_control'></td>
2017-03-28 23:47:41 -03:00
</tr>
{% endfor %}
</tbody>
</table>
2017-03-28 23:47:41 -03:00
{{ formset.management_form }}
{% if not perms.kfet.add_inventory %}
<div class='auth-form form-horizontal'>
{% include "kfet/form_authentication_snippet.html" %}
</div>
2017-03-28 23:47:41 -03:00
{% endif %}
<input type="submit" value="Enregistrer" class="btn btn-primary btn-lg btn-block">
2017-03-28 23:47:41 -03:00
{% csrf_token %}
</form>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
'use strict';
2017-04-03 16:05:18 -03:00
var conflicts = new Set();
/**
* Autofill new stock from other inputs
*/
2017-03-28 23:47:41 -03:00
$('input[type="number"]').on('input', function() {
var $line = $(this).closest('tr');
2017-03-29 20:43:48 -03:00
var box_capacity = +$line.find('.box_capacity').text();
2017-03-30 13:30:55 -03:00
var box_cellar = $line.find('.box_cellar input').val();
var box_bar = $line.find('.box_bar input').val();
var misc = $line.find('.misc input').val();
if (box_cellar || box_bar || misc)
$line.find('.stock_new input').val(
box_capacity*((+box_cellar) +(+box_bar))+(+misc));
else
$line.find('.stock_new input').val('');
2017-03-29 20:43:48 -03:00
});
/*
2017-03-30 13:31:16 -03:00
* Remove warning and update stock
2017-03-29 20:43:48 -03:00
*/
2017-04-03 16:03:22 -03:00
function update_stock($line, update_count) {
2017-03-30 13:31:16 -03:00
$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('');
2017-03-30 18:39:13 -03:00
2017-04-03 16:03:22 -03:00
if ($line.find('.stock_new input').val() && update_count) {
2017-03-30 18:39:13 -03:00
var old_misc = +$line.find('.misc input').val();
$line.find('.misc input').val(old_misc + stock_diff)
.trigger('input');
}
2017-03-30 13:31:16 -03:00
var id = $line.find('input[type="hidden"]').val();
2017-04-03 11:20:56 -03:00
conflicts.delete(parseInt(id));
2017-03-30 13:31:16 -03:00
}
2017-03-29 20:43:48 -03:00
$('.finished input').change(function() {
2017-03-30 13:31:16 -03:00
var $line = $(this).closest('tr');
2017-04-03 16:03:22 -03:00
update_stock($line, false);
2017-03-30 13:31:16 -03:00
});
$('.inventory_update button').click(function() {
var $line = $(this).closest('tr');
2017-04-03 16:03:22 -03:00
update_stock($line, true);
2017-03-28 23:47:41 -03:00
});
2017-03-30 13:30:55 -03:00
/**
* Websocket
*/
2017-04-03 16:05:18 -03:00
OperationWebSocket.add_handler(function(data) {
for (let article of data['articles']) {
2017-03-29 20:43:48 -03:00
var $line = $('input[value="'+article.id+'"]').parent();
2017-03-30 13:31:16 -03:00
if ($line.find('.finished input').is(":checked")) {
2017-03-31 10:06:02 -03:00
conflicts.add(article.id);
2017-03-30 13:31:16 -03:00
//Display warning
2017-03-29 20:43:48 -03:00
$line.addClass('inventory_modified');
2017-03-30 13:31:16 -03:00
//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);
2017-03-29 20:43:48 -03:00
}
}
2017-04-03 16:05:18 -03:00
});
2017-04-03 11:21:05 -03:00
$('input[type="submit"]').on("click", function(e) {
e.preventDefault();
2017-03-31 10:06:02 -03:00
if (conflicts.size) {
content = '';
content += "Conflits possibles :"
content += '<ul>';
2017-03-29 20:43:48 -03:00
for (let id of conflicts) {
2017-03-30 13:31:16 -03:00
var $line = $('input[value="'+id+'"]').closest('tr');
var name = $line.find('.name').text();
var stock_diff = $line.find('.stock_diff').text();
content += '<li>'+name+' ('+stock_diff+')</li>';
}
content += '</ul>'
} else {
2017-03-29 20:43:48 -03:00
// Prevent erroneous enter key confirmations
// Kinda complicated to filter if click or enter key...
content="Voulez-vous confirmer l'inventaire ?";
}
2017-03-29 20:43:48 -03:00
$.confirm({
title: "Confirmer l'inventaire",
content: content,
backgroundDismiss: true,
animation: 'top',
closeAnimation: 'bottom',
keyboardEnabled: true,
confirm: function() {
$('#inventoryform').submit();
},
onOpen: function() {
var that = this;
this.$content.find('input').on('keydown', function(e) {
if (e.keyCode == 13)
that.$confirmButton.click();
});
},
});
});
2017-03-28 23:47:41 -03:00
});
</script>
{% endblock %}