Files
sx-fc/app/models/customer.rb
2017-06-13 20:11:24 +06:30

57 lines
1.6 KiB
Ruby

class Customer < ApplicationRecord
#self.primary_key = :customer_id
before_create :generate_custom_id
has_many :orders
has_many :sales
validates_presence_of :name, :contact_no, :email
validates :contact_no, uniqueness: true
validates :email, uniqueness: true
paginates_per 50
def self.get_member_group
membership = MembershipSetting.find_by_membership_type("paypar_url")
memberaction = MembershipAction.find_by_membership_type("get_all_member_group")
app_token = membership.auth_token.to_s
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
response = HTTParty.get(url,
:body => { app_token: app_token}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
}
)
puts response.body, response.code, response.message, response.headers.inspect
return response;
end
def self.search(search)
if search
# find(:all, :conditions => ['name LIKE ? OR contact_no LIKE ?', "%#{search}%", "%#{search}%"])
where("name LIKE ? OR contact_no LIKE ?", "%#{search}%", "%#{search}%",)
else
find(:all)
end
end
# def self.search(search)
# where("name LIKE ? OR contact_no LIKE ?", "%#{search}%", "%#{search}%",)
# end
def lastest_invoices
sales.where(:customer_id => self.id).order("created_at desc").limit(5)
end
private
def generate_custom_id
self.customer_id = SeedGenerator.generate_id(self.class.name, "CUS")
end
end