Customer Update
This commit is contained in:
@@ -209,13 +209,7 @@ $(document).ready(function(){
|
|||||||
if(data["response_data"]["data"][i]["accountable_type"] == "RebateAccount"){
|
if(data["response_data"]["data"][i]["accountable_type"] == "RebateAccount"){
|
||||||
var balance = data["response_data"]["data"][i]["balance"];
|
var balance = data["response_data"]["data"][i]["balance"];
|
||||||
console.log(balance);
|
console.log(balance);
|
||||||
if (balance == "0.0") {
|
|
||||||
$("#customer_amount").text('0.0');
|
|
||||||
}else{
|
|
||||||
$("#customer_amount").text(balance);
|
$("#customer_amount").text(balance);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ class Crm::CustomersController < BaseCrmController
|
|||||||
# GET /crm/customers.json
|
# GET /crm/customers.json
|
||||||
def index
|
def index
|
||||||
filter = params[:filter]
|
filter = params[:filter]
|
||||||
|
|
||||||
if filter.nil?
|
if filter.nil?
|
||||||
@crm_customers = Customer.order("customer_id").page(params[:page])
|
@crm_customers = Customer.order("customer_id").page(params[:page])
|
||||||
#@products = Product.order("name").page(params[:page]).per(5)
|
#@products = Product.order("name").page(params[:page]).per(5)
|
||||||
@@ -31,7 +31,7 @@ class Crm::CustomersController < BaseCrmController
|
|||||||
# GET /crm/customers/1.json
|
# GET /crm/customers/1.json
|
||||||
def show
|
def show
|
||||||
@orders = Order.where("customer_id=?", params[:id])
|
@orders = Order.where("customer_id=?", params[:id])
|
||||||
|
|
||||||
if @orders
|
if @orders
|
||||||
@order_items = []
|
@order_items = []
|
||||||
@orders.each do |bo|
|
@orders.each do |bo|
|
||||||
@@ -57,6 +57,7 @@ class Crm::CustomersController < BaseCrmController
|
|||||||
def create
|
def create
|
||||||
|
|
||||||
@crm_customers = Customer.new(customer_params)
|
@crm_customers = Customer.new(customer_params)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
puts @crm_customers.errors.to_json
|
puts @crm_customers.errors.to_json
|
||||||
if @crm_customers.save
|
if @crm_customers.save
|
||||||
@@ -72,9 +73,7 @@ class Crm::CustomersController < BaseCrmController
|
|||||||
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
|
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
|
||||||
|
|
||||||
response = HTTParty.post(url, :body => { name: name,phone: phone,email: email,
|
response = HTTParty.post(url, :body => { name: name,phone: phone,email: email,
|
||||||
|
|
||||||
dob: dob,
|
dob: dob,
|
||||||
|
|
||||||
member_group_id: member_group_id,merchant_uid:merchant_uid}.to_json,
|
member_group_id: member_group_id,merchant_uid:merchant_uid}.to_json,
|
||||||
:headers => {
|
:headers => {
|
||||||
'Content-Type' => 'application/json',
|
'Content-Type' => 'application/json',
|
||||||
@@ -83,18 +82,18 @@ class Crm::CustomersController < BaseCrmController
|
|||||||
)
|
)
|
||||||
|
|
||||||
if response["status"] == true
|
if response["status"] == true
|
||||||
|
|
||||||
customer = Customer.find(@crm_customers.customer_id)
|
customer = Customer.find(@crm_customers.customer_id)
|
||||||
status = customer.update_attributes(membership_id: response["customer_datas"]["id"])
|
status = customer.update_attributes(membership_id: response["customer_datas"]["id"])
|
||||||
|
|
||||||
if params[:sale_id]
|
if params[:sale_id]
|
||||||
format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer', notice: 'Customer was successfully created.' }
|
format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer', notice: 'Customer was successfully created.' }
|
||||||
else
|
else
|
||||||
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created'}
|
format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created'}
|
||||||
end
|
end
|
||||||
# format.json { render :index, status: :created, location: @crm_customers }
|
# format.json { render :index, status: :created, location: @crm_customers }
|
||||||
else
|
else
|
||||||
|
|
||||||
@crm_customers.destroy
|
@crm_customers.destroy
|
||||||
if params[:sale_id]
|
if params[:sale_id]
|
||||||
format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'}
|
format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'}
|
||||||
@@ -105,9 +104,9 @@ class Crm::CustomersController < BaseCrmController
|
|||||||
else
|
else
|
||||||
|
|
||||||
if params[:sale_id]
|
if params[:sale_id]
|
||||||
format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'}
|
format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'}
|
||||||
else
|
else
|
||||||
|
flash[:errors] = @crm_customers.errors
|
||||||
format.html { redirect_to crm_customers_path}
|
format.html { redirect_to crm_customers_path}
|
||||||
format.json { render json: @crm_customers.errors, status: :unprocessable_entity }
|
format.json { render json: @crm_customers.errors, status: :unprocessable_entity }
|
||||||
end
|
end
|
||||||
@@ -134,7 +133,7 @@ end
|
|||||||
memberaction = MembershipAction.find_by_membership_type("update_membership_customer")
|
memberaction = MembershipAction.find_by_membership_type("update_membership_customer")
|
||||||
merchant_uid = memberaction.merchant_account_id.to_s
|
merchant_uid = memberaction.merchant_account_id.to_s
|
||||||
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
|
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
|
||||||
|
|
||||||
response = HTTParty.post(url, :body => { name: name,phone: phone,email: email,
|
response = HTTParty.post(url, :body => { name: name,phone: phone,email: email,
|
||||||
dob: dob,
|
dob: dob,
|
||||||
id: id,member_group_id:member_group_id,merchant_uid:merchant_uid}.to_json,
|
id: id,member_group_id:member_group_id,merchant_uid:merchant_uid}.to_json,
|
||||||
|
|||||||
@@ -67,6 +67,7 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-4">
|
<div class="col-lg-4">
|
||||||
|
|
||||||
<%= simple_form_for @crm_customer,:url => crm_customers_path, :method => :post do |f| %>
|
<%= simple_form_for @crm_customer,:url => crm_customers_path, :method => :post do |f| %>
|
||||||
|
|
||||||
<span class="patch_method"></span>
|
<span class="patch_method"></span>
|
||||||
@@ -74,16 +75,26 @@
|
|||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<%= f.input :name, :class => "form-control col-md-6 name" %>
|
<%= f.input :name, :class => "form-control col-md-6 name" %>
|
||||||
|
<% if flash[:errors] && !flash[:errors].empty? then -%>
|
||||||
|
<span style="color:red"><%= flash[:errors]["name"] %></span>
|
||||||
|
<% end -%>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<%= f.input :company, :class => "form-control col-md-6 company" %>
|
<%= f.input :company, :class => "form-control col-md-6 company" %>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<%= f.input :contact_no, :class => "form-control col-md-6 contact_no" %>
|
<%= f.input :contact_no, :class => "form-control col-md-6 contact_no" %>
|
||||||
|
<% if flash[:errors] && !flash[:errors].empty? then -%>
|
||||||
|
<span style="color:red"><%= flash[:errors]["contact_no"] %></span>
|
||||||
|
<% end -%>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<%= f.input :email, :class => "form-control col-md-6 email" %>
|
<%= f.input :email, :class => "form-control col-md-6 email" %>
|
||||||
|
<% if flash[:errors] && !flash[:errors].empty? then -%>
|
||||||
|
<span style="color:red"><%= flash[:errors]["email"] %></span>
|
||||||
|
<% end -%>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@@ -98,7 +109,10 @@
|
|||||||
<option value="<%= member.value %>">
|
<option value="<%= member.value %>">
|
||||||
<%= member.name %></option>
|
<%= member.name %></option>
|
||||||
<%end %>
|
<%end %>
|
||||||
</select>
|
</select>
|
||||||
|
<% if flash[:errors] && !flash[:errors].empty? then -%>
|
||||||
|
<span style="color:red"><%= flash[:errors]["member_group_id"] %></span>
|
||||||
|
<% end -%>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
@@ -119,13 +133,13 @@
|
|||||||
var sale_id = $("#sale_id").val() || 0;
|
var sale_id = $("#sale_id").val() || 0;
|
||||||
var customer_id = $(this).val();
|
var customer_id = $(this).val();
|
||||||
|
|
||||||
// if(sale_id != 0){
|
if(sale_id != 0){
|
||||||
// // var url = "/"+customer_id;
|
// var url = "/"+customer_id;
|
||||||
// update_sale(customer_id,sale_id);
|
update_sale(customer_id,sale_id);
|
||||||
// }else{
|
}else{
|
||||||
|
|
||||||
// var url = "customers/"+customer_id;
|
var url = "customers/"+customer_id;
|
||||||
// }
|
}
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "GET",
|
type: "GET",
|
||||||
@@ -161,43 +175,43 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// function update_sale(customer_id,sale_id) {
|
function update_sale(customer_id,sale_id) {
|
||||||
// $.confirm({
|
$.confirm({
|
||||||
// title: 'Confirm!',
|
title: 'Confirm!',
|
||||||
// content: 'Are You Sure to assign this customer!',
|
content: 'Are You Sure to assign this customer!',
|
||||||
// buttons: {
|
buttons: {
|
||||||
|
|
||||||
// cancel: function () {
|
cancel: function () {
|
||||||
|
|
||||||
// },
|
},
|
||||||
// confirm: {
|
confirm: {
|
||||||
// text: 'Confirm',
|
text: 'Confirm',
|
||||||
// btnClass: 'btn-green',
|
btnClass: 'btn-green',
|
||||||
// keys: ['enter', 'shift'],
|
keys: ['enter', 'shift'],
|
||||||
// action: function(){
|
action: function(){
|
||||||
// $.ajax({
|
$.ajax({
|
||||||
// type: "POST",
|
type: "POST",
|
||||||
// url: "update_sale/" ,
|
url: "update_sale/" ,
|
||||||
// data: {customer_id:customer_id,sale_id:sale_id},
|
data: {customer_id:customer_id,sale_id:sale_id},
|
||||||
// dataType: "json",
|
dataType: "json",
|
||||||
// success: function(data) {
|
success: function(data) {
|
||||||
// if(data.status == true)
|
if(data.status == true)
|
||||||
// {
|
{
|
||||||
// alert('Customer has assigned');
|
alert('Customer has assigned');
|
||||||
// window.location.href = '/origami'
|
window.location.href = '/origami'
|
||||||
// }else{
|
}else{
|
||||||
// alert('Record not found!');
|
alert('Record not found!');
|
||||||
// location.reload();
|
location.reload();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -78,17 +78,25 @@
|
|||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<%= f.input :name, :class => "form-control col-md-6 name" %>
|
<%= f.input :name, :class => "form-control col-md-6 name" %>
|
||||||
|
<% if flash[:errors] && !flash[:errors].empty? then -%>
|
||||||
|
<span style="color:red"><%= flash[:errors]["name"] %></span>
|
||||||
|
<% end -%>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<%= f.input :company, :class => "form-control col-md-6 company" %>
|
<%= f.input :company, :class => "form-control col-md-6 company" %>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<%= f.input :contact_no, :class => "form-control col-md-6 contact_no" %>
|
<%= f.input :contact_no, :class => "form-control col-md-6 contact_no" %>
|
||||||
|
<% if flash[:errors] && !flash[:errors].empty? then -%>
|
||||||
|
<span style="color:red"><%= flash[:errors]["contact_no"] %></span>
|
||||||
|
<% end -%>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<%= f.input :email, :class => "form-control col-md-6 email" %>
|
<%= f.input :email, :class => "form-control col-md-6 email" %>
|
||||||
|
<% if flash[:errors] && !flash[:errors].empty? then -%>
|
||||||
|
<span style="color:red"><%= flash[:errors]["email"] %></span>
|
||||||
|
<% end -%>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@@ -103,7 +111,11 @@
|
|||||||
<option value="<%= member.value %>">
|
<option value="<%= member.value %>">
|
||||||
<%= member.name %></option>
|
<%= member.name %></option>
|
||||||
<%end %>
|
<%end %>
|
||||||
</select>
|
</select>
|
||||||
|
<% if flash[:errors] && !flash[:errors].empty? then -%>
|
||||||
|
<span style="color:red"><%= flash[:errors]["member_group_id"] %></span>
|
||||||
|
<% end -%>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|||||||
Reference in New Issue
Block a user