From d2ce74f648a6c271c3307d5c246532a336eb9439 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 6 Jun 2017 14:16:40 +0630 Subject: [PATCH] bootstrap datepicker and customer save --- Gemfile | 4 +- Gemfile.lock | 3 + app/assets/javascripts/application.js | 1 + app/assets/stylesheets/application.scss | 1 + app/controllers/crm/customers_controller.rb | 18 ++- app/models/customer.rb | 21 ++- app/views/api/bookings/show.json.jbuilder | 1 - app/views/crm/customers/_form.html.erb | 2 +- app/views/crm/customers/index.html.erb | 141 +++++++++++++++----- 9 files changed, 146 insertions(+), 46 deletions(-) diff --git a/Gemfile b/Gemfile index f64229aa..c0663409 100644 --- a/Gemfile +++ b/Gemfile @@ -92,4 +92,6 @@ end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] -gem 'httparty', '~> 0.15.5' \ No newline at end of file +gem 'httparty', '~> 0.15.5' + +gem 'bootstrap-datepicker-rails' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 7bf4f9a4..ae2a3941 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -64,6 +64,8 @@ GEM bootstrap (4.0.0.alpha6) autoprefixer-rails (>= 6.0.3) sass (>= 3.4.19) + bootstrap-datepicker-rails (1.6.4.1) + railties (>= 3.0) builder (3.2.3) byebug (9.0.6) coffee-rails (4.2.2) @@ -243,6 +245,7 @@ PLATFORMS DEPENDENCIES bcrypt (~> 3.1.7) bootstrap (~> 4.0.0.alpha3) + bootstrap-datepicker-rails byebug coffee-rails (~> 4.2) cups (~> 0.0.7) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index f7b2e2b0..f2ee34ba 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -17,3 +17,4 @@ //= require turbolinks //= require cable //= require settings/processing_items +//= require bootstrap-datepicker diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 9456be10..d8101494 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -2,6 +2,7 @@ @import "bootstrap"; @import "font-awesome"; @import "theme"; +@import "bootstrap-datepicker3"; /* Show it is fixed to the top */ // body { diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 896d9d14..c25f6e80 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -5,6 +5,13 @@ class Crm::CustomersController < ApplicationController # GET /crm/customers.json def index @crm_customers = Customer.all + @customers = Customer.new + @membership = Customer.get_member_group + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @crm_customers } + end end # GET /crm/customers/1 @@ -15,7 +22,8 @@ class Crm::CustomersController < ApplicationController # GET /crm/customers/new def new @crm_customer = Customer.new - @membership = Customer.get_member_group + @membership = Customer.get_member_group() + end # GET /crm/customers/1/edit @@ -25,7 +33,7 @@ class Crm::CustomersController < ApplicationController # POST /crm/customers # POST /crm/customers.json def create - @crm_customer = Customer.new(crm_customer_params) + @crm_customer = Customer.new(customer_params) respond_to do |format| if @crm_customer.save @@ -42,7 +50,7 @@ class Crm::CustomersController < ApplicationController # PATCH/PUT /crm/customers/1.json def update respond_to do |format| - if @crm_customer.update(crm_customer_params) + if @crm_customer.update(customer_params) format.html { redirect_to @crm_customer, notice: 'Customer was successfully updated.' } format.json { render :show, status: :ok, location: @crm_customer } else @@ -69,7 +77,7 @@ class Crm::CustomersController < ApplicationController end # Never trust parameters from the scary internet, only allow the white list through. - def crm_customer_params - params.require(:crm_customer).permit(:name, :company, :contact_no, :email, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code) + def customer_params + params.require(:customer).permit(:name, :company, :contact_no, :email, :date_of_birth, :membership_id, :membership_type, :membership_authentication_code) end end diff --git a/app/models/customer.rb b/app/models/customer.rb index 4bdc290a..95901cce 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -1,12 +1,29 @@ class Customer < ApplicationRecord - self.primary_key = "customer_id" + + #self.primary_key = :customer_id before_create :generate_custom_id has_many :orders has_many :sales - validates_presence_of :name, :contact_no + validates_presence_of :name, :contact_no, :email validates :contact_no, uniqueness: true + validates :email, uniqueness: true + + 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) + 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 lastest_invoices sales.where(:customer_id => self.id).order("created_at desc").limit(5) diff --git a/app/views/api/bookings/show.json.jbuilder b/app/views/api/bookings/show.json.jbuilder index cbd1575a..27ec21b9 100644 --- a/app/views/api/bookings/show.json.jbuilder +++ b/app/views/api/bookings/show.json.jbuilder @@ -13,7 +13,6 @@ if (@booking) @total_amount = 0.00 @total_tax = 0.00 - @booking_orders = BookingOrder.where("booking_id = #{@booking.booking_id}").all; if @booking.booking_orders order_items = [] @booking.booking_orders.each do |bo| diff --git a/app/views/crm/customers/_form.html.erb b/app/views/crm/customers/_form.html.erb index 7c37a2fe..533710a9 100644 --- a/app/views/crm/customers/_form.html.erb +++ b/app/views/crm/customers/_form.html.erb @@ -8,7 +8,7 @@ <%= f.input :contact_no %> <%= f.input :email %> <%= f.input :date_of_birth %> - + <%= f.input :membership_id, :collection => @membership %> <%= f.input :membership_type %> <%= f.input :membership_authentication_code %> diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index 5a29b74c..d866d47d 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -1,41 +1,110 @@ -

