diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 49c64e52..cb2c6dd2 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -17,6 +17,8 @@ class Crm::CustomersController < BaseCrmController @crm_customer = Customer.new @count_customer = Customer.count_customer + @taxes = TaxProfile.all.order("order_by asc") + # if flash["errors"] # @crm_customer.valid? # end @@ -67,11 +69,14 @@ class Crm::CustomersController < BaseCrmController # POST /crm/customers # POST /crm/customers.json - def create + def create @crm_customers = Customer.new(customer_params) respond_to do |format| if @crm_customers.save + # update tax profile + customer = Customer.find(@crm_customers.customer_id) + customer.update_attributes(tax_profiles: params[:customer][:tax_profiles].to_json) name = customer_params[:name] phone = customer_params[:contact_no] email = customer_params[:email] @@ -346,7 +351,7 @@ end # 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,:salutation,:gender,:nrc_no,:address,:card_no, :paypar_account_no) + params.require(:customer).permit(:id, :name, :company, :contact_no, :email, + :date_of_birth,:salutation,:gender,:nrc_no,:address,:card_no, :paypar_account_no, :customer_type) end end diff --git a/app/views/crm/customers/_new_form.html.erb b/app/views/crm/customers/_new_form.html.erb index 1eda0bec..13896e85 100644 --- a/app/views/crm/customers/_new_form.html.erb +++ b/app/views/crm/customers/_new_form.html.erb @@ -1,25 +1,7 @@
<%= simple_form_for @crm_customer,:url => crm_customers_path, :method => :post do |f| %> - <%= f.hidden_field :id, :class => "form-control col-md-6 " %> - -
"> - <%= f.input :card_no, :class => "form-control col-md-6 card_no"%> - <% flash.each do |name, msg| %> - <% str="[\"#{msg['card_no']}\"]" - str.gsub!('["', '') - str.gsub!('"]', '') %> - <%= str %> - <% end %> -
- -
- -
- -
-
-
+ <%= f.hidden_field :id, :class => "form-control col-md-6 " %>

@@ -102,6 +84,38 @@ <%= f.text_field :date_of_birth,:value=>"01-01-1990",:class=>"form-control datepicker"%>
+
"> + <%= f.input :card_no, :class => "form-control col-md-6 card_no"%> + <% flash.each do |name, msg| %> + <% str="[\"#{msg['card_no']}\"]" + str.gsub!('["', '') + str.gsub!('"]', '') %> + <%= str %> + <% end %> +
+ +
+ + +
+ +
+ <%= f.input :tax_profiles, :collection => @taxes, :input_html => { :multiple => true }, :class => "form-control col-md-6 tax_profiles" %> +
+ +
+ +
+ +
+
+
+
- +
@@ -138,6 +151,11 @@ },100); } }); + + // $("#customer_card_no").click(function(){ + // var ab=$("#customer_tax_profiles").val(); + // console.log(JSON.stringify(ab)); + // }); }); diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index 6f336158..f2d28b19 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -76,7 +76,7 @@
- <%= render 'new_form', crm_customer: @crm_customer %> + <%= render 'new_form', crm_customer: @crm_customer, taxes: @taxes %>

diff --git a/db/migrate/20170622050926_create_customers.rb b/db/migrate/20170622050926_create_customers.rb index 28f38e15..cb370bc1 100644 --- a/db/migrate/20170622050926_create_customers.rb +++ b/db/migrate/20170622050926_create_customers.rb @@ -16,7 +16,7 @@ class CreateCustomers < ActiveRecord::Migration[5.1] t.string :membership_id t.string :membership_type t.string :membership_authentication_code - t.string :customer_type, default => "Dinein" + t.string :customer_type, :default => "Dinein" t.json :tax_profiles end end diff --git a/db/seeds.rb b/db/seeds.rb index 4e39275d..1b63bcb0 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -94,10 +94,9 @@ float_value = Lookup.create([{lookup_type:'float_value', name: '500', value: '50 {lookup_type:'float_value', name: '10000', value: '10000'}]) # customer type -customer_type = Lookup.create([{lookup_type:'float_value', name: '500', value: '500'}, - {lookup_type:'float_value', name: '1000', value: '1000'}, - {lookup_type:'float_value', name: '5000', value: '5000'}, - {lookup_type:'float_value', name: '10000', value: '10000'}]) +customer_type = Lookup.create([{lookup_type:'customer_type', name: 'Dinein', value: 'Dinein'}, + {lookup_type:'customer_type', name: 'Takeaway', value: 'Takeaway'}, + {lookup_type:'customer_type', name: 'Delivery', value: 'Delivery'}]) #WALK CUSTOMER - Default CUSTOMER (take key 1) customer = Customer.create({name:"WALK-IN", email: "cus1@customer.com", contact_no:"000000000",card_no:"000"})