Add initial support for mispicks / attaching credits for receiving batch

This commit is contained in:
Lance Edgar 2016-12-10 09:08:37 -06:00
parent b3010465b6
commit 839d3957dd
2 changed files with 259 additions and 49 deletions

View file

@ -8,11 +8,26 @@
${h.javascript_link(request.static_url('tailbone:static/js/numeric.js'))}
<script type="text/javascript">
function assert_quantity() {
if ($('#cases').val() && parseFloat($('#cases').val())) {
return true;
}
if ($('#units').val() && parseFloat($('#units').val())) {
return true;
}
alert("Please provide case and/or unit quantity");
$('#cases').select().focus();
return false;
}
function invalid_product(msg) {
$('#product-info p').text(msg);
$('#product-info img').hide();
$('#product-info .rogue-item-warning').hide();
$('#received-product-info p').text(msg);
$('#received-product-info img').hide();
$('#received-product-info .rogue-item-warning').hide();
$('#product-textbox').focus().select();
$('.field-wrapper.cases input').prop('disabled', true);
$('.field-wrapper.units input').prop('disabled', true);
$('.buttons button').button('disable');
}
$(function() {
@ -24,9 +39,12 @@
}
if (key_modifies(event)) {
$('#product').val('');
$('#product-info p').html('&nbsp;');
$('#product-info img').hide();
$('#product-info .rogue-item-warning').hide();
$('#received-product-info p').html("please ENTER a scancode");
$('#received-product-info img').hide();
$('#received-product-info .rogue-item-warning').hide();
$('.field-wrapper.cases input').prop('disabled', true);
$('.field-wrapper.units input').prop('disabled', true);
$('.buttons button').button('disable');
return true;
}
if (event.which == 13) {
@ -41,18 +59,17 @@
}
} else if (data.product) {
input.val(data.product.upc_pretty);
if (data.product.cost_found) {
$('#product').val(data.product.uuid);
$('#product-info p').text(data.product.full_description);
$('#product-info img').attr('src', data.product.image_url).show();
$('#product-info .rogue-item-warning').hide();
$('#cases').focus().select();
if (! data.product.found_in_batch) {
$('#product-info .rogue-item-warning').show();
}
} else {
invalid_product('cost not found for ' + data.product.full_description);
$('#product').val(data.product.uuid);
$('#received-product-info p').text(data.product.full_description);
$('#received-product-info img').attr('src', data.product.image_url).show();
$('#received-product-info .rogue-item-warning').hide();
if (! data.product.found_in_batch) {
$('#received-product-info .rogue-item-warning').show();
}
$('.field-wrapper.cases input').prop('disabled', false);
$('.field-wrapper.units input').prop('disabled', false);
$('.buttons button').button('enable');
$('#cases').focus().select();
} else {
invalid_product('product not found');
}
@ -61,49 +78,174 @@
return false;
});
$('#product-textbox').focus();
$('#received').click(function() {
if (! assert_quantity()) {
return;
}
$(this).button('disable').button('option', 'label', "Working...");
$('#mode').val('received');
$('#receiving-form').submit();
});
$('#damaged').click(function() {
if (! assert_quantity()) {
return;
}
$(this).button('disable').button('option', 'label', "Working...");
$('#mode').val('damaged');
$('#receiving-form').submit();
});
$('#expiration input[type="date"]').datepicker();
$('#expired').click(function() {
if (! assert_quantity()) {
return;
}
$(this).button('disable').button('option', 'label', "Working...");
$('#mode').val('expired');
$('#receiving-form').submit();
$('#expiration').dialog({
title: "Expiration Date",
modal: true,
buttons: [
{
text: "OK",
click: function() {
$('#expiration').dialog('close');
$('#receiving-form #expiration_date').val(
$('#expiration input[type="date"]').val());
$('#receiving-form').submit();
}
},
{
text: "Cancel",
click: function() {
$('#expired').button('option', 'label', "Expired").button('enable');
$('#expiration').dialog('close');
}
}
]
});
});
$('#mispick').click(function() {
if (! assert_quantity()) {
return;
}
$(this).button('disable').button('option', 'label', "Working...");
$('#ordered-product').val('');
$('#ordered-product-textbox').val('');
$('#ordered-product-info p').html("please ENTER a scancode");
$('#ordered-product-info img').hide();
$('#mispick-dialog').dialog({
title: "Mispick - Ordered Product",
modal: true,
width: 400,
buttons: [
{
text: "OK",
click: function() {
if ($('#ordered-product-info .warning').is(':visible')) {
alert("You must choose a product which was ordered.");
$('#ordered-product-textbox').select().focus();
return;
}
$('#mispick-dialog').dialog('close');
$('#mode').val('mispick');
$('#receiving-form').submit();
}
},
{
text: "Cancel",
click: function() {
$('#mispick').button('option', 'label', "Mispick").button('enable');
$('#mispick-dialog').dialog('close');
}
}
]
});
});
$('#ordered-product-textbox').keydown(function(event) {
if (key_allowed(event)) {
return true;
}
if (key_modifies(event)) {
$('#ordered_product').val('');
$('#ordered-product-info p').html("please ENTER a scancode");
$('#ordered-product-info img').hide();
$('#ordered-product-info .warning').hide();
return true;
}
if (event.which == 13) {
var input = $(this);
var data = {upc: input.val()};
$.get('${url('purchases.batch.receiving_lookup', uuid=batch.uuid)}', data, function(data) {
if (data.error) {
alert(data.error);
if (data.redirect) {
$('#mispick-dialog').mask("Redirecting...");
location.href = data.redirect;
}
} else if (data.product) {
input.val(data.product.upc_pretty);
$('#ordered_product').val(data.product.uuid);
$('#ordered-product-info p').text(data.product.full_description);
$('#ordered-product-info img').attr('src', data.product.image_url).show();
if (data.product.found_in_batch) {
$('#ordered-product-info .warning').hide();
} else {
$('#ordered-product-info .warning').show();
}
} else {
$('#ordered-product-info p').text("product not found");
$('#ordered-product-info img').hide();
$('#ordered-product-info .warning').hide();
}
});
}
return false;
});
$('#receiving-form').submit(function() {
$(this).mask("Working...");
});
$('#product-textbox').focus();
$('.field-wrapper.cases input').prop('disabled', true);
$('.field-wrapper.units input').prop('disabled', true);
$('.buttons button').button('disable');
});
</script>
<style type="text/css">
#product-info {
.product-info {
margin-top: 0.5em;
text-align: center;
}
#product-info p {
.product-info p {
margin-left: 0.5em;
}
#product-info .img-wrapper {
.product-info .img-wrapper {
height: 150px;
margin: 0.5em 0;
}
#product-info .rogue-item-warning {
.product-info .rogue-item-warning {
background: #f66;
display: none;
}
#mispick-dialog input[type="text"],
#ordered-product-info {
width: 320px;
}
#ordered-product-info .warning {
background: #f66;
display: none;
}
@ -124,36 +266,51 @@
<div class="form-wrapper">
${form.begin(id='receiving-form')}
${h.hidden('mode')}
${h.hidden('expiration_date')}
${h.hidden('ordered_product')}
<div class="field-wrapper">
<label for="product-textbox">Product</label>
<div class="field">
${h.hidden('product')}
<div>${h.text('product-textbox', autocomplete='off')}</div>
<div id="product-info">
<p>&nbsp;</p>
<div id="received-product-info" class="product-info">
<p>please ENTER a scancode</p>
<div class="img-wrapper"><img /></div>
<div class="rogue-item-warning">warning: product not found on current purchase</div>
</div>
</div>
</div>
<div class="field-wrapper">
<div class="field-wrapper cases">
<label for="cases">Cases</label>
<div class="field">${h.text('cases')}</div>
<div class="field">${h.text('cases', autocomplete='off')}</div>
</div>
<div class="field-wrapper">
<div class="field-wrapper units">
<label for="units">Units</label>
<div class="field">${h.text('units')}</div>
<div class="field">${h.text('units', autocomplete='off')}</div>
</div>
<div class="buttons">
<button type="button" id="received">Received</button>
<button type="button" id="damaged">Damaged</button>
<button type="button" id="expired">Expired</button>
<button type="button" id="mispick" disabled="disabled">Mispick</button>
<button type="button" id="mispick">Mispick</button>
</div>
${form.end()}
</div>
<div id="expiration" style="display: none;">
${h.text('expiration-date', type='date')}
</div>
<div id="mispick-dialog" style="display: none;">
<div>${h.text('ordered-product-textbox', autocomplete='off')}</div>
<div id="ordered-product-info" class="product-info">
<p>please ENTER a scancode</p>
<div class="img-wrapper"><img /></div>
<div class="warning">warning: product not found on current purchase</div>
</div>
</div>