<%= notice %>

+
+ +
+
-

Crm Customers

+
+
+ +
+
+ + + + + + + + + + -
NameCompanyContact noEmail
- - - - - - - - - - - - - + + <% @crm_customers.each do |crm_customer| %> + + + + + + + + <% end %> + +
NameCompanyContact noEmailDate of birthMembershipMembership typeMembership authentication code
<%= crm_customer.name %><%= crm_customer.company %><%= crm_customer.contact_no %><%= crm_customer.email %>
+
+
- - <% @crm_customers.each do |crm_customer| %> - - <%= crm_customer.name %> - <%= crm_customer.company %> - <%= crm_customer.contact_no %> - <%= crm_customer.email %> - <%= crm_customer.date_of_birth %> - <%= crm_customer.membership_id %> - <%= crm_customer.membership_type %> - <%= crm_customer.membership_authentication_code %> - <%= link_to 'Show', crm_customer_path(crm_customer) %> - <%= link_to 'Edit', edit_crm_customer_path(crm_customer) %> - <%= link_to 'Destroy', crm_customer_path(crm_customer), method: :delete, data: { confirm: 'Are you sure?' } %> - - <% end %> - - +
-
+
+ <%= simple_form_for crm_customers_path, :html => { :class => 'form-horizontal' } do |f| %> + +
+ <%= f.input :name, :class => "form-control col-md-6" %> +
+
+ <%= f.input :company, :class => "form-control col-md-6" %> +
+
+ <%= f.input :contact_no, :class => "form-control col-md-6" %> +
+
+ <%= f.input :email, :class => "form-control col-md-6" %> +
-<%= link_to 'New Crm Customer', new_crm_customer_path %> +
+ + <%= f.text_field :date_of_birth,:class=>"form-control datepicker",:readonly =>true, :value => @date_of_birth%> + +
+ +
+ <%= f.select :membership_id, options_for_select(@membership.collect { |member| + [member["id"].name.titleize, member["id"].id] }, 1), {}, { id: 'countries_select' } %> + +
+ + +
+ <%= f.input :membership_type, :class => "form-control col-md-6" %> +
+
+ <%= f.input :membership_authentication_code, :class => "form-control col-md-6" %> + +
+
+ <%= f.button :submit, "Submit", :class => 'btn btn-primary' , :id => 'submit_account' %> +
+ <%end%> +
+
+ +