crm update

This commit is contained in:
Aung Myo
2017-06-11 18:00:34 +06:30
parent 9c228dce5c
commit d65882ac5b
10 changed files with 146 additions and 75 deletions

View File

@@ -33,6 +33,10 @@ $(document).ready(function(){
$("#customer").attr('disabled','disabled');
}
var customer_id=$(this).find(".customer-id").text();
show_customer_details(customer_id);
var cashier="";
var receipt_date="";
var sub_total=0;
@@ -142,6 +146,7 @@ $(document).ready(function(){
});
});
// Payment for Bill
$('#pay-bill').click(function() {
var sale_id=$(".selected-item").find(".orders-id").text();
@@ -157,10 +162,27 @@ $(document).ready(function(){
$('#customer').click(function() {
var sale_id=$(".selected-item").find(".orders-id").text();
window.location.href = '/crm/customers/'+ sale_id + "/assign_sale_id"
window.location.href = '/origami/'+ sale_id + "/add_customer"
return false;
});
function show_customer_details(customer_id){
$('.customer_detail').removeClass('hide');
//Start Ajax
$.ajax({
type: "GET",
url: "origami/"+customer_id+"/get_customer/",
data: {},
dataType: "json",
success: function(data) {
$("#customer_name").text(data.name);
$("#customer_name").text(data.name);
}
});
//End Ajax
}
/* For Receipt - Calculate discount or tax */
$('.cashier_number').on('click', function(event){
if(event.handled !== true) {

View File

@@ -4,21 +4,23 @@ class Crm::CustomersController < BaseCrmController
# GET /crm/customers
# GET /crm/customers.json
def index
@sale_id = 0
filter = params[:filter]
if filter.nil?
@crm_customers = Customer.order("name").page(params[:page])
@crm_customers = Customer.order("customer_id").page(params[:page])
#@products = Product.order("name").page(params[:page]).per(5)
else
@crm_customers = Customer.where("name LIKE ?", "%#{filter}%").order("name").page(params[:page])
end
#@crm_customers = Customer.all
@crm_customer = Customer.new
@membership = Customer.get_member_group
if @membership["status"] == true
@member_group = @membership["data"]
end
@crm_customer = Customer.new
@crm_customer.valid?
# @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 }
@@ -49,8 +51,6 @@ class Crm::CustomersController < BaseCrmController
respond_to do |format|
if @crm_customers.save
name = customer_params[:name]
phone = customer_params[:contact_no]
email = customer_params[:email]
@@ -71,41 +71,41 @@ class Crm::CustomersController < BaseCrmController
)
if response["status"] == true
puts "hhhhhhhhhhhhhhhhhh"
puts params[:sale_id]
puts response.to_json
customer = Customer.find(@crm_customers.customer_id)
status = customer.update_attributes(membership_id: response["customer_datas"]["id"])
if params[:sale_id] != 0
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' }
if params[:sale_id].nil?
format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer', notice: 'Customer was successfully created.' }
else
format.html { redirect_to '/crm/customers/'+params[:sale_id]+'/assign_sale_id', notice: 'Customer was successfully created.' }
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created.' }
end
# format.json { render :index, status: :created, location: @crm_customers }
else
@crm_customers.destroy
if params[:sale_id] != 0
format.html { redirect_to crm_customers_path, notice: response["message"] }
if params[:sale_id].nil?
format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'}
else
format.html { redirect_to '/crm/customers/'+params[:sale_id]+'/assign_sale_id', notice: response["message"] }
format.html { redirect_to crm_customers_path, notice: response["message"] }
end
end
# format.json { render :index, status: :created, location: @crm_customers }
else
if params[:sale_id] != 0
format.html { redirect_to crm_customers_path}
format.json { render json: @crm_customers.errors, status: :unprocessable_entity }
else
format.html { redirect_to '/crm/customers/'+params[:sale_id]+'/assign_sale_id', notice: response["message"] }
end
if params[:sale_id].nil?
format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'}
else
format.html { redirect_to crm_customers_path}
format.json { render json: @crm_customers.errors, status: :unprocessable_entity }
end
end
end
@@ -161,20 +161,7 @@ class Crm::CustomersController < BaseCrmController
# DELETE /crm/customers/1
# DELETE /crm/customers/1.json
def get_sale_id
@sale_id = params[:sale_id]
@crm_customers = Customer.all
@crm_customer = Customer.new
@membership = Customer.get_member_group
if @membership["status"] == true
@member_group = @membership["data"]
end
respond_to do |format|
format.html { render action: "index"}
format.json { render json: @crm_customers }
end
end
private
# Use callbacks to share common setup or constraints between actions.
@@ -185,7 +172,7 @@ class Crm::CustomersController < BaseCrmController
# 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_type, :membership_authentication_code)
params.require(:customer).permit(:name, :company, :contact_no, :email, :date_of_birth)
end
end

View File

@@ -1,7 +1,38 @@
class Origami::CustomersController < BaseOrigamiController
#Form to add customer -
def index
end
def create
# GET /crm/customers/1
# GET /crm/customers/1.json
def show
end
def add_customer
@sale_id = params[:sale_id]
filter = params[:filter]
if filter.nil?
@crm_customers = Customer.order("name").page(params[:page])
else
@crm_customers = Customer.where("name LIKE ?", "%#{filter}%").order("name").page(params[:page])
end
@crm_customer = Customer.new
@membership = Customer.get_member_group
if @membership["status"] == true
@member_group = @membership["data"]
end
respond_to do |format|
# format.html { render :template => "crm/customers/index" }
format.html { render action: "index"}
format.json { render json: @crm_customers }
end
end
end

View File

@@ -3,6 +3,7 @@ class Origami::HomeController < BaseOrigamiController
@booking_orders = Order.get_booking_order_table()
@booking_rooms = Order.get_booking_order_rooms()
@orders = Order.get_orders()
end
def show
@@ -25,4 +26,23 @@ class Origami::HomeController < BaseOrigamiController
render :json => str.to_json
end
end
def update_sale_by_customer
sale = Sale.find(params[:sale_id])
status = sale.update_attributes(customer_id: params[:customer_id])
if status == true
render json: JSON.generate({:status => true})
else
render json: JSON.generate({:status => false, :error_message => "Record not found"})
end
end
def get_customer
@customer = Customer.find(params[:customer_id])
render :json => @customer.to_json
end
end

View File

@@ -222,7 +222,7 @@ class Order < ApplicationRecord
#Origami: Cashier : to view booking order Table
def self.get_booking_order_table
booking_orders = Booking.select("sales.receipt_no,orders.status as order_status,
booking_orders = Booking.select("sales.receipt_no,orders.status as order_status,orders.customer_id as customer_id,
bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name")
.joins("left join booking_orders on booking_orders.booking_id = bookings.booking_id")
.joins("left join dining_facilities on dining_facilities.id = bookings.dining_facility_id")
@@ -235,7 +235,7 @@ class Order < ApplicationRecord
#Origami: Cashier : to view order type Room
def self.get_booking_order_rooms
booking_rooms = Booking.select("sales.receipt_no,orders.status as order_status,bookings.booking_id,
booking_rooms = Booking.select("sales.receipt_no,orders.status as order_status,bookings.booking_id,orders.customer_id as customer_id,
sales.sale_id as sale_id,dining_facilities.name as room_name")
.joins("left join booking_orders on booking_orders.booking_id = bookings.booking_id")
.joins("left join dining_facilities on dining_facilities.id = bookings.dining_facility_id")
@@ -264,7 +264,7 @@ class Order < ApplicationRecord
from = Time.now.beginning_of_day.utc
to = Time.now.end_of_day.utc
orders = Order.select("orders.order_id as order_id,sales.receipt_no,orders.status as order_status,
bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name")
orders.customer_id as customer_id,bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name")
.joins("left join booking_orders on booking_orders.order_id = orders.order_id
left join bookings on bookings.booking_id = booking_orders.order_id
left join dining_facilities on dining_facilities.id = bookings.dining_facility_id

View File

@@ -69,8 +69,10 @@
<div class="col-lg-4">
<%= simple_form_for @crm_customer,:url => crm_customers_path, :method => :post do |f| %>
<span class="patch_method"></span>
<input type="hidden" id="sale_id" name="sale_id" value="<%= @sale_id %>" />
<%= f.error_notification %>
<%= f.hidden_field :id, :class => "form-control col-md-6 " %>
<div class="form-group">
@@ -95,24 +97,14 @@
<%= f.text_field :date_of_birth,:class=>"form-control date_of_birth datepicker"%>
</div>
<div class="form-group">
<select class="selectpicker form-control col-md-12" name="membership_id">
<option>Select Member Group</option>
<% @member_group.each do |member| %>
<option value="<%= member["id"] %>">
<%= member["name"] %></option>
<%end %>
</select>
</div>
<div class="form-group">
<!-- <div class="form-group">
<%= f.input :membership_type, :class => "form-control col-md-6 membership_type" %>
</div>
<div class="form-group">
<%= f.input :membership_authentication_code, :class => "form-control col-md-6 membership_authentication_code" %>
</div>
-->
<div class="form-group">
<%= f.button :submit, "Submit",:class => 'btn btn-primary ', :id => 'submit_customer' %>
<%= f.button :submit, "Update",:class => 'btn btn-primary ', :disabled =>'', :id => 'update_customer' %>
@@ -140,11 +132,11 @@
$(document).on('click',".checkbox_check",function(){
if(this.checked){
var sale_id = $("#sale_id").val() || 0;
var sale_id = $("#sale_id").val() || 0;
var customer_id = $(this).val();
if(sale_id != 0){
var url = "../"+customer_id;
// var url = "/"+customer_id;
update_sale(customer_id,sale_id);
}else{
@@ -201,7 +193,7 @@
action: function(){
$.ajax({
type: "POST",
url: "../../update_sale/" ,
url: "update_sale/" ,
data: {customer_id:customer_id,sale_id:sale_id},
dataType: "json",
success: function(data) {

View File

@@ -76,8 +76,9 @@ $(function(){
//End Print Click
$('.assign').click(function(e){
var booking_id = $(this).val()
var type = $(this).attr("data-type")
var booking_id = $(this).val();
var type = $(this).attr("data-type");
alert(booking_id);
update_booking(booking_id,type)
});
@@ -190,7 +191,7 @@ function update_booking(booking_id,type) {
//Start Ajax
$.ajax({
type: "POST",
url: "update_booking/" ,
url: "crm/update_booking/" ,
data: {booking_id:booking_id,type:type},
dataType: "json",
success: function(data) {

View File

@@ -3,7 +3,7 @@
<!-- Column One -->
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<!-- <ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#queue" role="tab">Queue <span class="badge badge-pill badge-default"><%= @queue.count %></span></a>
</li>
@@ -13,7 +13,7 @@
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#customer" role="tab">Customers</a>
</li>
</ul>
</ul> -->
<!-- Nav tabs - End -->
<div class="tab-content" style="min-height:670px; max-height:670px; overflow-y:scroll">

View File

@@ -37,6 +37,7 @@
<div class="card orders <%= sale_status %>">
<div class="card-block">
<p class="hidden orders-id"><%= unique_id %></p>
<p class="hidden customer-id"><%= bko.customer_id %></p>
<h4 class="card-title orders-table"><%= bko.table_name %></h4>
<p class="card-text">
Receipt No :
@@ -77,7 +78,8 @@
%>
<div class="card orders <%= sale_status %>">
<div class="card-block">
<p class="hidden orders-id"><%= unique_id %></p>
<p class="hidden orders-id"><%= unique_id %></p>
<p class="hidden customer-id"><%= rmo.customer_id %></p>
<h4 class="card-title orders-table"><%= rmo.room_name %></h4>
<p class="card-text">
Receipt No :
@@ -118,7 +120,8 @@
%>
<div class="card orders <%= sale_status %>">
<div class="card-block">
<p class="hidden orders-id"><%= unique_id %></p>
<p class="hidden orders-id"><%= unique_id %></p>
<p class="hidden customer-id"><%= odr.customer_id %></p>
<h4 class="card-title orders-table"><%= odr.table_name %></h4>
<p class="card-text">
Receipt No :
@@ -162,6 +165,15 @@
<p>Date: <span id="receipt_date"></span></p>
</div>
</div>
<div class="card-title row customer_detail hide">
<div class="col-lg-6 col-md-6 col-sm-6">
<p>Customer : <span id="customer_name"></span></p>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 text-right">
<p>Amount : <span id="customer_amount"></span></p>
</div>
</div>
<div class="card-text">
<table class="table table-striped" id="order-items-table">
<thead>
@@ -215,7 +227,7 @@
<button type="button" class="btn btn-primary btn-lg btn-block" disabled>Edit</button>
<button type="button" class="btn btn-primary btn-lg btn-block" disabled>Move</button>
<button type="button" class="btn btn-primary btn-lg btn-block" disabled>Customer</button>
<button type="button" id="customer"class="btn btn-primary btn-lg btn-block" disabled>Customer</button>
<button type="button" id="request_bills" class="btn btn-primary btn-lg btn-block">Req.Bill</button>
<!-- Cashier Buttons -->
<button type="button" id="discount" class="btn btn-primary btn-lg btn-block">Discount</button>

View File

@@ -74,7 +74,7 @@ Rails.application.routes.draw do
root "home#index"
get "/:booking_id" => "home#show" do #origami/:booking_id will show
resources :discounts, only: [:index,:new, :create ] #add discount type
resources :customers, only: [:index,:new, :create ] #add customer type
resources :customers #add customer type
end
get "/request_bills/:id" => "request_bills#print"
@@ -88,6 +88,12 @@ Rails.application.routes.draw do
get 'sale/:sale_id/payment/credit_payment' => "credit_payments#index"
get 'sale/:sale_id/payment/others_payment' => "others_payments#index"
#---------Add Customer --------------#
#resources :customers
get '/:sale_id/add_customer', to: "customers#add_customer"
get '/:customer_id/get_customer' => 'home#get_customer'
post '/:sale_id/update_sale' , to: "home#update_sale_by_customer"#update customer id in sale table
end
#--------- Waiter/Ordering Station ------------#
@@ -102,9 +108,7 @@ Rails.application.routes.draw do
root "home#index"
resources :customers
resources :dining_queues
get 'customers/:sale_id/assign_sale_id', to: "customers#get_sale_id", :as => "assign_sale"#get sale id with customer for crm
post "update_booking" , to: "bookings#update_booking", as: "update_booking"#assign and cancel
post "update_sale" , to: "home#update_sale_by_customer"#update customer id in sale table
get '/print/:id', to: "home#print_order"#print order for crm
end
@@ -156,6 +160,8 @@ Rails.application.routes.draw do
resources :tax_profiles
#lookups
resources :lookups
#orders
resources :orders
#cashier_terminals
resources :cashier_terminals
#order_job_stations