show card balance when insufficient error occurred

This commit is contained in:
yarzar_code
2020-08-13 14:09:05 +06:30
parent 975d0f3ecd
commit e19bff005e
4 changed files with 50 additions and 62 deletions

View File

@@ -30,6 +30,11 @@ function member_card(cardNo) {
success: function(data) { success: function(data) {
if (data[0].customer_id == false) { if (data[0].customer_id == false) {
swal("Alert!", data[0].message, "error"); swal("Alert!", data[0].message, "error");
if ($("#order-items-table tr").length > 1){
$("#create_pay_order").prop("disabled", false);
$("#create_order").prop("disabled", false);
}
$("#oqs_loading_wrapper").hide();
}else{ }else{
g_customer_id = data[0].customer_id; g_customer_id = data[0].customer_id;
g_customer_name = data[0].name; g_customer_name = data[0].name;
@@ -115,40 +120,22 @@ function update_sale(membership_id, customer_id, customer_name, sale_id) {
if(customer_name != ""){ if(customer_name != ""){
customer = '(' + customer_name + ')'; customer = '(' + customer_name + ')';
} }
$("#oqs_loading_wrapper").show();
swal({ $.ajax({
title: "Confirmation !", type: "POST",
text: 'Are you sure to assign this customer' + customer + '!', url: "/foodcourt/"+sale_id+"/"+cashier_type+"/customers/update_sale" ,
showCancelButton: true, data: {customer_id:customer_id,sale_id:sale_id},
confirmButtonColor: "green", dataType: "json",
confirmButtonText: "Yes!", success: function(data) {
cancelButtonClass: 'btn btn-danger customer_assign_cancel', if(data.status == true)
closeOnConfirm: true, {
}, function (inputValue) { //change customer detail
if (inputValue===false) { $("#customer_name").html(customer_name);
if ($("#order-items-table tr").length > 1){ $("#membership_id").html(membership_id);
$("#create_pay_order").prop("disabled", false); window.location.href = '/foodcourt/sale/'+sale_id+'/'+cashier_type+'/payment/';
$("#create_order").prop("disabled", false); }else{
window.location.href = '/foodcourt/sale/'+sale_id+'/'+cashier_type+'/payment/';
} }
} else {
$("#oqs_loading_wrapper").show();
$.ajax({
type: "POST",
url: "/foodcourt/"+sale_id+"/"+cashier_type+"/customers/update_sale" ,
data: {customer_id:customer_id,sale_id:sale_id},
dataType: "json",
success: function(data) {
if(data.status == true)
{
//change customer detail
$("#customer_name").html(customer_name);
$("#membership_id").html(membership_id);
window.location.href = '/foodcourt/sale/'+sale_id+'/'+cashier_type+'/payment/';
}else{
window.location.href = '/foodcourt/sale/'+sale_id+'/'+cashier_type+'/payment/';
}
}
});
} }
}); });
} }

View File

@@ -187,7 +187,7 @@ class Foodcourt::CustomersController < BaseFoodcourtController
sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,sale.cashier_id, action_by,remark,"PAYBYACCOUNT" ) sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,sale.cashier_id, action_by,remark,"PAYBYACCOUNT" )
end end
@out = membership_data @out = membership_data
render json: JSON.generate({:status => membership_data["status"], :message => membership_data["message"]}) render json: JSON.generate({:status => membership_data["status"], :message => membership_data["message"], :balance => membership_data["balance"]})
end end
end end
end end

View File

@@ -375,6 +375,12 @@ class Customer < ApplicationRecord
rescue SocketError rescue SocketError
response = {"status" => false, "message" => "No internet connection "} response = {"status" => false, "message" => "No internet connection "}
end end
case response.code
when 404
response = {"status" => false, "message" => "Not Found "}
when 500...600
response = {"status" => false, "message" => response.message}
end
Rails.logger.debug "--------Search Paypar Account No response -------" Rails.logger.debug "--------Search Paypar Account No response -------"
Rails.logger.debug response.to_json Rails.logger.debug response.to_json
return response return response

View File

@@ -738,6 +738,7 @@ $(document).ready(function(){
dataType: "json", dataType: "json",
success: function(data) { success: function(data) {
if (data.status == true) { if (data.status == true) {
var customer_card_balance= data.balance;
var valid_amount = parseFloat(data.old_balance_amount) - parseFloat(data.reload_amount); var valid_amount = parseFloat(data.old_balance_amount) - parseFloat(data.reload_amount);
// $("#valid_amount").val((valid_amount > 0) ? parseFloat(valid_amount) : 0); // $("#valid_amount").val((valid_amount > 0) ? parseFloat(valid_amount) : 0);
$.ajax({ $.ajax({
@@ -788,6 +789,7 @@ $(document).ready(function(){
allowOutsideClick: false allowOutsideClick: false
}, },
function (isConfirm) { function (isConfirm) {
$("#loading_wrapper").show();
$('.confirm').attr("disabled","disabled"); $('.confirm').attr("disabled","disabled");
window.location.href = "<%= foodcourt_food_court_path %>"; window.location.href = "<%= foodcourt_food_court_path %>";
}); });
@@ -800,9 +802,10 @@ $(document).ready(function(){
customer_display_view(null,"reload"); customer_display_view(null,"reload");
} }
} else { } else {
var insufficient_message = result.message + '<br> Card balance : ' + customer_card_balance
swal({ swal({
title: 'Oops', title: 'Oops',
text: result.message, text: insufficient_message,
type: 'warning', type: 'warning',
html: true, html: true,
closeOnConfirm: false, closeOnConfirm: false,
@@ -827,6 +830,7 @@ $(document).ready(function(){
}, function () { }, function () {
window.location.href = '/foodcourt/sale/'+ sale_id +"/"+cashier_type + "/payment"; window.location.href = '/foodcourt/sale/'+ sale_id +"/"+cashier_type + "/payment";
}); });
$("#loading_wrapper").hide();
} }
} }
}); });
@@ -842,6 +846,7 @@ $(document).ready(function(){
}, function () { }, function () {
window.location.href = '/foodcourt/sale/'+ sale_id +"/"+cashier_type + "/payment"; window.location.href = '/foodcourt/sale/'+ sale_id +"/"+cashier_type + "/payment";
}); });
$("#loading_wrapper").hide();
} }
} }
@@ -939,35 +944,25 @@ $(document).ready(function(){
if(customer_name != ""){ if(customer_name != ""){
customer = '(' + customer_name + ')'; customer = '(' + customer_name + ')';
} }
$("#loading_wrapper").show();
swal({ $.ajax({
title: "Confirmation !", type: "POST",
text: 'Are you sure to assign this customer' + customer + '!', url: "/foodcourt/"+sale_id+"/"+cashier_type+"/customers/update_sale" ,
showCancelButton: true, data: {customer_id:customer_id,sale_id:sale_id},
confirmButtonColor: "green", dataType: "json",
confirmButtonText: "Yes!", success: function(data) {
cancelButtonClass: 'btn btn-danger', if(data.status == true)
closeOnConfirm: true, {
}, function () { //change customer detail
$("#loading_wrapper").show(); $("#customer_name").html(customer_name);
$.ajax({ $("#membership_id").html(membership_id);
type: "POST", window.location.href = '/foodcourt/sale/'+sale_id+'/'+cashier_type+'/payment/';
url: "/foodcourt/"+sale_id+"/"+cashier_type+"/customers/update_sale" , }else{
data: {customer_id:customer_id,sale_id:sale_id}, swal("Alert!", "Record not found!", "error");
dataType: "json", location.reload();
success: function(data) {
if(data.status == true)
{
//change customer detail
$("#customer_name").html(customer_name);
$("#membership_id").html(membership_id);
window.location.href = '/foodcourt/sale/'+sale_id+'/'+cashier_type+'/payment/';
}else{
swal("Alert!", "Record not found!", "error");
location.reload();
}
} }
}); }
}); });
} }