Merge branch 'master' of bitbucket.org:code2lab/sxrestaurant into adminbsb_material_ui

This commit is contained in:
Aung Myo
2017-12-12 18:06:52 +06:30
10 changed files with 351 additions and 229 deletions

View File

@@ -323,7 +323,7 @@ class SalePayment < ApplicationRecord
self.sale.sale_status = "completed"
if MembershipSetting.find_by_rebate(1) && is_foc == 0
if MembershipSetting.find_by_rebate(1) && is_foc == 0 && is_credit == 0
response = rebat(sObj)
#record an payment in sale-audit
@@ -369,6 +369,7 @@ class SalePayment < ApplicationRecord
def table_update_status(sale_obj)
status = true
booking = Booking.find_by_sale_id(sale_obj.id)
if booking
table = DiningFacility.find(booking.dining_facility_id)
bookings = table.bookings
@@ -377,12 +378,15 @@ class SalePayment < ApplicationRecord
if tablebooking.sale_id
if tablebooking.sale.sale_status != 'completed' && tablebooking.sale.sale_status != 'void'
status = false
else
status = true
end
else
status = false
end
end
end
if status
table.status = "available"
table.save
@@ -410,6 +414,7 @@ class SalePayment < ApplicationRecord
# overall_dis = SaleItem.get_overall_discount(sObj.id)
overall_dis = sObj.total_discount
if credit != 1
membership = MembershipSetting.find_by_membership_type("paypar_url")
memberaction = MembershipAction.find_by_membership_type("get_member_campaign")
merchant_uid = memberaction.merchant_account_id.to_s
@@ -438,87 +443,89 @@ class SalePayment < ApplicationRecord
rescue SocketError
response = { "status": false, "message": "Can't connect server"}
end
redeem_amount = payparcost + overall_dis
total_percentage = 0
redeem_amount = payparcost + overall_dis
type_arr = []
Rails.logger.debug "Get Member Campaign"
Rails.logger.debug response.to_json
# Check for present response fields
if response["membership_campaign_data"].present?
response["membership_campaign_data"].each do |a|
data = {:type => a["rules_type"], :percentage => a["change_unit"].to_i * a["base_unit"].to_i}
total_percentage = total_percentage + a["change_unit"].to_i * a["base_unit"].to_i
type_arr.push(data)
end
end
total_percentage = 0
rebate_arr =[]
campaign_method.each do |a|
data = {:type => a[:type], :amount => a[:amount]}
type_arr.each do |si|
if si[:type] == a[:type]
if credit == 1
data[:amount] = 0
else
amount = (redeem_amount / total_percentage)*si[:percentage]
actual = a[:amount] - amount
data[:amount] = actual
end
type_arr = []
Rails.logger.debug "Get Member Campaign"
Rails.logger.debug response.to_json
# Check for present response fields
if response["membership_campaign_data"].present?
response["membership_campaign_data"].each do |a|
data = {:type => a["rules_type"], :percentage => a["change_unit"].to_i * a["base_unit"].to_i}
total_percentage = total_percentage + a["change_unit"].to_i * a["base_unit"].to_i
type_arr.push(data)
end
end
rebate_arr.push(data)
end
total_amount = rebate_prices - payparcost - overall_dis
if credit == 1
total_amount = 0
end
if total_amount >= 0
receipt_no = sObj.receipt_no
membership = MembershipSetting.find_by_membership_type("paypar_url")
memberaction = MembershipAction.find_by_membership_type("rebate")
merchant_uid = memberaction.merchant_account_id.to_s
campaign_type_id = memberaction.additional_parameter["campaign_type_id"]
auth_token = memberaction.auth_token.to_s
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
# Control for Paypar Cloud
begin
response = HTTParty.post(url,
:body => {
generic_customer_id:generic_customer_id ,
total_sale_transaction_amount: sObj.grand_total,
merchant_uid:merchant_uid,
total_amount: total_amount,
campaign_type_id: campaign_type_id,
receipt_no: receipt_no,
campaign_method: rebate_arr.to_json,
auth_token:auth_token
}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json; version=2'
}, :timeout => 10)
rescue Net::OpenTimeout
response = { "status": false , "message": "Connect To" }
rescue OpenURI::HTTPError
response = { "status": false, "message": "Can't connect server"}
rescue SocketError
response = { "status": false, "message": "Can't connect server"}
rebate_arr =[]
campaign_method.each do |a|
data = {:type => a[:type], :amount => a[:amount]}
type_arr.each do |si|
if si[:type] == a[:type]
if credit == 1
data[:amount] = 0
else
amount = (redeem_amount / total_percentage)*si[:percentage]
actual = a[:amount] - amount
data[:amount] = actual
end
end
end
rebate_arr.push(data)
end
total_amount = rebate_prices - payparcost - overall_dis
if credit == 1
total_amount = 0
end
if total_amount >= 0
receipt_no = sObj.receipt_no
membership = MembershipSetting.find_by_membership_type("paypar_url")
memberaction = MembershipAction.find_by_membership_type("rebate")
merchant_uid = memberaction.merchant_account_id.to_s
campaign_type_id = memberaction.additional_parameter["campaign_type_id"]
auth_token = memberaction.auth_token.to_s
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
# Control for Paypar Cloud
begin
response = HTTParty.post(url,
:body => {
generic_customer_id:generic_customer_id ,
total_sale_transaction_amount: sObj.grand_total,
merchant_uid:merchant_uid,
total_amount: total_amount,
campaign_type_id: campaign_type_id,
receipt_no: receipt_no,
campaign_method: rebate_arr.to_json,
auth_token:auth_token
}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json; version=2'
}, :timeout => 10)
rescue Net::OpenTimeout
response = { "status": false , "message": "Connect To" }
rescue OpenURI::HTTPError
response = { "status": false, "message": "Can't connect server"}
rescue SocketError
response = { "status": false, "message": "Can't connect server"}
end
Rails.logger.debug "Rebage Response"
Rails.logger.debug response.to_json
return response
end
Rails.logger.debug "Rebage Response"
Rails.logger.debug response.to_json
return response
end
else
response = { "status": "no_member", "message": "Not membership"}
response = { "status": "no_member", "message": "Not membership"}
end
end