finished Customer save and return data from membership in crm
This commit is contained in:
@@ -124,7 +124,6 @@ GEM
|
|||||||
nokogiri (1.7.2)
|
nokogiri (1.7.2)
|
||||||
mini_portile2 (~> 2.1.0)
|
mini_portile2 (~> 2.1.0)
|
||||||
pdf-core (0.7.0)
|
pdf-core (0.7.0)
|
||||||
pg (0.20.0)
|
|
||||||
prawn (2.2.2)
|
prawn (2.2.2)
|
||||||
pdf-core (~> 0.7.0)
|
pdf-core (~> 0.7.0)
|
||||||
ttfunk (~> 1.5)
|
ttfunk (~> 1.5)
|
||||||
@@ -260,7 +259,6 @@ DEPENDENCIES
|
|||||||
kaminari!
|
kaminari!
|
||||||
listen (~> 3.0.5)
|
listen (~> 3.0.5)
|
||||||
mysql2 (>= 0.3.18, < 0.5)
|
mysql2 (>= 0.3.18, < 0.5)
|
||||||
pg
|
|
||||||
prawn
|
prawn
|
||||||
prawn-table
|
prawn-table
|
||||||
puma (~> 3.0)
|
puma (~> 3.0)
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ class Crm::CustomersController < ApplicationController
|
|||||||
# GET /crm/customers.json
|
# GET /crm/customers.json
|
||||||
def index
|
def index
|
||||||
@crm_customers = Customer.all
|
@crm_customers = Customer.all
|
||||||
@customers = Customer.new
|
@crm_customer = Customer.new
|
||||||
@membership = Customer.get_member_group
|
@membership = Customer.get_member_group
|
||||||
|
if @membership["status"] == true
|
||||||
|
@member_group = @membership["data"]
|
||||||
|
end
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # index.html.erb
|
format.html # index.html.erb
|
||||||
format.json { render json: @crm_customers }
|
format.json { render json: @crm_customers }
|
||||||
@@ -33,14 +35,39 @@ class Crm::CustomersController < ApplicationController
|
|||||||
# POST /crm/customers
|
# POST /crm/customers
|
||||||
# POST /crm/customers.json
|
# POST /crm/customers.json
|
||||||
def create
|
def create
|
||||||
@crm_customer = Customer.new(customer_params)
|
puts "Hello"
|
||||||
|
puts customer_params.to_json
|
||||||
|
@crm_customers = Customer.new(customer_params)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @crm_customer.save
|
if @crm_customers.save
|
||||||
format.html { redirect_to @crm_customer, notice: 'Customer was successfully created.' }
|
|
||||||
format.json { render :show, status: :created, location: @crm_customer }
|
name = customer_params[:name]
|
||||||
|
phone = customer_params[:contact_no]
|
||||||
|
email = customer_params[:email]
|
||||||
|
date_of_birth = customer_params[:date_of_birth]
|
||||||
|
membership_id = params[:membership_id]
|
||||||
|
|
||||||
|
membership = MembershipSetting.find_by_membership_type("smartpay_url")
|
||||||
|
app_token = membership.auth_token.to_s
|
||||||
|
url = membership.gateway_url.to_s + "/api/create_membership_customer".to_s
|
||||||
|
|
||||||
|
response = HTTParty.post(url,
|
||||||
|
:body => { name: name,phone: phone,email: email,date_of_birth: date_of_birth,membership_id: membership_id}.to_json,
|
||||||
|
:headers => {
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
'Accept' => 'application/json'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
puts "rrrrrrrrrrrrrr"
|
||||||
|
puts response.to_json
|
||||||
|
|
||||||
|
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' }
|
||||||
|
format.json { render :index, status: :created, location: @crm_customers }
|
||||||
|
|
||||||
else
|
else
|
||||||
format.html { render :new }
|
format.html { render :index }
|
||||||
format.json { render json: @crm_customer.errors, status: :unprocessable_entity }
|
format.json { render json: @crm_customer.errors, status: :unprocessable_entity }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -78,6 +105,9 @@ class Crm::CustomersController < ApplicationController
|
|||||||
|
|
||||||
# Never trust parameters from the scary internet, only allow the white list through.
|
# Never trust parameters from the scary internet, only allow the white list through.
|
||||||
def customer_params
|
def customer_params
|
||||||
params.require(:customer).permit(:name, :company, :contact_no, :email, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code)
|
|
||||||
|
params.require(:customer).permit(:name, :company, :contact_no, :email, :date_of_birth, :membership_type, :membership_authentication_code)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,20 +10,47 @@ class Customer < ApplicationRecord
|
|||||||
validates :contact_no, uniqueness: true
|
validates :contact_no, uniqueness: true
|
||||||
validates :email, 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
|
def self.get_member_group
|
||||||
|
|
||||||
gateway_url = MembershipSetting.find_by_membership_type("smartpay_url")
|
membership = MembershipSetting.find_by_membership_type("smartpay_url")
|
||||||
url = gateway_url.gateway_url.to_s + "/api/get_all_member_group".to_s
|
app_token = membership.auth_token.to_s
|
||||||
response = HTTParty.get(url)
|
|
||||||
|
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
|
puts response.body, response.code, response.message, response.headers.inspect
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# http://192.168.1.47:3006/api/create_membership_customer
|
# http://192.168.1.47:3006/api/create_membership_customer
|
||||||
#get_all_member_group
|
#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
|
def lastest_invoices
|
||||||
sales.where(:customer_id => self.id).order("created_at desc").limit(5)
|
sales.where(:customer_id => self.id).order("created_at desc").limit(5)
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-lg-5">
|
<div class="col-lg-5">
|
||||||
<%= simple_form_for crm_customers_path, :html => { :class => 'form-horizontal' } do |f| %>
|
<%= simple_form_for @crm_customer, :url => crm_customers_path, :method => :post do |f| %>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<%= f.input :name, :class => "form-control col-md-6" %>
|
<%= f.input :name, :class => "form-control col-md-6" %>
|
||||||
@@ -63,18 +63,16 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="date_of_birth" class="col-md-6 control-label">Date Of Birth</label>
|
|
||||||
<%= f.text_field :date_of_birth,:class=>"form-control datepicker",:readonly =>true, :value => @date_of_birth%>
|
<%= f.text_field :date_of_birth,:class=>"form-control datepicker",:readonly =>true, :value => @date_of_birth%>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<%= f.select :membership_id, options_for_select(@membership.collect { |member|
|
|
||||||
[member["name"], member["id"]] }, 1), {}, { id: 'countries_select' } %>
|
|
||||||
|
|
||||||
<select class="selectpicker form-control col-md-6" name="membership_id">
|
<select class="selectpicker form-control col-md-6" name="membership_id">
|
||||||
<option>Select Member Group</option>
|
<option>Select Member Group</option>
|
||||||
<% @membership.each do |member| %>
|
<% @member_group.each do |member| %>
|
||||||
<option value="<%= member["id"] %>">
|
<option value="<%= member["id"] %>">
|
||||||
<%= member["name"] %></option>
|
<%= member["name"] %></option>
|
||||||
<%end %>
|
<%end %>
|
||||||
|
|||||||
Reference in New Issue
Block a user