check qty update in edit

This commit is contained in:
phyusin
2018-02-21 18:42:00 +06:30
parent e2903075b2
commit 950f479da6

View File

@@ -59,7 +59,8 @@
</td>
<% if sale_item.remark != 'void' && sale_item.remark != 'edit' && sale_item.remark != 'foc' %>
<td class="p-1" width="5%">
<input id="<%= sale_item.id %>_qty" data-id="<%= sale_item.id %>" type="text" value="<%= sale_item.qty %>" class="form-control "/>
<input id="<%= sale_item.id %>_qty" data-id="<%= sale_item.id %>" type="text" value="<%= sale_item.qty %>" class="form-control " onkeyup="checkQuantity(this.value,'<%= sale_item.id %>');" onkeypress="return isNumberKey(event);" />
<span id="<%= sale_item.id %>_qtyErr" style="color:red;"></span>
</td>
<td class="p-1" width="10%">
<input id="<%= sale_item.id %>_price" data-id="<%= sale_item.id %>" type="text" value="<%= sale_item.unit_price %>" class="form-control"/>
@@ -166,21 +167,27 @@ var cashier_type = "<%= @cashier_type %>";
var sale_item_id = $(this).attr('data-id');
var qty = $('#' + sale_item_id + "_qty").val();
var price = $('#' + sale_item_id + "_price").val();
console.log(qty + "|" + price)
var ajax_url = "/origami/item_edit";
$.ajax({
type: "POST",
url: ajax_url,
data: 'sale_item_id=' + sale_item_id + "&update_qty=" + qty + "&update_price=" + price,
success: function (result) {
swal({
title: "Information!",
text: "Qty and Price was successfully Updated",
}, function () {
location.reload();
});
}
});
console.log(qty + "|" + price);
if(qty > 0){
$('#' + sale_item_id + "_qtyErr").html("");
var ajax_url = "/origami/item_edit";
$.ajax({
type: "POST",
url: ajax_url,
data: 'sale_item_id=' + sale_item_id + "&update_qty=" + qty + "&update_price=" + price,
success: function (result) {
swal({
title: "Information!",
text: "Qty and Price was successfully Updated",
}, function () {
location.reload();
});
}
});
}else{
$('#' + sale_item_id + "_qtyErr").html("can't be blank");
}
});
$('.void').on('click', function () {
@@ -311,4 +318,20 @@ var cashier_type = "<%= @cashier_type %>";
return false;
}
});
//check for isNumber
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
} else {
return true;
}
}
function checkQuantity(obj_value,sale_item_id) {
if(obj_value == '0'){
$("#"+sale_item_id+"_qty").val('1');
}
}
</script>