bootstrap datepicker and customer save

This commit is contained in:
Aung Myo
2017-06-06 14:16:40 +06:30
parent 324f1e3b24
commit d2ce74f648
9 changed files with 146 additions and 46 deletions

View File

@@ -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'
gem 'httparty', '~> 0.15.5'
gem 'bootstrap-datepicker-rails'

View File

@@ -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)

View File

@@ -17,3 +17,4 @@
//= require turbolinks
//= require cable
//= require settings/processing_items
//= require bootstrap-datepicker

View File

@@ -2,6 +2,7 @@
@import "bootstrap";
@import "font-awesome";
@import "theme";
@import "bootstrap-datepicker3";
/* Show it is fixed to the top */
// body {

View File

@@ -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

View File

@@ -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)

View File

@@ -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|

View File

@@ -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 %>
</div>

View File

@@ -1,41 +1,110 @@
<p id="notice"><%= notice %></p>
<div class="row">
<div class="col-lg-12">
<ol class="breadcrumb">
<li><a href="<%= dashboard_path %>">Home</a></li>
<li class="active">
<a href="<%= crm_customers_path %>">Customer</a>
</li>
<a href="<%= new_crm_customer_path%>" class="btn btn-primary pull-right">
<i class="fa fa-plus-circle fa-lg"></i> Add Customer
</a>
</ol>
</div>
</div>
<br/>
<h1>Crm Customers</h1>
<div class="row">
<div class="col-lg-7">
<div class="main-box-body clearfix">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Company</th>
<th>Contact no</th>
<th>Email</th>
</tr>
</thead>
<table>
<thead>
<tr>
<th>Name</th>
<th>Company</th>
<th>Contact no</th>
<th>Email</th>
<th>Date of birth</th>
<th>Membership</th>
<th>Membership type</th>
<th>Membership authentication code</th>
<th colspan="3"></th>
</tr>
</thead>
<tbody>
<% @crm_customers.each do |crm_customer| %>
<tr>
<td><%= crm_customer.name %></td>
<td><%= crm_customer.company %></td>
<td><%= crm_customer.contact_no %></td>
<td><%= crm_customer.email %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
<tbody>
<% @crm_customers.each do |crm_customer| %>
<tr>
<td><%= crm_customer.name %></td>
<td><%= crm_customer.company %></td>
<td><%= crm_customer.contact_no %></td>
<td><%= crm_customer.email %></td>
<td><%= crm_customer.date_of_birth %></td>
<td><%= crm_customer.membership_id %></td>
<td><%= crm_customer.membership_type %></td>
<td><%= crm_customer.membership_authentication_code %></td>
<td><%= link_to 'Show', crm_customer_path(crm_customer) %></td>
<td><%= link_to 'Edit', edit_crm_customer_path(crm_customer) %></td>
<td><%= link_to 'Destroy', crm_customer_path(crm_customer), method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
<br>
<div class="col-lg-5">
<%= simple_form_for crm_customers_path, :html => { :class => 'form-horizontal' } do |f| %>
<div class="form-group">
<%= f.input :name, :class => "form-control col-md-6" %>
</div>
<div class="form-group">
<%= f.input :company, :class => "form-control col-md-6" %>
</div>
<div class="form-group">
<%= f.input :contact_no, :class => "form-control col-md-6" %>
</div>
<div class="form-group">
<%= f.input :email, :class => "form-control col-md-6" %>
</div>
<%= link_to 'New Crm Customer', new_crm_customer_path %>
<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["id"].name.titleize, member["id"].id] }, 1), {}, { id: 'countries_select' } %>
<select class="selectpicker form-control col-md-6" name="membership_id">
<option>Select Member Group</option>
<% @membership.each do |member| %>
<option value="<%= member["id"] %>">
<%= member["name"] %></option>
<%end %>
</select>
</div>
<div class="form-group">
<%= f.input :membership_type, :class => "form-control col-md-6" %>
</div>
<div class="form-group">
<%= f.input :membership_authentication_code, :class => "form-control col-md-6" %>
</div>
<div class="form-group">
<%= f.button :submit, "Submit", :class => 'btn btn-primary' , :id => 'submit_account' %>
</div>
<%end%>
</div>
</div>
<script type="text/javascript">
$(function () {
if (jQuery().datepicker) {
$('.datepicker').datepicker({
format : 'dd-mm-yyyy',
autoclose: true
});
$('.datepicker').attr('ReadOnly','true');
$('.datepicker').css('cursor','pointer');
}
});
</script>