Class: CustomersController
Instance Method Summary
collapse
#preferences_customer_type=, #preferences_customer_type?, #signed_in?, #signed_in_user, #store_location
Instance Method Details
#create ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'app/controllers/customers_controller.rb', line 47
def create
if (params[:customer]==nil)
return
end
@customer = Customer.new(params[:customer])
@person = CustomerPj.new(params[:customer_pj])
@customer.person = @person
update_advanced_fields
if @customer.save
flash[:success] = t("helpers.forms.new_sucess")
redirect_to customer_path(@customer)
else
authorize! :new, @customer, 'new.'+preferences_customer_type?.to_s
render 'new.'+preferences_customer_type?.to_s
end
end
|
#custom_load_creator ⇒ Object
109
110
111
112
|
# File 'app/controllers/customers_controller.rb', line 109
def custom_load_creator
params[:customer_pj] = params[:customer][:customer_pj]
params[:customer].delete :customer_pj
end
|
#disable ⇒ Object
29
30
31
|
# File 'app/controllers/customers_controller.rb', line 29
def disable
end
|
#edit ⇒ Object
86
87
88
89
90
91
|
# File 'app/controllers/customers_controller.rb', line 86
def edit
@customer = Customer.find params[:id]
@person = @customer.person
@customer.emails.build
end
|
#filter_before_changes ⇒ Object
93
94
95
96
97
98
|
# File 'app/controllers/customers_controller.rb', line 93
def filter_before_changes
authorize! params[:action].to_sym, @customer
params[:customer][:doc].gsub! /[\.\/-]/, "" if params[:customer][:doc]
params[:customer][:doc_rg].gsub! /[\.\/-]/, "" if params[:customer][:doc_rg]
end
|
#index ⇒ Object
10
11
12
13
14
15
16
|
# File 'app/controllers/customers_controller.rb', line 10
def index
@sels = params["sels"] || []
@search = Customer.search(params[:search])
@customers = @search.paginate(page: params[:page], :per_page => 10)
params[:search] = {} if params[:search].nil?
end
|
#multiselect_business_activities ⇒ Object
105
106
107
|
# File 'app/controllers/customers_controller.rb', line 105
def multiselect_business_activities
render :json => BusinessActivity.where(["name ilike ?", "%"+params[:tag]+"%"] ).collect { |c| { :key => c.id.to_s, :value => c.name } }
end
|
#multiselect_business_segments ⇒ Object
101
102
103
|
# File 'app/controllers/customers_controller.rb', line 101
def multiselect_business_segments
render :json => BusinessSegment.where(["name ilike ?", "%"+params[:tag]+"%"] ).collect { |c| { :key => c.id.to_s, :value => c.name } }
end
|
#multiselect_customers_pj ⇒ Object
114
115
116
|
# File 'app/controllers/customers_controller.rb', line 114
def multiselect_customers_pj
render :json => CustomerPj.includes(:customer).where(["(customers.name ilike ? or customers.name_sec ilike ?)", params[:tag]+"%", params[:tag]+"%"] ).collect { |c| { :key => c.id.to_s, :value => c.customer.name } }
end
|
#new ⇒ Object
33
34
35
36
37
38
|
# File 'app/controllers/customers_controller.rb', line 33
def new
@person = CustomerPj.new
@customer.person = @person
@segments = BusinessSegment.all
render "new."+preferences_customer_type?.to_s
end
|
#show ⇒ Object
18
19
20
21
22
23
24
25
26
27
|
# File 'app/controllers/customers_controller.rb', line 18
def show
@task = @customer.tasks.build
@tasks = @customer.tasks.paginate(page:params[:task_page] || 1, per_page: 4)
@selected_department = params[:department]
@contacts = @customer.contacts
@contacts = Contact.search_by_params @contacts, department_id: @selected_department if @selected_department
render "show."+@customer.person.prefix
end
|
#update ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
# File 'app/controllers/customers_controller.rb', line 68
def update
params_pj = params[:customer][:customer_pj]
params[:customer].delete :customer_pj
@person = @customer.person
update_advanced_fields
if @person.save && @customer.update_attributes(params[:customer]) && @person.update_attributes(params_pj)
flash[:success] = t("helpers.forms.new_sucess")
redirect_to customer_path(@customer)
else
render 'new.'+preferences_customer_type?.to_s
end
end
|
#update_advanced_fields ⇒ Object
40
41
42
43
44
45
|
# File 'app/controllers/customers_controller.rb', line 40
def update_advanced_fields
@person.segments = params[:segments_select] ? params[:segments_select].collect { |bsid| BusinessSegment.find bsid }.uniq : []
@person.activities = params[:activities_select] ? params[:activities_select].collect { |baid| BusinessActivity.find baid }.uniq : []
@person.associateds = params[:associateds_select] ? params[:associateds_select].collect { |assoc| CustomerPj.find assoc }.uniq : []
end
|