finished Customer save and return data from membership in crm

This commit is contained in:
Aung Myo
2017-06-06 18:07:38 +06:30
parent 8fd23bfd87
commit 9e3eaaf214
4 changed files with 76 additions and 23 deletions

View File

@@ -10,20 +10,47 @@ class Customer < ApplicationRecord
validates :contact_no, uniqueness: true
validates :email, uniqueness: true
# attr_accessor :name, :company, :contact_no, :email, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code
def self.get_member_group
gateway_url = MembershipSetting.find_by_membership_type("smartpay_url")
url = gateway_url.gateway_url.to_s + "/api/get_all_member_group".to_s
response = HTTParty.get(url)
membership = MembershipSetting.find_by_membership_type("smartpay_url")
app_token = membership.auth_token.to_s
url = membership.gateway_url.to_s + "/api/get_all_member_group".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
# http://192.168.1.47:3006/api/create_membership_customer
#get_all_member_group
def self.generate(params)
puts "Hello "
puts params.to_json
customer = Customer.new
customer.name= params[:name]
customer.company= params[:company]
customer.contact_no= params[:contact_no]
customer.email= params[:email]
customer.date_of_birth= params[:date_of_birth]
customer.membership_id= params[:membership_id]
customer.membership_type= params[:membership_type]
customer.membership_authentication_code= params[:membership_authentication_code]
customer.save!
return customer
end
def lastest_invoices
sales.where(:customer_id => self.id).order("created_at desc").limit(5)