From e19bff005ea468f2c55542c223f55feb4a94d8e8 Mon Sep 17 00:00:00 2001 From: yarzar_code Date: Thu, 13 Aug 2020 14:09:05 +0630 Subject: [PATCH] show card balance when insufficient error occurred --- app/assets/javascripts/foodcourt/addorder.js | 53 +++++++------------ .../foodcourt/customers_controller.rb | 2 +- app/models/customer.rb | 6 +++ app/views/foodcourt/payments/show.html.erb | 51 ++++++++---------- 4 files changed, 50 insertions(+), 62 deletions(-) diff --git a/app/assets/javascripts/foodcourt/addorder.js b/app/assets/javascripts/foodcourt/addorder.js index 448c5fc7..c32a0452 100644 --- a/app/assets/javascripts/foodcourt/addorder.js +++ b/app/assets/javascripts/foodcourt/addorder.js @@ -30,6 +30,11 @@ function member_card(cardNo) { success: function(data) { if (data[0].customer_id == false) { 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{ g_customer_id = data[0].customer_id; g_customer_name = data[0].name; @@ -115,40 +120,22 @@ function update_sale(membership_id, customer_id, customer_name, sale_id) { if(customer_name != ""){ customer = '(' + customer_name + ')'; } - - swal({ - title: "Confirmation !", - text: 'Are you sure to assign this customer' + customer + '!', - showCancelButton: true, - confirmButtonColor: "green", - confirmButtonText: "Yes!", - cancelButtonClass: 'btn btn-danger customer_assign_cancel', - closeOnConfirm: true, - }, function (inputValue) { - if (inputValue===false) { - if ($("#order-items-table tr").length > 1){ - $("#create_pay_order").prop("disabled", false); - $("#create_order").prop("disabled", false); + $("#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/'; } - } 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/'; - } - } - }); } }); } diff --git a/app/controllers/foodcourt/customers_controller.rb b/app/controllers/foodcourt/customers_controller.rb index f28f5397..a8fb5979 100644 --- a/app/controllers/foodcourt/customers_controller.rb +++ b/app/controllers/foodcourt/customers_controller.rb @@ -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" ) end @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 diff --git a/app/models/customer.rb b/app/models/customer.rb index da8435df..dfbb8500 100755 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -375,6 +375,12 @@ class Customer < ApplicationRecord rescue SocketError response = {"status" => false, "message" => "No internet connection "} 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 response.to_json return response diff --git a/app/views/foodcourt/payments/show.html.erb b/app/views/foodcourt/payments/show.html.erb index 1aa59dd2..e87ae1de 100755 --- a/app/views/foodcourt/payments/show.html.erb +++ b/app/views/foodcourt/payments/show.html.erb @@ -738,6 +738,7 @@ $(document).ready(function(){ dataType: "json", success: function(data) { if (data.status == true) { + var customer_card_balance= data.balance; var valid_amount = parseFloat(data.old_balance_amount) - parseFloat(data.reload_amount); // $("#valid_amount").val((valid_amount > 0) ? parseFloat(valid_amount) : 0); $.ajax({ @@ -788,6 +789,7 @@ $(document).ready(function(){ allowOutsideClick: false }, function (isConfirm) { + $("#loading_wrapper").show(); $('.confirm').attr("disabled","disabled"); window.location.href = "<%= foodcourt_food_court_path %>"; }); @@ -800,9 +802,10 @@ $(document).ready(function(){ customer_display_view(null,"reload"); } } else { + var insufficient_message = result.message + '
Card balance : ' + customer_card_balance swal({ title: 'Oops', - text: result.message, + text: insufficient_message, type: 'warning', html: true, closeOnConfirm: false, @@ -827,6 +830,7 @@ $(document).ready(function(){ }, function () { window.location.href = '/foodcourt/sale/'+ sale_id +"/"+cashier_type + "/payment"; }); + $("#loading_wrapper").hide(); } } }); @@ -842,6 +846,7 @@ $(document).ready(function(){ }, function () { window.location.href = '/foodcourt/sale/'+ sale_id +"/"+cashier_type + "/payment"; }); + $("#loading_wrapper").hide(); } } @@ -939,35 +944,25 @@ $(document).ready(function(){ if(customer_name != ""){ customer = '(' + customer_name + ')'; } + $("#loading_wrapper").show(); - swal({ - title: "Confirmation !", - text: 'Are you sure to assign this customer' + customer + '!', - showCancelButton: true, - confirmButtonColor: "green", - confirmButtonText: "Yes!", - cancelButtonClass: 'btn btn-danger', - closeOnConfirm: true, - }, function () { - $("#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{ - swal("Alert!", "Record not found!", "error"); - location.reload(); - } + $.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{ + swal("Alert!", "Record not found!", "error"); + location.reload(); } - }); + } }); }