educode_sales 0.7.7 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/educode_sales/application_controller.rb +24 -0
- data/app/controllers/educode_sales/assessments_controller.rb +151 -285
- data/app/controllers/educode_sales/businesses_controller.rb +68 -2
- data/app/controllers/educode_sales/customers_controller.rb +0 -3
- data/app/helpers/educode_sales/application_helper.rb +3 -3
- data/app/models/educode_sales/business.rb +8 -0
- data/app/models/educode_sales/business_relation_ship.rb +6 -0
- data/app/models/educode_sales/customer_follow.rb +1 -0
- data/app/models/educode_sales/filter.rb +18 -0
- data/app/models/educode_sales/follow_up.rb +2 -0
- data/app/models/educode_sales/role_area.rb +1 -1
- data/app/views/educode_sales/assessments/_progress.html.erb +7 -4
- data/app/views/educode_sales/assessments/_setup.html.erb +115 -13
- data/app/views/educode_sales/assessments/edit.html.erb +47 -54
- data/app/views/educode_sales/assessments/index.html.erb +1 -2
- data/app/views/educode_sales/assessments/index.json.jbuilder +1 -1
- data/app/views/educode_sales/assessments/new.html.erb +148 -111
- data/app/views/educode_sales/assessments/progress.json.jbuilder +2 -198
- data/app/views/educode_sales/businesses/following_businesses.jbuilder +44 -0
- data/app/views/educode_sales/businesses/index.html.erb +175 -27
- data/app/views/educode_sales/businesses/index.json.jbuilder +1 -0
- data/app/views/educode_sales/businesses/new_follow_record.html.erb +1 -1
- data/app/views/educode_sales/plans/edit_month.html.erb +1 -1
- data/app/views/layouts/educode_sales/application.html.erb +2 -2
- data/config/routes.rb +4 -0
- data/db/migrate/20220419103842_add_column_timestamps_to_assessments_settings.rb +9 -0
- data/db/migrate/20220420071909_create_educode_sales_business_relation_ships.rb +10 -0
- data/db/migrate/20220507020149_create_filter.rb +10 -0
- data/db/migrate/20220507091959_change_educode_sales_filter_column_length.rb +5 -0
- data/lib/educode_sales/version.rb +1 -1
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb565ace898040e094fd5bb5659ba71b471f4d3c6d718f5b0d52c8d0b3b78329
|
4
|
+
data.tar.gz: 5c235c5d885f53def688cf0cf1f6bbfb8a33de88de4811249f54fb69cab34665
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2471c1f71f7e9bd3a724a932462fec5eeac8a292d1e7c25938120fbbe25d1c2063d381aa4cca78d8eaa1519b2690b57b02b4e8f1392c28c387f7c4cfc13d9b2a
|
7
|
+
data.tar.gz: 7fe56251df0ff25212c1a3bbc5b9ce9f4c0f418d5e445e4b90eca2ff324ce12f9cd3f4fbfe3d712610dfb513531977713a7e23af5485944277c4b838539160d1
|
@@ -27,6 +27,30 @@ module EducodeSales
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
def filter
|
31
|
+
filter = Filter.find_or_create_by(staff_id: @current_admin.id, filter_type: params[:type])
|
32
|
+
params[:hidden] = params[:hidden] == "true" ? "0":"1"
|
33
|
+
a = ''
|
34
|
+
b = []
|
35
|
+
filter.filter_data&.split(",")&.each do |d|
|
36
|
+
b << d[0..-2]
|
37
|
+
if d[0..-2] == params[:name]
|
38
|
+
d[-1] = params[:hidden]
|
39
|
+
end
|
40
|
+
a = a + d + ','
|
41
|
+
end
|
42
|
+
if b.include?(params[:name]) == false
|
43
|
+
p "include"
|
44
|
+
a = a + params[:name] + params[:hidden]
|
45
|
+
p a
|
46
|
+
end
|
47
|
+
filter.filter_data = a
|
48
|
+
filter.save
|
49
|
+
render_success
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
|
30
54
|
rescue_from CanCan::AccessDenied do |exception|
|
31
55
|
redirect_to no_permission_path
|
32
56
|
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
require_dependency "educode_sales/application_controller"
|
2
2
|
|
3
|
-
|
4
3
|
module EducodeSales
|
5
4
|
class AssessmentsController < ApplicationController
|
5
|
+
before_action :progress_or_get_export_data, only: [:progress, :get_export_data]
|
6
|
+
|
7
|
+
|
6
8
|
def index
|
7
9
|
respond_to do |format|
|
8
10
|
format.html do
|
@@ -12,47 +14,54 @@ module EducodeSales
|
|
12
14
|
gon.export_menus = []
|
13
15
|
gon.export_menus << { title: '导出到Csv文件', event: 'export_csv' }
|
14
16
|
gon.export_menus << { title: '导出到Excel文件', event: 'export_excel' }
|
17
|
+
# index页面new弹出层下使用
|
18
|
+
gon.staff_ids = Staff.joins(:user).where(job_type: common.id).map do |d|
|
19
|
+
{value: d.id, name: d.user.real_name }
|
20
|
+
end
|
21
|
+
filter = Filter.find_or_create_by(staff_id: @current_admin.id, filter_type: "assessments_setup")
|
22
|
+
gon.filter = {}
|
23
|
+
filter.filter_data&.split(",")&.each do |d|
|
24
|
+
m = d[0..-2]
|
25
|
+
# gon.filter[:"#{m}"] = d[-1].to_i # 前端的hide注意时int类型 string类型 获取不到
|
26
|
+
gon.filter["#{m}"] = d[-1].to_i # 前端的hide注意时int类型 string类型 获取不到
|
27
|
+
end
|
28
|
+
# p gon.filter
|
29
|
+
# gon.filter2 = {:username => false }
|
30
|
+
# gon.filter3 = '1'
|
31
|
+
# p gon.filter
|
15
32
|
end
|
16
33
|
format.json do
|
17
|
-
|
18
|
-
p '--------------------------admin'
|
19
|
-
p @current_admin
|
20
|
-
p '----------------admin'
|
21
|
-
|
22
|
-
@assessments = AssessmentsSetting.all
|
23
34
|
@year = params[:q].present? && params[:q][:assessment_year].present? ? params[:q][:assessment_year]:'2022'
|
24
35
|
@assessments_id = params[:q].present? && params[:q][:assessment_id].present? ? params[:q][:assessment_id]: '1'
|
25
|
-
@assessments =
|
26
|
-
@assessments = @assessments.where(assessment: @assessments_id).order("
|
36
|
+
@assessments = AssessmentsSetting.where("assessment_year >= ? and assessment_year <= ?", "#{@year}-01-01 00:00:00".to_date, "#{@year}-12-31 23:59:00".to_date)
|
37
|
+
@assessments = @assessments.where(assessment: @assessments_id).order("updated_at desc")
|
27
38
|
if params[:q].present? && params[:q][:staff_id].present?
|
28
|
-
@assessments = @assessments.where(staff_id: params[:q][:staff_id]).order("
|
39
|
+
@assessments = @assessments.where(staff_id: params[:q][:staff_id]).order("updated_at desc")
|
29
40
|
end
|
30
|
-
# 对数据进行分页 默认为page=1 limit=10
|
31
|
-
# @assessments = @assessments.order("id desc").page(params[:page]).per(params[:limit])
|
32
41
|
end
|
33
42
|
end
|
34
43
|
end
|
35
44
|
|
36
|
-
|
37
|
-
|
38
45
|
# 新增
|
39
46
|
def create
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
47
|
+
begin
|
48
|
+
demo = AssessmentsSetting.new(params_create)
|
49
|
+
demo.user_id = current_user.user_id
|
50
|
+
demo.assessment_year = "#{params[:assessment_year]}-01-01"
|
51
|
+
AssessmentsSetting.transaction do
|
52
|
+
params[:staffs_ids].split(",").each do |d|
|
53
|
+
staff = demo.dup
|
54
|
+
staff.staff_id = d.to_i
|
55
|
+
staff.save
|
56
|
+
end
|
57
|
+
end
|
58
|
+
render_success
|
59
|
+
rescue OneError => e
|
60
|
+
render_failure '增加数据错误'
|
46
61
|
end
|
47
|
-
render_success
|
48
62
|
end
|
49
63
|
|
50
|
-
|
51
64
|
def new
|
52
|
-
common = Common.find_by(clazz: 'staff_type', name: '销售')
|
53
|
-
@staffs = Staff.joins(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id]} # [[], [], ............]
|
54
|
-
# do something
|
55
|
-
# @staffs = Staff.joins(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id]}
|
56
65
|
render layout: false
|
57
66
|
end
|
58
67
|
|
@@ -62,19 +71,19 @@ module EducodeSales
|
|
62
71
|
@username = @assessment.staff.user.real_name
|
63
72
|
@year = @assessment.assessment_year.to_s[0..3]
|
64
73
|
case @assessment.assessment
|
65
|
-
when
|
74
|
+
when 1
|
66
75
|
@assessment_name = "签单金额"
|
67
|
-
when
|
76
|
+
when 2
|
68
77
|
@assessment_name = "回款金额"
|
69
|
-
when
|
78
|
+
when 3
|
70
79
|
@assessment_name = "拜访量"
|
71
|
-
when
|
80
|
+
when 4
|
72
81
|
@assessment_name = "新增商机数"
|
73
82
|
end
|
74
83
|
render layout: false
|
75
84
|
end
|
76
85
|
|
77
|
-
#
|
86
|
+
# 根新
|
78
87
|
def update
|
79
88
|
@assessment = AssessmentsSetting.find_by(id: params[:id])
|
80
89
|
@assessment.update_attributes(params_update)
|
@@ -87,163 +96,94 @@ module EducodeSales
|
|
87
96
|
assessment = AssessmentsSetting.find(params[:id])
|
88
97
|
assessment.destroy
|
89
98
|
render_success
|
90
|
-
rescue
|
91
|
-
render_failure '
|
99
|
+
rescue OneError => e
|
100
|
+
render_failure '暂不能删除'
|
92
101
|
end
|
93
102
|
end
|
94
103
|
|
95
104
|
|
96
105
|
|
97
106
|
|
98
|
-
|
99
107
|
# 导出数据
|
100
108
|
def get_export_data
|
101
|
-
|
102
|
-
@staff_ids = Staff.joins(:user).where(job_type: common.id).pluck(:id)
|
103
|
-
@assessment_id = params[:assessment_id].present? ? params[:assessment_id]:'1'
|
104
|
-
@assessment_year = params[:assessment_year] ? params[:assessment_year] : '2022'
|
105
|
-
@assessments =AssessmentsSetting.where(assessment: @assessment_id).
|
106
|
-
where("assessment_year >= ? and assessment_year <= ?", "#{@assessment_year}-01-01 00:00:00".to_date, "#{@assessment_year}-12-31 23:59:00".to_date)
|
107
|
-
if params[:staff_id].present?
|
108
|
-
@assessment = @assessments.where(staff_id: params[:staff_id]).order("id desc").first
|
109
|
-
progress_main
|
110
|
-
else
|
111
|
-
# @assessments = @assessments.where(staff_id: @staff_ids) 注意 这样写有问题
|
112
|
-
@staff_ids.each do |s|
|
113
|
-
@assessment = @assessments.where(staff_id: s).order("id desc").first
|
114
|
-
progress_main
|
115
|
-
end
|
116
|
-
end
|
117
|
-
# 在从新获取一下 统计后的所有assessment_setting数据
|
118
|
-
@assessments = AssessmentsSetting.where(assessment: @assessment_id).
|
119
|
-
where("assessment_year >= ? and assessment_year <= ?", "#{@assessment_year}-01-01 00:00:00".to_date, "#{@assessment_year}-12-31 23:59:00".to_date)
|
120
|
-
@assessments = params[:staff_id].present? ? @assessments.where(staff_id: params[:staff_id]).order("id desc"):
|
121
|
-
@assessments.order("id desc")
|
109
|
+
p 'get_export_data'
|
122
110
|
end
|
123
111
|
|
124
112
|
|
125
113
|
|
126
|
-
|
127
|
-
|
128
|
-
|
114
|
+
# 考核完成情况
|
115
|
+
def progress
|
116
|
+
p 'progress'
|
129
117
|
end
|
130
118
|
|
131
119
|
|
132
120
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
# todo 可以增加一个字段(用户判断assessment_setting表中的某一数据是否在一定条件下为最新数据
|
137
|
-
# todo 在统计数据时 可以通过该字段 获取最新的数据 并统计 当比之前写的大大降低的代码的重复量 ,并且提高了数据库的性能)----注意 如果增加该字段后 在对某条数据进行操作时,要实施更新该条数据的该字段
|
138
|
-
|
139
|
-
# 考核完成情况
|
140
|
-
def progress
|
141
|
-
common = Common.find_by(clazz: 'staff_type', name: '销售')
|
142
|
-
@staff_ids = Staff.joins(:user).where(job_type: common.id).pluck(:id)
|
121
|
+
def progress_or_get_export_data
|
122
|
+
# common = Common.find_by(clazz: 'staff_type', name: '销售')
|
123
|
+
# @staff_ids = Staff.joins(:user).where(job_type: common.id).pluck(:id)
|
143
124
|
@assessment_id = params[:q].present? && params[:q][:assessment_id].present? ? params[:q][:assessment_id]:'1'
|
144
|
-
@assessment_year = params[:q].present? && params[:q][:assessment_year] ? params[:q][:assessment_year] :
|
145
|
-
@assessments =AssessmentsSetting.where(assessment: @assessment_id)
|
146
|
-
|
147
|
-
|
148
|
-
|
125
|
+
@assessment_year = params[:q].present? && params[:q][:assessment_year].present? ? params[:q][:assessment_year] : Time.now.year
|
126
|
+
@assessments =AssessmentsSetting.where(assessment: @assessment_id)
|
127
|
+
.where("assessment_year >= ? and assessment_year <= ?", "#{@assessment_year}-01-01 00:00:00".to_date, "#{@assessment_year}-12-31 23:59:00".to_date)
|
128
|
+
.order("created_at desc")
|
129
|
+
if @assessments.present?
|
130
|
+
# 小优化
|
131
|
+
@staff_ids = params[:q].present? && params[:q][:staff_id].present? ? [params[:q][:staff_id].to_i]:@assessments.distinct.pluck(:staff_id)
|
149
132
|
progress_main
|
150
|
-
|
151
|
-
|
152
|
-
@staff_ids.each do |s|
|
153
|
-
@assessment = @assessments.where(staff_id: s).order("id desc").first
|
154
|
-
progress_main
|
155
|
-
end
|
133
|
+
# 注意一下
|
134
|
+
@assessments = @assessments.where(staff_id: @staff_ids)
|
156
135
|
end
|
157
|
-
# 在从新获取一下 统计后的所有assessment_setting数据
|
158
|
-
@assessments = AssessmentsSetting.where(assessment: @assessment_id).
|
159
|
-
where("assessment_year >= ? and assessment_year <= ?", "#{@assessment_year}-01-01 00:00:00".to_date, "#{@assessment_year}-12-31 23:59:00".to_date)
|
160
|
-
@assessments = params[:q].present? && params[:q][:staff_id].present? ? @assessments.where(staff_id: params[:q][:staff_id]).order("id desc"):
|
161
|
-
@assessments.order("id desc")
|
162
|
-
|
163
136
|
end
|
164
137
|
|
165
138
|
|
166
|
-
|
167
|
-
|
168
139
|
# todo 主方法 统计用户的数据
|
169
140
|
def progress_main
|
170
|
-
if @assessment.present?
|
171
|
-
a = []
|
172
141
|
case @assessment_id
|
173
142
|
when '1' # 签单金额
|
174
143
|
busniness_jurisdiction
|
175
|
-
|
144
|
+
signed_count
|
176
145
|
when '2' # 回款金额
|
177
|
-
|
146
|
+
collection_count
|
178
147
|
when '3' # 拜访量
|
179
148
|
visits
|
180
|
-
|
181
|
-
@customers = @customers.where(id: school_ids)
|
182
|
-
busniness_visits(a) # 商机拜访量
|
183
|
-
customer_visits(a) # 客户拜访量
|
149
|
+
customer_and_busniness_visits
|
184
150
|
when '4' # 新增商机数
|
185
151
|
busniness_jurisdiction
|
186
|
-
busniness_add
|
152
|
+
busniness_add
|
187
153
|
end
|
188
|
-
update_assessments_progress(a)
|
189
|
-
else
|
190
|
-
# render layout:false
|
191
|
-
end
|
192
154
|
end
|
193
155
|
|
194
156
|
|
195
157
|
|
196
|
-
|
197
158
|
# 签单金额
|
198
|
-
def
|
159
|
+
def signed_count
|
199
160
|
# 过滤x类商机
|
200
|
-
ids = Common.where(extras: %w[
|
201
|
-
@businesses = @businesses.joins(
|
161
|
+
ids = Common.where.not(extras: %w[x_class]).pluck(:id)
|
162
|
+
@businesses = @businesses.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id in (?) ",ids)
|
163
|
+
.where("educode_sales_follow_ups.signed_date >= ? and educode_sales_follow_ups.signed_date <= ?",
|
164
|
+
"#{@assessment_year}-01-01 00:00:00".to_date, "#{@assessment_year}-12-31 23:59:59".to_date)
|
202
165
|
# 得到最新阶段为已签单商机
|
203
166
|
s_stage_ids = Common.where(clazz: '商机阶段', name: ['已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
|
204
167
|
@businesses = @businesses.joins("
|
205
168
|
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
206
169
|
").where("educode_sales_follow_ups.stage_id IN (?)",s_stage_ids)
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
when "#{@assessment_year}-01"
|
216
|
-
a[0] = a[0].to_i + @follow_ups.first.actual_amount.to_i
|
217
|
-
when "#{@assessment_year}-02"
|
218
|
-
a[1] = a[1].to_i + @follow_ups.first.actual_amount.to_i
|
219
|
-
when "#{@assessment_year}-03"
|
220
|
-
a[2] = a[2].to_i + @follow_ups.first.actual_amount.to_i
|
221
|
-
when "#{@assessment_year}-04"
|
222
|
-
a[3] = a[3].to_i + @follow_ups.first.actual_amount.to_i
|
223
|
-
when "#{@assessment_year}-05"
|
224
|
-
a[4] = a[4].to_i + @follow_ups.first.actual_amount.to_i
|
225
|
-
when "#{@assessment_year}-06"
|
226
|
-
a[5] = a[5].to_i + @follow_ups.first.actual_amount.to_i
|
227
|
-
when "#{@assessment_year}-07"
|
228
|
-
a[6] = a[6].to_i + @follow_ups.first.actual_amount.to_i
|
229
|
-
when "#{@assessment_year}-08"
|
230
|
-
a[7] = a[7].to_i + @follow_ups.first.actual_amount.to_i
|
231
|
-
when "#{@assessment_year}-09"
|
232
|
-
a[8] = a[8].to_i + @follow_ups.first.actual_amount.to_i
|
233
|
-
when "#{@assessment_year}-10"
|
234
|
-
a[9] = a[9].to_i + @follow_ups.first.actual_amount.to_i
|
235
|
-
when "#{@assessment_year}-11"
|
236
|
-
a[10] = a[10].to_i + @follow_ups.first.actual_amount.to_i
|
237
|
-
when "#{@assessment_year}-12"
|
238
|
-
a[11] = a[11].to_i + @follow_ups.first.actual_amount.to_i
|
170
|
+
@staff_ids.each do |d|
|
171
|
+
# 注意
|
172
|
+
businesses = @businesses.where(staff_id: d)
|
173
|
+
b = []
|
174
|
+
a=[]
|
175
|
+
FollowUp.joins("JOIN educode_sales_businesses ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id")
|
176
|
+
.where("educode_sales_businesses.id in (?)",businesses.pluck(:id)).each do |m|
|
177
|
+
b << {value: m.actual_amount.to_i, date:m.signed_date.to_s[5..6].to_i}
|
239
178
|
end
|
179
|
+
count_data(b,a) # 统计数据
|
180
|
+
update_assessments_progress(a,d) # 批量更新assessment数据 事物 一个commit
|
240
181
|
end
|
241
|
-
}
|
242
182
|
end
|
243
183
|
|
244
184
|
|
245
|
-
# 回款金额
|
246
|
-
def
|
185
|
+
# 回款金额 权限
|
186
|
+
def collection_count
|
247
187
|
follow_up_ids = Business.pluck(:last_follow_up_id)
|
248
188
|
if @current_admin.is_admin?
|
249
189
|
@money_plans = MoneyPlan.joins(:follow_up).where(follow_up_id: follow_up_ids)
|
@@ -262,39 +202,22 @@ module EducodeSales
|
|
262
202
|
@money_plans = MoneyPlan.joins(:follow_up).where(follow_up_id: follow_up_ids)
|
263
203
|
end
|
264
204
|
end
|
265
|
-
# todo 1 :实际回款 0:计划回款 where(clazz: 1 OR 实际回款 )
|
266
|
-
@money_plans = @money_plans.where(clazz: 1).where.not(date_at: nil
|
267
|
-
@
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
a[1] = a[1].to_i + d.amount.to_i
|
273
|
-
when "#{@assessment_year}-03"
|
274
|
-
a[2] = a[2].to_i + d.amount.to_i
|
275
|
-
when "#{@assessment_year}-04"
|
276
|
-
a[3] = a[3].to_i + d.amount.to_i
|
277
|
-
when "#{@assessment_year}-05"
|
278
|
-
a[4] = a[4].to_i + d.amount.to_i
|
279
|
-
when "#{@assessment_year}-06"
|
280
|
-
a[5] = a[5].to_i + d.amount.to_i
|
281
|
-
when "#{@assessment_year}-07"
|
282
|
-
a[6] = a[6].to_i + d.amount.to_i
|
283
|
-
when "#{@assessment_year}-08"
|
284
|
-
a[7] = a[7].to_i + d.amount.to_i
|
285
|
-
when "#{@assessment_year}-09"
|
286
|
-
a[8] = a[8].to_i + d.amount.to_i
|
287
|
-
when "#{@assessment_year}-10"
|
288
|
-
a[9] = a[9].to_i + d.amount.to_i
|
289
|
-
when "#{@assessment_year}-11"
|
290
|
-
a[10] = a[10].to_i + d.amount.to_i
|
291
|
-
when "#{@assessment_year}-12"
|
292
|
-
a[11] = a[11].to_i + d.amount.to_i
|
205
|
+
# todo 1 :实际回款 0:计划回款 where(clazz: 1 OR 实际回款 )
|
206
|
+
@money_plans = @money_plans.where(clazz: 1).where.not(date_at: nil)
|
207
|
+
@staff_ids.each do |d|
|
208
|
+
b = []
|
209
|
+
a = []
|
210
|
+
@money_plans.where(staff_id: d).each do |m|
|
211
|
+
b << {date:m.date_at.to_s[5..6].to_i, value:m.amount.to_i}
|
293
212
|
end
|
213
|
+
count_data(b,a)
|
214
|
+
update_assessments_progress(a, d)
|
294
215
|
end
|
295
216
|
end
|
296
217
|
|
297
|
-
|
218
|
+
|
219
|
+
|
220
|
+
# 权限获取拜访量
|
298
221
|
def visits
|
299
222
|
if @current_admin.is_admin?
|
300
223
|
@customers = School.all
|
@@ -319,121 +242,45 @@ module EducodeSales
|
|
319
242
|
@customers = @customers.where(id: ids)
|
320
243
|
end
|
321
244
|
|
322
|
-
# 客户拜访量
|
323
|
-
def customer_visits(a)
|
324
|
-
@customers.each do |d|
|
325
|
-
customer_follows = EducodeSales::CustomerFollow.where(school_id: d.id)
|
326
|
-
customer_follows.each do |f|
|
327
|
-
case f.created_at.to_time.to_s[0..6]
|
328
|
-
when "#{@assessment_year}-01"
|
329
|
-
a[0] = a[0].to_i + 1
|
330
|
-
when "#{@assessment_year}-02"
|
331
|
-
a[1] = a[1].to_i + 1
|
332
|
-
when "#{@assessment_year}-03"
|
333
|
-
a[2] = a[2].to_i + 1
|
334
|
-
when "#{@assessment_year}-04"
|
335
|
-
a[3] = a[3].to_i + 1
|
336
|
-
when "#{@assessment_year}-05"
|
337
|
-
a[4] = a[4].to_i + 1
|
338
|
-
when "#{@assessment_year}-06"
|
339
|
-
a[5] = a[5].to_i + 1
|
340
|
-
when "#{@assessment_year}-07"
|
341
|
-
a[6] = a[6].to_i + 1
|
342
|
-
when "#{@assessment_year}-08"
|
343
|
-
a[7] = a[7].to_i + 1
|
344
|
-
when "#{@assessment_year}-09"
|
345
|
-
a[8] = a[8].to_i + 1
|
346
|
-
when "#{@assessment_year}-10"
|
347
|
-
a[9] = a[9].to_i + 1
|
348
|
-
when "#{@assessment_year}-11"
|
349
|
-
a[10] = a[10].to_i + 1
|
350
|
-
when "#{@assessment_year}-12"
|
351
|
-
a[11] = a[11].to_i + 1
|
352
|
-
end
|
353
|
-
end
|
354
|
-
end
|
355
|
-
end
|
356
|
-
|
357
245
|
|
358
|
-
#
|
359
|
-
def
|
360
|
-
@
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
a[1] = a[1].to_i + 1
|
369
|
-
when "#{@assessment_year}-03"
|
370
|
-
a[2] = a[2].to_i + 1
|
371
|
-
when "#{@assessment_year}-04"
|
372
|
-
a[3] = a[3].to_i + 1
|
373
|
-
when "#{@assessment_year}-05"
|
374
|
-
a[4] = a[4].to_i + 1
|
375
|
-
when "#{@assessment_year}-06"
|
376
|
-
a[5] = a[5].to_i + 1
|
377
|
-
when "#{@assessment_year}-07"
|
378
|
-
a[6] = a[6].to_i + 1
|
379
|
-
when "#{@assessment_year}-08"
|
380
|
-
a[7] = a[7].to_i + 1
|
381
|
-
when "#{@assessment_year}-09"
|
382
|
-
a[8] = a[8].to_i + 1
|
383
|
-
when "#{@assessment_year}-10"
|
384
|
-
a[9] = a[9].to_i + 1
|
385
|
-
when "#{@assessment_year}-11"
|
386
|
-
a[10] = a[10].to_i + 1
|
387
|
-
when "#{@assessment_year}-12"
|
388
|
-
a[11] = a[11].to_i + 1
|
389
|
-
end
|
246
|
+
# 拜访量
|
247
|
+
def customer_and_busniness_visits
|
248
|
+
@staff_ids.each do |m|
|
249
|
+
customers = @customers.where(id: EducodeSales::CustomerExtension.where(customer_staff_id: m).pluck(:school_id))
|
250
|
+
b = []
|
251
|
+
a = []
|
252
|
+
CustomerFollow.joins(:school).where(school_id: customers.pluck(:id))
|
253
|
+
.where("Educode_Sales_customer_follows.created_at >= ? and Educode_Sales_customer_follows.created_at <= ?","#{@assessment_year}-01-01 ","#{@assessment_year}-12-31 23:59:59" )
|
254
|
+
.each do |d|
|
255
|
+
b << {value: 1, date: d.created_at.to_s[5..6].to_i}
|
390
256
|
end
|
257
|
+
FollowUp.joins(:business).where("Educode_Sales_businesses.id in (?)",EducodeSales::Business.where(school_id: customers.pluck(:id)).pluck(:id))
|
258
|
+
.where("Educode_Sales_follow_ups.created_at >= ? and Educode_Sales_follow_ups.created_at <= ?","#{@assessment_year}-01-01 00:00:00", "#{@assessment_year}-12-31 23:59:59").each do |d|
|
259
|
+
b << {date: d.created_at.to_s[5..6].to_i, value: 1}
|
260
|
+
end
|
261
|
+
count_data(b,a)
|
262
|
+
assessment = @assessments.where(staff_id: m)
|
263
|
+
update_assessments_progress(a, assessment)
|
391
264
|
end
|
392
|
-
|
393
|
-
# busniness_jurisdiction
|
394
|
-
# ids = Common.where(extras: %w[a_class b_class c_class d_claass e_class o_class x_class]).pluck(:id)
|
395
|
-
# @businesses = @businesses.joins("JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id").where("educode_sales_follow_ups.clazz_id in (?) ",ids)
|
396
|
-
# @businesses = @businesses.where("educode_sales_businesses.follow_ups_count > ?",'0').where(staff_id: @staff_id)
|
265
|
+
end
|
397
266
|
|
398
267
|
|
399
268
|
|
400
269
|
|
401
270
|
# 新增商机数
|
402
|
-
def busniness_add
|
403
|
-
|
404
|
-
|
405
|
-
# 2.销售人员新增的商机数量,过滤E、O、X类商机,包含:ABCD类商机; 上面有连接follow_up表
|
406
|
-
ids = Common.where(extras: %w[a_class b_class c_class d_claass]).pluck(:id) # 数组[1,5,2,15]
|
271
|
+
def busniness_add
|
272
|
+
@businesses = @businesses.where("educode_sales_businesses.created_at >= ? and educode_sales_businesses.created_at <= ?", "#{@assessment_year}-01-01 00:00:00","#{@assessment_year}-12-31 23:59:59")
|
273
|
+
ids = Common.where(extras: %w[a_class b_class c_class d_class]).pluck(:id)
|
407
274
|
@businesses = @businesses.joins("JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id").where("educode_sales_follow_ups.clazz_id in (?) ",ids)
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
when "#{@assessment_year}-02"
|
415
|
-
a[1] = a[1].to_i + 1
|
416
|
-
when "#{@assessment_year}-03"
|
417
|
-
a[2] = a[2].to_i + 1
|
418
|
-
when "#{@assessment_year}-04"
|
419
|
-
a[3] = a[3].to_i + 1
|
420
|
-
when "#{@assessment_year}-05"
|
421
|
-
a[4] = a[4].to_i + 1
|
422
|
-
when "#{@assessment_year}-06"
|
423
|
-
a[5] = a[5].to_i + 1
|
424
|
-
when "#{@assessment_year}-07"
|
425
|
-
a[6] = a[6].to_i + 1
|
426
|
-
when "#{@assessment_year}-08"
|
427
|
-
a[7] = a[7].to_i + 1
|
428
|
-
when "#{@assessment_year}-09"
|
429
|
-
a[8] = a[8].to_i + 1
|
430
|
-
when "#{@assessment_year}-10"
|
431
|
-
a[9] = a[9].to_i + 1
|
432
|
-
when "#{@assessment_year}-11"
|
433
|
-
a[10] = a[10].to_i + 1
|
434
|
-
when "#{@assessment_year}-12"
|
435
|
-
a[11] = a[11].to_i + 1
|
275
|
+
@staff_ids.each do |d|
|
276
|
+
businesses = @businesses.where(staff_id: d)
|
277
|
+
b = []
|
278
|
+
a = []
|
279
|
+
businesses.each do |m|
|
280
|
+
b << {date: m.created_at.to_s[5..6].to_i, value: 1}
|
436
281
|
end
|
282
|
+
count_data(b,a) # 统计数据
|
283
|
+
update_assessments_progress(a, d) # 批量更新assessment数据 事物 一个commit
|
437
284
|
end
|
438
285
|
end
|
439
286
|
|
@@ -442,7 +289,7 @@ module EducodeSales
|
|
442
289
|
def busniness_jurisdiction
|
443
290
|
# busniness 权限
|
444
291
|
if @current_admin.is_admin?
|
445
|
-
@businesses = Business
|
292
|
+
@businesses = Business.all
|
446
293
|
else
|
447
294
|
level = @current_admin.role.role_areas.find_by(clazz: '商机管理').level
|
448
295
|
case level
|
@@ -455,29 +302,48 @@ module EducodeSales
|
|
455
302
|
business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
|
456
303
|
@businesses = Business.joins("JOIN departments ON educode_sales_businesses.department_id = departments.id").where("departments.school_id in (?) OR educode_sales_businesses.staff_id = #{@current_admin.id} OR educode_sales_businesses.id in (?)", school_ids, business_ids)
|
457
304
|
else
|
458
|
-
@businesses = Business
|
305
|
+
@businesses = Business.all
|
459
306
|
end
|
460
307
|
end
|
461
308
|
end
|
462
309
|
|
310
|
+
|
463
311
|
# 更新assessments_settings表中数据
|
464
|
-
def update_assessments_progress(a)
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
312
|
+
def update_assessments_progress(a,staff_id)
|
313
|
+
a[12] = a[0].to_i + a[1].to_i + a[2].to_i
|
314
|
+
a[13] = a[3].to_i + a[4].to_i + a[5].to_i
|
315
|
+
a[14] = a[6].to_i + a[7].to_i + a[8].to_i
|
316
|
+
a[15] = a[9].to_i + a[10].to_i + a[11].to_i
|
317
|
+
a[16] = a[12].to_i + a[13].to_i + a[14].to_i + a[15].to_i
|
318
|
+
# 开启事物 处理 批量修改数据
|
319
|
+
assessments = @assessments.where(staff_id: staff_id)
|
320
|
+
assessments.update(annual_progress: a[16], first_quarter_progress: a[12], second_quarter_progress: a[13], third_quarter_progress: a[14], fourth_quarter_progress: a[15],
|
321
|
+
january_progress: a[0], february_progress: a[1], march_progress: a[2], april_progress: a[3], may_progress: a[4], june_progress: a[5],
|
322
|
+
july_progress: a[6], august_progress: a[7], september_progress: a[8], october_progress: a[9], november_progress: a[10], december_progress: a[11])
|
323
|
+
|
324
|
+
end
|
325
|
+
|
326
|
+
# 将统计到的数据转入a中
|
327
|
+
def count_data(arry,a)
|
328
|
+
arry.each do |d|
|
329
|
+
if a[d[:date]-1].present?
|
330
|
+
a[d[:date]-1] = a[d[:date]-1] + d[:value]
|
331
|
+
else
|
332
|
+
a[d[:date]-1] = d[:value]
|
333
|
+
end
|
334
|
+
end
|
473
335
|
end
|
474
336
|
|
475
337
|
|
476
338
|
|
477
339
|
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
|
478
344
|
private
|
479
345
|
def params_create
|
480
|
-
params.permit(
|
346
|
+
params.permit( :annual, :assessment,:assessment_year, :first_quarter, :second_quarter, :third_quarter, :fourth_quarter,
|
481
347
|
:january, :february, :march, :april, :may, :june, :july, :august, :september, :october, :november, :december)
|
482
348
|
end
|
483
349
|
|