update precision and delimetor all
This commit is contained in:
@@ -146,7 +146,7 @@ class Customer < ApplicationRecord
|
||||
if sale.customer.membership_id
|
||||
response = self.rebat(Sale.find(sale.sale_id))
|
||||
#record an payment in sale-audit
|
||||
remark = "UPdate Rebate Response - #{response} for Customer #{sale.customer_id} Sale Id [#{sale.sale_id}]| pay amount -> #{sale.received_amount} "
|
||||
remark = "UPdate Rebate Response - #{response} for Customer #{sale.customer_id} Sale Id [#{sale.sale_id}]| pay amount -> #{sale.amount_received} "
|
||||
sale_audit = SaleAudit.record_paymal(sale.sale_id, remark, 1)
|
||||
|
||||
if response["status"] == true
|
||||
@@ -157,66 +157,137 @@ class Customer < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.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
|
||||
if generic_customer_id.present?
|
||||
paypar = sObj.sale_payments
|
||||
|
||||
paypar = sObj.sale_payments
|
||||
payparcost = 0
|
||||
credit = 0
|
||||
credit = 0
|
||||
|
||||
paypar.each do |pp|
|
||||
if pp.payment_method == "paypar"
|
||||
payparcost = payparcost + pp.payment_amount
|
||||
elsif pp.payment_method == "creditnote"
|
||||
end
|
||||
if pp.payment_method == "creditnote"
|
||||
credit = 1
|
||||
end
|
||||
end
|
||||
|
||||
# overall_dis = SaleItem.get_overall_discount(sObj.id)
|
||||
overall_dis = sObj.total_discount
|
||||
|
||||
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
|
||||
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
|
||||
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,
|
||||
auth_token:auth_token}.to_json,
|
||||
:headers => {
|
||||
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; version=2'
|
||||
}, :timeout => 10)
|
||||
'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
|
||||
|
||||
redeem_amount = payparcost + overall_dis
|
||||
|
||||
total_percentage = 0
|
||||
|
||||
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
|
||||
return response
|
||||
Rails.logger.debug "--------Update Rebate response -------"
|
||||
Rails.logger.debug response.to_json
|
||||
|
||||
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
|
||||
end
|
||||
else
|
||||
response = { "status": "no_member", "message": "Not membership"}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user