added member discount

This commit is contained in:
Aung Myo
2017-07-11 11:06:13 +06:30
parent f1f1253bde
commit 72aa769490
5 changed files with 99 additions and 10 deletions

View File

@@ -125,6 +125,71 @@ class Origami::DiscountsController < BaseOrigamiController
sale_id = params[:sale_id]
account_types = JSON.parse(params[:account_types])
sub_total = params[:sub_total]
sale = Sale.find(sale_id)
price = SaleItem.calculate_price_by_accounts(sale.sale_items)
arr = Array.new;
account_types.each do |at|
price.each do |pc|
if pc[:name].to_s == at["name"].to_s && pc[:price]>0
str={type:pc[:name],amount:pc[:price]}
arr.push(str)
end
end
end
generic_customer_id = sale.customer.membership_id
receipt_no = sale.receipt_no
membership = MembershipSetting.find_by_membership_type("paypar_url")
memberaction = MembershipAction.find_by_membership_type("member_discount")
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 ,
campaign_type_id: campaign_type_id,
receipt_no: receipt_no,
merchant_uid:merchant_uid,
discount_method:arr.to_json,
total_sale_transaction_amount: sale.grand_total,
auth_token:auth_token}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
}, :timeout => 10)
rescue HTTParty::Error
response = {status: false, message: "Can't open membership server "}
rescue Net::OpenTimeout
response = { status: false , message: "Can't open membership server "}
rescue OpenURI::HTTPError
response = { status: false, message: "Can't open membership server "}
rescue SocketError
response = { status: false, message: "Can't open membership server "}
end
puts response.to_json
table_id = sale.bookings[0].dining_facility_id
table_type = DiningFacility.find(table_id).type
# Re-calc All Amount in Sale
if response["status"] == true
sale.compute_by_sale_items(sale_id, sale.sale_items, response["rebate_earned"].to_f,"member_discount")
end
result = {:status=> "Success", :table_id => table_id, :table_type => table_type,:table_type => table_type,:url_status => response[:status],:url_message => response[:message] }
render :json => result.to_json
end
#discount for selected order