diff --git a/app/models/sale.rb b/app/models/sale.rb index 70f0da4e..8c6d7847 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -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}'") } @@ -2436,50 +2436,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) diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index dc96a425..daffd8cf 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -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)