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

@@ -124,7 +124,6 @@ GEM
nokogiri (1.7.2)
mini_portile2 (~> 2.1.0)
pdf-core (0.7.0)
pg (0.20.0)
prawn (2.2.2)
pdf-core (~> 0.7.0)
ttfunk (~> 1.5)
@@ -260,7 +259,6 @@ DEPENDENCIES
kaminari!
listen (~> 3.0.5)
mysql2 (>= 0.3.18, < 0.5)
pg
prawn
prawn-table
puma (~> 3.0)

View File

@@ -5,9 +5,11 @@ class Crm::CustomersController < ApplicationController
# GET /crm/customers.json
def index
@crm_customers = Customer.all
@customers = Customer.new
@crm_customer = Customer.new
@membership = Customer.get_member_group
if @membership["status"] == true
@member_group = @membership["data"]
end
respond_to do |format|
format.html # index.html.erb
format.json { render json: @crm_customers }
@@ -33,14 +35,39 @@ class Crm::CustomersController < ApplicationController
# POST /crm/customers
# POST /crm/customers.json
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|
if @crm_customer.save
format.html { redirect_to @crm_customer, notice: 'Customer was successfully created.' }
format.json { render :show, status: :created, location: @crm_customer }
if @crm_customers.save
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
format.html { render :new }
format.html { render :index }
format.json { render json: @crm_customer.errors, status: :unprocessable_entity }
end
end
@@ -78,6 +105,9 @@ class Crm::CustomersController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
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

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)

View File

@@ -47,7 +47,7 @@
</div>
<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">
<%= f.input :name, :class => "form-control col-md-6" %>
@@ -63,22 +63,20 @@
</div>
<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%>
</div>
<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>
<% @membership.each do |member| %>
<% @member_group.each do |member| %>
<option value="<%= member["id"] %>">
<%= member["name"] %></option>
<%end %>
</select>
</select>
</div>
@@ -90,7 +88,7 @@
</div>
<div class="form-group">
<%= f.button :submit, "Submit", :class => 'btn btn-primary' , :id => 'submit_account' %>
<%= f.button :submit, "Submit",:class => 'btn btn-primary' , :id => 'submit_account' %>
</div>
<%end%>
</div>