remove member_discount method from sale

This commit is contained in:
Thein Lin Kyaw
2020-07-21 11:38:54 +06:30
parent 4e61eba843
commit 567a716fe3
2 changed files with 1 additions and 46 deletions

View File

@@ -26,7 +26,7 @@ class Sale < ApplicationRecord
has_one :booking
has_many :product_commissions
before_save :member_discount, :round_to_precision
before_save :round_to_precision
after_update :update_stock_journal
scope :open_invoices, -> { where("sale_status = 'new' and receipt_date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") }
@@ -2321,50 +2321,6 @@ private
end
end
def member_discount
return unless will_save_change_to_customer_id? || will_save_change_to_total_amount?
if self.customer && self.customer.membership_id.present?
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
url = "#{membership.gateway_url}#{memberaction.gateway_url}"
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; version=3'
}, :timeout => 10)
rescue Net::OpenTimeout
response = { "status": false , "message": " Connection timeout" }
rescue OpenURI::HTTPError
response = { "status": false, "message": "Can't connect server"}
rescue SocketError
response = { "status": false, "message": "Can't connect server"}
end
return unless response['status'] && response['membership_campaign_data'].present?
Account.where(discount: true).inject(0) do |dis, acc|
rule = response['membership_campaign_data'].find { |c| c['rules_type'].downcase.strip == acc.title.downcase.strip }
dis += acc.sale_items.inject(0) { |i| i.account_id == acc.id ? i.price : 0 } * rule["change_unit"].to_i / rule["base_unit"].to_i
end
else
end
end
def round_to_precision
if (self.total_amount % 1 > 0 || self.total_discount % 1 > 0 || self.total_tax % 1 > 0)
self.total_amount = self.total_amount.round(precision)

View File

@@ -180,7 +180,6 @@ class ShiftSale < ApplicationRecord
def self.get_total_member_discount(shift)
query = Sale.select("SUM(sales.total_discount) as member_discount")
.where("shift_sale_id =? and sale_status = 'completed' and discount_type = 'member_discount'", shift.id)
end
def self.get_total_dinein(shift)