sale edit prevent multiple action

This commit is contained in:
Thein Lin Kyaw
2020-08-04 10:43:27 +06:30
parent 05ffd6cbb5
commit ffb8e56031

View File

@@ -88,7 +88,7 @@
</td> -->
<td class="p-1" width="25%">
<button data-id="<%= sale_item.id %>" class='btn btn-lg bg-danger waves-effect cancel'>Cancel
Void/Update
<%= sale_item.status %>
</button>
</td>
<% else %>
@@ -147,15 +147,15 @@
<div class="col-md-4 cashier_number border-top border- border-left green" data-type="nett">Nett</div>
<div class="col-md-4 cashier_number border-top border- border-left red" data-type="del">Del</div>
<div class="col-md-4 cashier_number border-top border- border-left orange" data-type="clr">Clr</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div> -->
<!-- Column Three -->
<div class="col-lg-1 col-md-1 col-sm-1">
<!-- Waiter Buttons -->
<button type="button" class="btn btn-block btn-lg bg-default waves-effect" id='back'><i class="material-icons">reply</i>Back</button>
<button type="button" class="btn btn-danger btn- action-btn" id='cancel_all_void'>Cancel All Void</button>
<button type="button" class="btn btn-block btn-lg btn-danger action-btn waves-effect" id='cancel_all_void'>Cancel All</button>
<button type="button" class="btn btn-block btn-lg bg-blue waves-effect" id='apply'>Apply</button>
</div>
</div>
@@ -180,231 +180,205 @@
<button type="button" class="btn btn-link p-t-5 p-b-5 bg-blue waves-effect" data-dismiss="modal">CLOSE</button>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
var cashier_type = "<%= @cashier_type %>";
var cashier_type = "<%= @cashier_type %>";
var access_code = localStorage.getItem("access_code");
// Bill Request
$(document).ready(function () {
// Bill Request
$(document).ready(function () {
setHeaderBreadCrumb(_SALE_EDIT_);
$('.editModal').on('click', function () {
$("#action").attr('data-type', $(this).attr('data-type'));
$("#action").attr('data-id', $(this).attr('data-id'));
$("#action").text($(this).attr('data-type'))
})
$(".update").on('click', function () {
var sale_item_id = $(this).attr('data-id');
var qty = $('#' + sale_item_id + "_qty").val();
var price = $('#' + sale_item_id + "_price").val();
var qty_status = true;
var price_status = true;
if((qty > 0) && (price > 0)){
qty_status = true;
price_status = true;
$('#' + sale_item_id + "_qtyErr").html("");
$('#' + sale_item_id + "_priceErr").html("");
}else if((qty > 0) && (price <= 0 || price == '')){
price_status = false;
$('#' + sale_item_id + "_qtyErr").html("");
if(price == ''){
$('#' + sale_item_id + "_priceErr").html("can't be blank");
}else{
$('#' + sale_item_id + "_price").val("");
$('#' + sale_item_id + "_priceErr").html("Price must be greater than 0");
}
}else if((qty <= 0 || qty == '') && (price > 0)){
qty_status = false;
if(qty == ''){
$('#' + sale_item_id + "_qtyErr").html("can't be blank");
}else{
$('#' + sale_item_id + "_qty").val("");
$('#' + sale_item_id + "_qtyErr").html("Quantity must be greater than 0");
}
$('#' + sale_item_id + "_priceErr").html("");
}else{
qty_status = false;
price_status = false;
$('#' + sale_item_id + "_qtyErr").html("can't be blank");
$('#' + sale_item_id + "_priceErr").html("can't be blank");
}
if(qty_status && price_status){
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+ "&access_code=" + access_code + "&type=" + cashier_type,
success: function (result) {
swal({
title: "Information!",
text: "Qty and Price was successfully Updated",
}, function () {
location.reload();
});
}
});
}
});
/*$('.void').on('click', function () {
var sale_item_id = $(this).attr('data-id');
var remark = $("#remark").val();
var ajax_url = "/origami/item_void";
$.ajax({
type: "POST",
url: ajax_url,
data: 'sale_item_id=' + sale_item_id + "&remark=" + remark,
success: function (result) {
location.reload();
}
});
})
$('.foc').on('click', function () {
var sale_item_id = $(this).attr('data-id');
var ajax_url = "/origami/item_foc";
$.ajax({
type: "POST",
url: ajax_url,
data: 'sale_item_id=' + sale_item_id + "&remark=" + remark,
success: function (result) {
location.reload();
}
});
})*/
$('#action').on('click', function () {
var access_code = localStorage.getItem("access_code");
var sale_item_id = $(this).attr('data-id');
var type = $(this).attr('data-type');
var remark = $("#remark").val();
if (type=='foc') {
var ajax_url = "/origami/item_foc";
}else{
var ajax_url = "/origami/item_void";
}
$.ajax({
type: "POST",
url: ajax_url,
data: 'sale_item_id=' + sale_item_id + "&remark=" + remark+ "&access_code=" + access_code + "&type=" + cashier_type,
success: function (result) {
location.reload();
}
});
})
$('.cancel').on('click', function () {
var sale_item_id = $(this).attr('data-id');
var ajax_url = "/origami/item_void_cancel";
$.ajax({
type: "POST",
url: ajax_url,
data: 'sale_item_id=' + sale_item_id + '&access_code=' + access_code + "&type=" + cashier_type,
success: function (result) {
location.reload();
}
});
})
})
$('#back').on('click', function () {
var table_id = '<%= @table_id %>'
var sale_id = "<%= @saleobj.sale_id %>"
if (cashier_type=="quick_service" || cashier_type == "food_court") {
window.location.href = '/origami/sale/'+sale_id+'/'+cashier_type+'/payment/';
}else{
window.location.href = '/origami/table/' + table_id;
}
})
$('#cancel_all_void').on('click', function () {
var sale_id = "<%= @saleobj.sale_id %>"
var ajax_url = "/origami/cancel_all_void";
$.ajax({
type: "POST",
url: ajax_url,
data: 'sale_id=' + sale_id +'&type='+cashier_type,
success: function (result) {
location.reload();
}
});
})
$('#apply').on('click', function () {
var sale_id = "<%= @saleobj.sale_id %>"
var ajax_url = "/origami/apply_void";
var table_id = '<%= @table_id %>'
$.ajax({
type: "POST",
url: ajax_url,
data: 'sale_id=' + sale_id+'&type='+cashier_type,
success: function (result) {
if (cashier_type=="quick_service" || cashier_type=="food_court") {
window.location.href = '/origami/sale/'+sale_id+'/'+cashier_type+'/payment/';
}else{
window.location.href = '/origami/table/' + table_id;
}
}
});
})
$( "input" ).focusin(function() {
$('.addfocus').removeClass('addfocus');
$( this ).addClass('addfocus');
setHeaderBreadCrumb(_SALE_EDIT_);
$('.editModal').on('click', function () {
$("#action").attr('data-type', $(this).attr('data-type'));
$("#action").attr('data-id', $(this).attr('data-id'));
$("#action").text($(this).attr('data-type'))
});
$(".cashier_number").on('click', function(event){
if(event.handled !== true) {
var original_value='';
original_value = $('.addfocus').val();
var input_type = $(this).attr("data-type");
switch (input_type) {
case 'num':
var input_value = $(this).attr("data-value");
if (original_value == "0.0"){
$('.addfocus').val(input_value);
}
else{
$('.addfocus').val(original_value + '' + input_value);
}
break;
case 'add':
var input_value = $(this).attr("data-value");
amount = parseInt(input_value);
$('.addfocus').val(amount);
break;
case 'del' :
var discount_text=$('.addfocus').val();
$('.addfocus').val(discount_text.substr(0,discount_text.length-1));
break;
case 'clr':
$('.addfocus').val("");
break;
$(".update").on('click', function () {
var sale_item_id = $(this).attr('data-id');
var qty = $('#' + sale_item_id + "_qty").val();
var price = $('#' + sale_item_id + "_price").val();
var qty_status = true;
var price_status = true;
if((qty > 0) && (price > 0)){
qty_status = true;
price_status = true;
$('#' + sale_item_id + "_qtyErr").html("");
$('#' + sale_item_id + "_priceErr").html("");
}else if((qty > 0) && (price <= 0 || price == '')){
price_status = false;
$('#' + sale_item_id + "_qtyErr").html("");
if(price == ''){
$('#' + sale_item_id + "_priceErr").html("can't be blank");
}else{
$('#' + sale_item_id + "_price").val("");
$('#' + sale_item_id + "_priceErr").html("Price must be greater than 0");
}
event.handled = true;
} else {
return false;
}else if((qty <= 0 || qty == '') && (price > 0)){
qty_status = false;
if(qty == ''){
$('#' + sale_item_id + "_qtyErr").html("can't be blank");
}else{
$('#' + sale_item_id + "_qty").val("");
$('#' + sale_item_id + "_qtyErr").html("Quantity must be greater than 0");
}
$('#' + sale_item_id + "_priceErr").html("");
}else{
qty_status = false;
price_status = false;
$('#' + sale_item_id + "_qtyErr").html("can't be blank");
$('#' + sale_item_id + "_priceErr").html("can't be blank");
}
if(qty_status && price_status){
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+ "&access_code=" + access_code + "&type=" + cashier_type,
success: function (result) {
swal({
title: "Information!",
text: "Qty and Price was successfully Updated",
}, function () {
location.reload();
});
}
});
}
});
$('#action').on('click', function () {
$(this).attr("disabled", true);
var access_code = localStorage.getItem("access_code");
var sale_item_id = $(this).attr('data-id');
var type = $(this).attr('data-type');
var remark = $("#remark").val();
if (type=='foc') {
var ajax_url = "/origami/item_foc";
}else{
var ajax_url = "/origami/item_void";
}
$.ajax({
type: "POST",
url: ajax_url,
data: 'sale_item_id=' + sale_item_id + "&remark=" + remark+ "&access_code=" + access_code + "&type=" + cashier_type,
success: function (result) {
location.reload();
}
});
})
$('.cancel').on('click', function () {
var sale_item_id = $(this).attr('data-id');
var ajax_url = "/origami/item_void_cancel";
$.ajax({
type: "POST",
url: ajax_url,
data: 'sale_item_id=' + sale_item_id + '&access_code=' + access_code + "&type=" + cashier_type,
success: function (result) {
location.reload();
}
});
})
})
$('#back').on('click', function () {
var table_id = '<%= @table_id %>'
var sale_id = "<%= @saleobj.sale_id %>"
if (cashier_type=="quick_service" || cashier_type == "food_court") {
window.location.href = '/origami/sale/'+sale_id+'/'+cashier_type+'/payment/';
}else{
window.location.href = '/origami/table/' + table_id;
}
})
$('#cancel_all_void').on('click', function () {
$(this).attr('disabled', true);
var sale_id = "<%= @saleobj.sale_id %>"
var ajax_url = "/origami/cancel_all_void";
$.ajax({
type: "POST",
url: ajax_url,
data: 'sale_id=' + sale_id +'&type='+cashier_type,
success: function (result) {
location.reload();
}
});
})
$('#apply').on('click', function () {
$(this).attr('disabled', true)
var sale_id = "<%= @saleobj.sale_id %>"
var ajax_url = "/origami/apply_void";
var table_id = '<%= @table_id %>'
$.ajax({
type: "POST",
url: ajax_url,
data: 'sale_id=' + sale_id+'&type='+cashier_type,
success: function (result) {
if (cashier_type=="quick_service" || cashier_type=="food_court") {
window.location.href = '/origami/sale/'+sale_id+'/'+cashier_type+'/payment/';
}else{
window.location.href = '/origami/table/' + table_id;
}
}
});
})
$( "input" ).focusin(function() {
$('.addfocus').removeClass('addfocus');
$( this ).addClass('addfocus');
});
$(".cashier_number").on('click', function(event){
if(event.handled !== true) {
var original_value='';
original_value = $('.addfocus').val();
var input_type = $(this).attr("data-type");
switch (input_type) {
case 'num':
var input_value = $(this).attr("data-value");
if (original_value == "0.0"){
$('.addfocus').val(input_value);
}
else{
$('.addfocus').val(original_value + '' + input_value);
}
break;
case 'add':
var input_value = $(this).attr("data-value");
amount = parseInt(input_value);
$('.addfocus').val(amount);
break;
case 'del' :
var discount_text=$('.addfocus').val();
$('.addfocus').val(discount_text.substr(0,discount_text.length-1));
break;
case 'clr':
$('.addfocus').val("");
break;
}
event.handled = true;
} else {
return false;
}
});
//check for isNumber
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode;
@@ -412,16 +386,16 @@ var access_code = localStorage.getItem("access_code");
return false;
} else {
return true;
}
}
}
function checkQuantity(obj_value,sale_item_id) {
if(obj_value == '0'){
$("#"+sale_item_id+"_qty").val('1');
}
if(obj_value == '0'){
$("#"+sale_item_id+"_qty").val('1');
}
}
function checkPrice(obj_value,sale_item_id) {
}
</script>