Merge branch 'staging' of bitbucket.org:code2lab/sxrestaurant into osaka
This commit is contained in:
@@ -67,6 +67,9 @@ class Customer < ApplicationRecord
|
|||||||
},
|
},
|
||||||
:timeout => 10
|
:timeout => 10
|
||||||
)
|
)
|
||||||
|
rescue HTTParty::Error
|
||||||
|
response = {status: false, message: "Can't open membership server " }
|
||||||
|
|
||||||
rescue Net::OpenTimeout
|
rescue Net::OpenTimeout
|
||||||
response = { status: false , message: "Server Time out"}
|
response = { status: false , message: "Server Time out"}
|
||||||
|
|
||||||
|
|||||||
@@ -69,23 +69,29 @@ class SaleItem < ApplicationRecord
|
|||||||
# Calculate rebate_by_account
|
# Calculate rebate_by_account
|
||||||
def self.calculate_rebate_by_account(sale_items)
|
def self.calculate_rebate_by_account(sale_items)
|
||||||
rebateacc = Account.where("rebate=?",true)
|
rebateacc = Account.where("rebate=?",true)
|
||||||
puts "Account that can rebate"
|
price = 0
|
||||||
rebateacc.each do |i|
|
rebate_arr = []
|
||||||
puts i.title
|
rebateacc.each do |a|
|
||||||
end
|
account_price = {:type => a.title, :amount => 0}
|
||||||
prices=0
|
|
||||||
sale_items.each do |si|
|
|
||||||
price = self.get_rebate_price(si.sale_item_id,rebateacc)
|
|
||||||
|
|
||||||
prices = prices + price
|
# Check for actual sale items
|
||||||
|
sale_items.each do |si|
|
||||||
|
if si.account_id == a.id
|
||||||
|
account_price[:amount] = account_price[:amount] + si.price
|
||||||
|
price = price + si.price
|
||||||
end
|
end
|
||||||
return prices
|
|
||||||
|
end
|
||||||
|
rebate_arr.push(account_price)
|
||||||
|
end
|
||||||
|
|
||||||
|
return price,rebate_arr
|
||||||
end
|
end
|
||||||
|
|
||||||
# get food price or beverage price for item
|
# get food price or beverage price for item
|
||||||
def self.get_rebate_price(sale_item_id,rebateacc)
|
def self.get_rebate_price(sale_item_id,rebateacc)
|
||||||
price = 0
|
price = 0
|
||||||
|
type = ''
|
||||||
item=SaleItem.select("sale_items.price , menu_items.account_id")
|
item=SaleItem.select("sale_items.price , menu_items.account_id")
|
||||||
.joins("left join menu_items on menu_items.item_code = sale_items.product_code")
|
.joins("left join menu_items on menu_items.item_code = sale_items.product_code")
|
||||||
.where("sale_items.sale_item_id=?", sale_item_id.to_s)
|
.where("sale_items.sale_item_id=?", sale_item_id.to_s)
|
||||||
@@ -93,12 +99,14 @@ class SaleItem < ApplicationRecord
|
|||||||
rebateacc.each do |i|
|
rebateacc.each do |i|
|
||||||
if item[0].account_id == i.id
|
if item[0].account_id == i.id
|
||||||
price = item[0].price
|
price = item[0].price
|
||||||
|
type = i.title
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return price
|
return price,type
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# def self.get_overall_discount(sale_id)
|
# def self.get_overall_discount(sale_id)
|
||||||
# price = 0.0
|
# price = 0.0
|
||||||
# item=SaleItem.where("product_code=?", sale_id)
|
# item=SaleItem.where("product_code=?", sale_id)
|
||||||
|
|||||||
@@ -77,7 +77,10 @@ class SalePayment < ApplicationRecord
|
|||||||
# Control for Paypar Cloud
|
# Control for Paypar Cloud
|
||||||
begin
|
begin
|
||||||
response = HTTParty.get(url,
|
response = HTTParty.get(url,
|
||||||
:body => { app_token: token,membership_id:membership_id,campaign_type_id:campaign_type_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json,
|
:body => { app_token: token,membership_id:membership_id,
|
||||||
|
campaign_type_id:campaign_type_id,merchant_uid:merchant_uid,
|
||||||
|
auth_token:auth_token
|
||||||
|
}.to_json,
|
||||||
:headers => {
|
:headers => {
|
||||||
'Content-Type' => 'application/json',
|
'Content-Type' => 'application/json',
|
||||||
'Accept' => 'application/json'
|
'Accept' => 'application/json'
|
||||||
@@ -115,7 +118,14 @@ class SalePayment < ApplicationRecord
|
|||||||
# Control for Paypar Cloud
|
# Control for Paypar Cloud
|
||||||
begin
|
begin
|
||||||
response = HTTParty.post(url,
|
response = HTTParty.post(url,
|
||||||
:body => { generic_customer_id:membership_id,total_amount: redeem_prices,total_sale_transaction_amount: sale_data.grand_total,redeem_amount:received_amount,receipt_no:sale_data.receipt_no,campaign_type_id:campaign_type_id,account_no:"",merchant_uid:merchant_uid,auth_token:auth_token}.to_json,
|
:body => { generic_customer_id:membership_id,
|
||||||
|
total_amount: redeem_prices,
|
||||||
|
total_sale_transaction_amount: sale_data.grand_total,
|
||||||
|
redeem_amount:received_amount,
|
||||||
|
receipt_no:sale_data.receipt_no,
|
||||||
|
campaign_type_id:campaign_type_id,
|
||||||
|
account_no:"",merchant_uid:merchant_uid,
|
||||||
|
auth_token:auth_token}.to_json,
|
||||||
:headers => {
|
:headers => {
|
||||||
'Content-Type' => 'application/json',
|
'Content-Type' => 'application/json',
|
||||||
'Accept' => 'application/json'
|
'Accept' => 'application/json'
|
||||||
@@ -261,7 +271,7 @@ class SalePayment < ApplicationRecord
|
|||||||
end
|
end
|
||||||
self.sale.sale_status = "completed"
|
self.sale.sale_status = "completed"
|
||||||
|
|
||||||
if MembershipSetting.find(1).rebate
|
if MembershipSetting.find_by_rebate(1)
|
||||||
response = rebat(sObj)
|
response = rebat(sObj)
|
||||||
|
|
||||||
if !response.nil?
|
if !response.nil?
|
||||||
@@ -280,12 +290,12 @@ class SalePayment < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
puts "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"
|
puts "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"
|
||||||
|
puts response.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
self.sale.save!
|
self.sale.save!
|
||||||
table_update_status(sObj)
|
table_update_status(sObj)
|
||||||
|
|
||||||
|
|
||||||
if paid_amount != "0.0"
|
if paid_amount != "0.0"
|
||||||
update_shift
|
update_shift
|
||||||
end
|
end
|
||||||
@@ -324,13 +334,14 @@ class SalePayment < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def rebat(sObj)
|
def rebat(sObj)
|
||||||
rebate_prices = SaleItem.calculate_rebate_by_account(sObj.sale_items)
|
rebate_prices,campaign_method = SaleItem.calculate_rebate_by_account(sObj.sale_items)
|
||||||
|
|
||||||
generic_customer_id = sObj.customer.membership_id
|
generic_customer_id = sObj.customer.membership_id
|
||||||
if generic_customer_id.present?
|
if generic_customer_id.present?
|
||||||
|
|
||||||
paypar = sObj.sale_payments
|
paypar = sObj.sale_payments
|
||||||
payparcost = 0
|
payparcost = 0
|
||||||
credit = 0
|
credit = 0
|
||||||
|
|
||||||
paypar.each do |pp|
|
paypar.each do |pp|
|
||||||
if pp.payment_method == "paypar"
|
if pp.payment_method == "paypar"
|
||||||
payparcost = payparcost + pp.payment_amount
|
payparcost = payparcost + pp.payment_amount
|
||||||
@@ -341,7 +352,67 @@ class SalePayment < ApplicationRecord
|
|||||||
# overall_dis = SaleItem.get_overall_discount(sObj.id)
|
# overall_dis = SaleItem.get_overall_discount(sObj.id)
|
||||||
overall_dis = sObj.total_discount
|
overall_dis = sObj.total_discount
|
||||||
|
|
||||||
|
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
|
||||||
|
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.get(url,
|
||||||
|
:body => {
|
||||||
|
member_group_id:sObj.customer.membership_type,
|
||||||
|
merchant_uid:merchant_uid,
|
||||||
|
campaign_type_id: campaign_type_id,
|
||||||
|
auth_token:auth_token
|
||||||
|
}.to_json,
|
||||||
|
:headers => {
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
'Accept' => 'application/json'
|
||||||
|
}, :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
|
||||||
|
|
||||||
|
redeem_amount = payparcost + overall_dis
|
||||||
|
|
||||||
|
total_percentage = 0
|
||||||
|
|
||||||
|
type_arr = []
|
||||||
|
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
|
||||||
|
|
||||||
|
rebate_arr =[]
|
||||||
|
campaign_method.each do |a|
|
||||||
|
data = {:type => a[:type], :amount => a[:amount]}
|
||||||
|
puts data
|
||||||
|
type_arr.each do |si|
|
||||||
|
if si[:type] == a[:type]
|
||||||
|
puts "steeeeeeeeeeeee"
|
||||||
|
amount = (redeem_amount / total_percentage)*si[:percentage]
|
||||||
|
actual = a[:amount] - amount
|
||||||
|
data[:amount] = actual
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
rebate_arr.push(data)
|
||||||
|
|
||||||
|
end
|
||||||
|
puts "ssssssssss"
|
||||||
|
puts rebate_arr.to_json
|
||||||
total_amount = rebate_prices - payparcost - overall_dis
|
total_amount = rebate_prices - payparcost - overall_dis
|
||||||
|
|
||||||
if credit == 1
|
if credit == 1
|
||||||
total_amount = 0
|
total_amount = 0
|
||||||
end
|
end
|
||||||
@@ -356,24 +427,31 @@ class SalePayment < ApplicationRecord
|
|||||||
|
|
||||||
# Control for Paypar Cloud
|
# Control for Paypar Cloud
|
||||||
begin
|
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,
|
response = HTTParty.post(url,
|
||||||
receipt_no: receipt_no,auth_token:auth_token}.to_json,
|
: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 => {
|
:headers => {
|
||||||
'Content-Type' => 'application/json',
|
'Content-Type' => 'application/json',
|
||||||
'Accept' => 'application/json'
|
'Accept' => 'application/json'
|
||||||
}, :timeout => 10)
|
}, :timeout => 10)
|
||||||
rescue Net::OpenTimeout
|
rescue Net::OpenTimeout
|
||||||
response = { "status": false , "message": "Connect To" }
|
response = { "status": false , "message": "Connect To" }
|
||||||
|
|
||||||
|
|
||||||
rescue OpenURI::HTTPError
|
rescue OpenURI::HTTPError
|
||||||
response = { "status": false, "message": "Can't connect server"}
|
response = { "status": false, "message": "Can't connect server"}
|
||||||
|
|
||||||
rescue SocketError
|
rescue SocketError
|
||||||
response = { "status": false, "message": "Can't connect server"}
|
response = { "status": false, "message": "Can't connect server"}
|
||||||
|
|
||||||
end
|
end
|
||||||
return response
|
return response
|
||||||
|
puts "latest respppppp"
|
||||||
puts response.to_json
|
puts response.to_json
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -174,6 +174,7 @@ member_actions= MembershipAction.create([{membership_type:"get_account_balance",
|
|||||||
{membership_type:"get_all_member_account",gateway_url:"/api/generic_customer/get_membership_data",merchant_account_id:"vWSsseoZCzxd6xcNf_uS",auth_token:"code2lab"},
|
{membership_type:"get_all_member_account",gateway_url:"/api/generic_customer/get_membership_data",merchant_account_id:"vWSsseoZCzxd6xcNf_uS",auth_token:"code2lab"},
|
||||||
{membership_type:"get_member_transactions",gateway_url:"/api/generic_customer/get_membership_transactions",merchant_account_id:"vWSsseoZCzxd6xcNf_uS",auth_token:"code2lab"},
|
{membership_type:"get_member_transactions",gateway_url:"/api/generic_customer/get_membership_transactions",merchant_account_id:"vWSsseoZCzxd6xcNf_uS",auth_token:"code2lab"},
|
||||||
{membership_type:"member_discount",gateway_url:"/api/membership_campaigns/discount",additional_parameter:{campaign_type_id:6},merchant_account_id:"vWSsseoZCzxd6xcNf_uS",auth_token:"code2lab"},
|
{membership_type:"member_discount",gateway_url:"/api/membership_campaigns/discount",additional_parameter:{campaign_type_id:6},merchant_account_id:"vWSsseoZCzxd6xcNf_uS",auth_token:"code2lab"},
|
||||||
|
{membership_type:"get_member_campaign",gateway_url:"/api/membership_campaigns/get_member_campaign",additional_parameter:{campaign_type_id:6},merchant_account_id:"vWSsseoZCzxd6xcNf_uS",auth_token:"code2lab"},
|
||||||
])
|
])
|
||||||
|
|
||||||
payment_methods = PaymentMethodSetting.create({payment_method:"MPU",gateway_url: "http://192.168.1.47:3006"})
|
payment_methods = PaymentMethodSetting.create({payment_method:"MPU",gateway_url: "http://192.168.1.47:3006"})
|
||||||
|
|||||||
Reference in New Issue
Block a user