change rebate calculation formula

This commit is contained in:
phyusin
2018-12-18 16:05:36 +06:30
parent 04d5e86291
commit da96c57c8c
2 changed files with 39 additions and 21 deletions

View File

@@ -101,20 +101,25 @@ class SaleAudit < ApplicationRecord
end
def self.paymal_search(sale_id)
amount = nil
paymal = SaleAudit.where("sale_id =? and action = 'PAYMAL'",sale_id)
remark = paymal[0].remark.split("}")
response = "["+remark[0]+'}]'
response = JSON.parse(response)
puts response
if response[0]["status"] == true
if response[0]["current_rebate_amount"].present?
amount = response[0]["current_rebate_amount"]
if !paymal.nil?
if paymal[0]
remark = paymal[0].remark.split("}")
response = "["+remark[0]+'}]'
response = JSON.parse(response)
puts response
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
amount = response[0]["current_balance_amount"]
amount = nil
end
else
amount = nil
end
end
end
return amount
end

View File

@@ -728,6 +728,7 @@ class SalePayment < ApplicationRecord
def rebat(sObj)
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
@@ -780,28 +781,38 @@ class SalePayment < ApplicationRecord
total_percentage = 0
type_arr = []
Rails.logger.debug "Get Member Campaign"
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)
campaign_method.each do |cm|
if cm[:type].downcase.strip == a["rules_type"].downcase.strip
if cm[:amount] > 0
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
Rails.logger.debug "--------------Get Member Campaign Data----------"
Rails.logger.debug type_arr.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 (si[:type] == a[:type]) && (a[:amount] > 0)
if credit == 1
data[:amount] = 0
else
amount = (redeem_amount / total_percentage)*si[:percentage]
actual = a[:amount] - amount
amount = (redeem_amount / total_percentage).to_f * si[:percentage]
actual = a[:amount].to_f - amount.to_f
data[:amount] = actual
end
@@ -809,9 +820,11 @@ class SalePayment < ApplicationRecord
end
rebate_arr.push(data)
end
Rails.logger.debug "Rebage Response"
Rails.logger.debug rebate_arr.to_json
Rails.logger.debug "---------------Rebate Response----------------"
Rails.logger.debug rebate_arr.to_json
total_amount = rebate_prices - payparcost - overall_dis
Rails.logger.debug total_amount
if credit == 1
total_amount = 0