change rebate calculation formula
This commit is contained in:
@@ -101,20 +101,25 @@ class SaleAudit < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.paymal_search(sale_id)
|
def self.paymal_search(sale_id)
|
||||||
|
amount = nil
|
||||||
paymal = SaleAudit.where("sale_id =? and action = 'PAYMAL'",sale_id)
|
paymal = SaleAudit.where("sale_id =? and action = 'PAYMAL'",sale_id)
|
||||||
remark = paymal[0].remark.split("}")
|
if !paymal.nil?
|
||||||
response = "["+remark[0]+'}]'
|
if paymal[0]
|
||||||
response = JSON.parse(response)
|
remark = paymal[0].remark.split("}")
|
||||||
puts response
|
response = "["+remark[0]+'}]'
|
||||||
if response[0]["status"] == true
|
response = JSON.parse(response)
|
||||||
if response[0]["current_rebate_amount"].present?
|
puts response
|
||||||
amount = response[0]["current_rebate_amount"]
|
if response[0]["status"] == true
|
||||||
|
if response[0]["current_rebate_amount"].present?
|
||||||
|
amount = response[0]["current_rebate_amount"]
|
||||||
|
else
|
||||||
|
amount = response[0]["current_balance_amount"]
|
||||||
|
end
|
||||||
else
|
else
|
||||||
amount = response[0]["current_balance_amount"]
|
amount = nil
|
||||||
end
|
end
|
||||||
else
|
end
|
||||||
amount = nil
|
end
|
||||||
end
|
|
||||||
return amount
|
return amount
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -728,6 +728,7 @@ class SalePayment < ApplicationRecord
|
|||||||
def rebat(sObj)
|
def rebat(sObj)
|
||||||
rebate_prices,campaign_method = 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
|
||||||
@@ -780,28 +781,38 @@ class SalePayment < ApplicationRecord
|
|||||||
total_percentage = 0
|
total_percentage = 0
|
||||||
|
|
||||||
type_arr = []
|
type_arr = []
|
||||||
Rails.logger.debug "Get Member Campaign"
|
Rails.logger.debug "-------------Get Member Campaign--------------"
|
||||||
Rails.logger.debug response.to_json
|
Rails.logger.debug response.to_json
|
||||||
# Check for present response fields
|
# Check for present response fields
|
||||||
if response["membership_campaign_data"].present?
|
if response["membership_campaign_data"].present?
|
||||||
response["membership_campaign_data"].each do |a|
|
response["membership_campaign_data"].each do |a|
|
||||||
data = {:type => a["rules_type"], :percentage => a["change_unit"].to_i * a["base_unit"].to_i}
|
campaign_method.each do |cm|
|
||||||
total_percentage = total_percentage + a["change_unit"].to_i * a["base_unit"].to_i
|
if cm[:type].downcase.strip == a["rules_type"].downcase.strip
|
||||||
|
if cm[:amount] > 0
|
||||||
type_arr.push(data)
|
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
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Rails.logger.debug "--------------Get Member Campaign Data----------"
|
||||||
|
Rails.logger.debug type_arr.to_json
|
||||||
|
|
||||||
rebate_arr =[]
|
rebate_arr =[]
|
||||||
|
|
||||||
campaign_method.each do |a|
|
campaign_method.each do |a|
|
||||||
data = {:type => a[:type], :amount => a[:amount]}
|
data = {:type => a[:type], :amount => a[:amount]}
|
||||||
type_arr.each do |si|
|
type_arr.each do |si|
|
||||||
if si[:type] == a[:type]
|
if (si[:type] == a[:type]) && (a[:amount] > 0)
|
||||||
if credit == 1
|
if credit == 1
|
||||||
data[:amount] = 0
|
data[:amount] = 0
|
||||||
else
|
else
|
||||||
amount = (redeem_amount / total_percentage)*si[:percentage]
|
amount = (redeem_amount / total_percentage).to_f * si[:percentage]
|
||||||
actual = a[:amount] - amount
|
actual = a[:amount].to_f - amount.to_f
|
||||||
data[:amount] = actual
|
data[:amount] = actual
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -809,9 +820,11 @@ class SalePayment < ApplicationRecord
|
|||||||
end
|
end
|
||||||
rebate_arr.push(data)
|
rebate_arr.push(data)
|
||||||
end
|
end
|
||||||
Rails.logger.debug "Rebage Response"
|
Rails.logger.debug "---------------Rebate Response----------------"
|
||||||
Rails.logger.debug rebate_arr.to_json
|
Rails.logger.debug rebate_arr.to_json
|
||||||
|
|
||||||
total_amount = rebate_prices - payparcost - overall_dis
|
total_amount = rebate_prices - payparcost - overall_dis
|
||||||
|
Rails.logger.debug total_amount
|
||||||
|
|
||||||
if credit == 1
|
if credit == 1
|
||||||
total_amount = 0
|
total_amount = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user