check customer contact no
This commit is contained in:
@@ -99,9 +99,11 @@ class Crm::CustomersController < BaseCrmController
|
||||
def create
|
||||
# Remove "" default first
|
||||
params[:customer][:tax_profiles].delete_at(0)
|
||||
@checked_contact = Customer.find_by_contact_no(customer_params[:contact_no])
|
||||
if @checked_contact.nil?
|
||||
respond_to do |format|
|
||||
@crm_customers = Customer.new(customer_params)
|
||||
|
||||
respond_to do |format|
|
||||
if @crm_customers.save
|
||||
# update tax profile
|
||||
customer = Customer.find(@crm_customers.customer_id)
|
||||
@@ -206,7 +208,6 @@ class Crm::CustomersController < BaseCrmController
|
||||
end
|
||||
end
|
||||
else
|
||||
|
||||
if params[:sale_id]
|
||||
flash[:errors] = @crm_customers.errors
|
||||
format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page]}
|
||||
@@ -217,14 +218,30 @@ class Crm::CustomersController < BaseCrmController
|
||||
format.json { render json: @crm_customers.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
else
|
||||
flash[:errors] = {"contact_no":["has already been taken"]}
|
||||
respond_to do |format|
|
||||
if params[:sale_id]
|
||||
format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page]}
|
||||
else
|
||||
format.html { redirect_to crm_customers_path}
|
||||
end
|
||||
format.json { render json: @crm_customers.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end #end of contact no checked
|
||||
end
|
||||
# PATCH/PUT /crm/customers/1
|
||||
# PATCH/PUT /crm/customers/1.json
|
||||
def update
|
||||
# Remove "" default first
|
||||
params[:customer][:tax_profiles].delete_at(0)
|
||||
@checked_contact = nil
|
||||
@existed_contact = Customer.find_by_customer_id_and_contact_no(customer_params[:id], customer_params[:contact_no])
|
||||
if @existed_contact.nil?
|
||||
@checked_contact = Customer.find_by_contact_no(customer_params[:contact_no])
|
||||
end
|
||||
if !@existed_contact.nil? && @checked_contact.nil?
|
||||
respond_to do |format|
|
||||
if @crm_customer.update(customer_params)
|
||||
# update tax profile
|
||||
@@ -363,16 +380,24 @@ end
|
||||
end
|
||||
format.html { redirect_to crm_customers_path, notice: response["message"] }
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
flash[:errors] = @crm_customer.errors
|
||||
format.html { redirect_to crm_customers_path}
|
||||
format.json { render json: @crm_customer.errors, status: :unprocessable_entity }
|
||||
end
|
||||
|
||||
end
|
||||
else
|
||||
flash[:errors] = {"contact_no":["has already been taken"]}
|
||||
respond_to do |format|
|
||||
if params[:sale_id]
|
||||
format.html { redirect_to '/origami/'+params[:sale_id]+'/'+params[:type]+'/customers/'+params[:page]}
|
||||
else
|
||||
format.html { redirect_to crm_customers_path}
|
||||
end
|
||||
format.json { render json: @crm_customers.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ class Customer < ApplicationRecord
|
||||
has_many :sales
|
||||
|
||||
validates_presence_of :name, :contact_no, :email #,:card_no
|
||||
validates :contact_no, uniqueness: true, numericality: true
|
||||
validates :contact_no, numericality: true #uniqueness: true,
|
||||
validates :email, uniqueness: true,format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, on: :create }
|
||||
# validates :card_no, uniqueness: true
|
||||
# validates :paypar_account_no, uniqueness: true
|
||||
|
||||
Reference in New Issue
Block a user