update member discount

This commit is contained in:
Aung Myo
2017-09-14 17:36:00 +06:30
parent 90681cddcc
commit e878a6387e
14 changed files with 1055 additions and 932 deletions

View File

@@ -127,88 +127,91 @@ class Origami::DiscountsController < BaseOrigamiController
# Member Discount
def member_discount
sale_id = params[:sale_id]
# account_types = JSON.parse(params[:account_types])
account_types = Account.where("discount=?",true)
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] == at.title && 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
# Check for items for Paypar Cloud
if arr.length > 0
begin
response = HTTParty.post(url,
:body => { account_no: nil,
generic_customer_id:generic_customer_id ,
campaign_type_id: campaign_type_id,
receipt_no: receipt_no,
merchant_uid:merchant_uid,
campaign_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
else
response = {:status=> false, :message => "You have no selected discount item" }
end
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
discount_amount = response["discount_earned"]
if response["discount_bonus_earned"]
discount_amount = discount_amount + response["discount_bonus_earned"]
end
sale.compute_by_sale_items(sale_id, sale.sale_items, discount_amount, 'member_discount')
result = {:status=> "Success",:title=>"Member Discount", :table_id => table_id,:table_type => table_type }
end
if response["status"] == "500"
result = {:status=> response["error"],:title=>"Alert", :table_id => table_id,:table_type => table_type }
end
if !response.nil?
if response[:status] == false
result = {:status=> response[:message],:title=>"Alert", :table_id => table_id,:table_type => table_type }
end
end
render :json => result.to_json
sale_id = params[:sale_id]
is_card = params[:is_card]
sub_total = params[:sub_total]
sale = Sale.find(sale_id)
# Check for Card Payment
is_card_payment = SaleItem.get_sale_payments_by_card(sale.sale_payments)
if is_card_payment != true
account_types = Account.where("discount=?",true)
table_id = sale.bookings[0].dining_facility_id
table_type = DiningFacility.find(table_id).type
# Get Prices for each accounts (eg: food, beverage)
account_price = SaleItem.calculate_price_by_accounts(sale.sale_items)
acc_prices = Array.new;
account_types.each do |at|
account_price.each do |pc|
if pc[:name] == at.title && pc[:price]>0
str={type:pc[:name],amount:pc[:price]}
acc_prices.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
# Check for items for Paypar Cloud
if acc_prices.length > 0
begin
response = HTTParty.post(url,
:body => { account_no: nil,
generic_customer_id:generic_customer_id ,
campaign_type_id: campaign_type_id,
receipt_no: receipt_no,
merchant_uid:merchant_uid,
campaign_method:acc_prices.to_json,
total_sale_transaction_amount: sale.grand_total,
is_card: is_card,
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
else
response = {"status": false, "message": "You have no selected discount item" }
end
# Re-calc All Amount in Sale
if response["status"] == true
discount_amount = response["discount_earned"]
if response["discount_bonus_earned"]
discount_amount = discount_amount + response["discount_bonus_earned"]
end
sale.compute_by_sale_items(sale_id, sale.sale_items, discount_amount, 'member_discount')
result = {:status=> "Success",:title=>"Member Discount", :table_id => table_id,:table_type => table_type }
elsif response["status"] == "500"
result = {:status=> response["error"],:title=>"Alert", :table_id => table_id,:table_type => table_type }
else
result = {:status=> response["message"],:title=>"Alert", :table_id => table_id,:table_type => table_type }
end
render :json => result.to_json
end #end Is Card Payment
end
#discount for selected order