update member discount
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -17,6 +17,9 @@ class Origami::JcbController < BaseOrigamiController
|
||||
end
|
||||
@can_jcb = total - @jcbcount - others
|
||||
|
||||
@member_discount = MembershipSetting.find_by_discount(1)
|
||||
@sub_total = sale_data.total_amount
|
||||
@membership_id = sale_data.customer.membership_id
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
@@ -16,6 +16,9 @@ class Origami::MasterController < BaseOrigamiController
|
||||
end
|
||||
end
|
||||
@can_master = total - @mastercount - others
|
||||
@member_discount = MembershipSetting.find_by_discount(1)
|
||||
@sub_total = sale_data.total_amount
|
||||
@membership_id = sale_data.customer.membership_id
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
@@ -5,9 +5,10 @@ class Origami::MpuController < BaseOrigamiController
|
||||
|
||||
# limit mpu_amount
|
||||
sale_data = Sale.find_by_sale_id(@sale_id)
|
||||
total = sale_data.grand_total
|
||||
total = sale_data.grand_total
|
||||
@mpucount = 0
|
||||
others = 0
|
||||
others = 0
|
||||
|
||||
sale_data.sale_payments.each do |sale_payment|
|
||||
if sale_payment.payment_method == "mpu"
|
||||
@mpucount = @mpucount + sale_payment.payment_amount
|
||||
@@ -17,6 +18,9 @@ class Origami::MpuController < BaseOrigamiController
|
||||
end
|
||||
@can_mpu = total - @mpucount - others
|
||||
|
||||
@member_discount = MembershipSetting.find_by_discount(1)
|
||||
@sub_total = sale_data.total_amount
|
||||
@membership_id = sale_data.customer.membership_id
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
@@ -75,6 +75,8 @@ class Origami::PaymentsController < BaseOrigamiController
|
||||
|
||||
def show
|
||||
sale_id = params[:sale_id]
|
||||
|
||||
@member_discount = MembershipSetting.find_by_discount(1)
|
||||
|
||||
if Sale.exists?(sale_id)
|
||||
@cash = 0.0
|
||||
|
||||
@@ -16,6 +16,9 @@ class Origami::VisaController < BaseOrigamiController
|
||||
end
|
||||
end
|
||||
@can_visa = total - @visacount - others
|
||||
@member_discount = MembershipSetting.find_by_discount(1)
|
||||
@sub_total = sale_data.total_amount
|
||||
@membership_id = sale_data.customer.membership_id
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
Reference in New Issue
Block a user