diff --git a/Gemfile.lock b/Gemfile.lock index 533cd08b..ae2a3941 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index c25f6e80..15657a98 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -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 + + diff --git a/app/models/customer.rb b/app/models/customer.rb index 95901cce..206c2ada 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -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) diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index 8088bcba..ce4c3826 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -47,7 +47,7 @@