educode_sales 0.7.4 → 0.7.5

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.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/educode_sales/assessment.png +0 -0
  3. data/app/controllers/educode_sales/assessments_controller.rb +490 -0
  4. data/app/controllers/educode_sales/businesses_controller.rb +2 -3
  5. data/app/controllers/educode_sales/customers_controller.rb +3 -0
  6. data/app/controllers/educode_sales/home_controller.rb +4 -3
  7. data/app/controllers/educode_sales/money_plans_controller.rb +2 -0
  8. data/app/controllers/educode_sales/plans_controller.rb +1 -0
  9. data/app/controllers/educode_sales/roles_controller.rb +4 -1
  10. data/app/controllers/educode_sales/sessions_controller.rb +2 -1
  11. data/app/helpers/educode_sales/application_helper.rb +61 -0
  12. data/app/helpers/educode_sales/assessments_help.rb +52 -0
  13. data/app/models/educode_sales/assessments_setting.rb +28 -0
  14. data/app/models/educode_sales/business.rb +2 -1
  15. data/app/models/educode_sales/follow_up.rb +1 -1
  16. data/app/models/educode_sales/money_plan.rb +1 -0
  17. data/app/models/educode_sales/permission.rb +2 -1
  18. data/app/models/educode_sales/role_area.rb +2 -1
  19. data/app/views/educode_sales/assessments/_progress.html.erb +433 -0
  20. data/app/views/educode_sales/assessments/_setup.html.erb +331 -0
  21. data/app/views/educode_sales/assessments/edit.html.erb +238 -0
  22. data/app/views/educode_sales/assessments/get_export_data.json.jbuilder +197 -0
  23. data/app/views/educode_sales/assessments/index.html.erb +63 -0
  24. data/app/views/educode_sales/assessments/index.json.jbuilder +26 -0
  25. data/app/views/educode_sales/assessments/new.html.erb +310 -0
  26. data/app/views/educode_sales/assessments/progress.json.jbuilder +372 -0
  27. data/app/views/educode_sales/businesses/index.html.erb +1 -1
  28. data/app/views/educode_sales/businesses/new_follow_record.html.erb +8 -8
  29. data/app/views/educode_sales/places/index.html.erb +5 -3
  30. data/app/views/educode_sales/plans/_monthPlan.html.erb +3 -1
  31. data/app/views/educode_sales/plans/new_month.html.erb +2 -0
  32. data/app/views/educode_sales/plans/new_week.html.erb +5 -1
  33. data/app/views/educode_sales/roles/edit.html.erb +26 -18
  34. data/app/views/educode_sales/sale_reports/index.json.jbuilder +1 -0
  35. data/app/views/layouts/educode_sales/application.html.erb +12 -12
  36. data/app/views/layouts/educode_sales/login.html.erb +1 -1
  37. data/config/routes.rb +11 -0
  38. data/db/migrate/20210902064109_create_educode_sales_role_permissions.rb +9 -1
  39. data/db/migrate/20220402020233_create_educode_sales_assessments_settings.rb +27 -0
  40. data/db/migrate/20220411021641_add_new_column_assessments_settings.rb +20 -0
  41. data/db/migrate/20220413090940_add_september_progress_to_assessment_settings.rb +5 -0
  42. data/lib/educode_sales/version.rb +1 -1
  43. metadata +17 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e481393e6e2fb7a42757e804b0e2be3381abad943a7e860c403fe12c655571c1
4
- data.tar.gz: dad674b1735e1cf66839f0757bc5dba844b15135339ce8fcc92ca71dc894143c
3
+ metadata.gz: 3d682317c15b09667c1c6c61d293b8d2c03e8c2af55cd08502e135eaab348a88
4
+ data.tar.gz: 5b577be152af9d51e88abe6e22b2e638b1c376322da24ac615aca52695793466
5
5
  SHA512:
6
- metadata.gz: a6d11197cb72adbfc6e98c448c38a706273fb1c5a4d5ff27c0c153bf056e01dbc4ec6051ead65b27a9796233beac8f475969a68b9921a344a64ddbbce661a481
7
- data.tar.gz: 7e630350f05c53575453206d8a6df23601911dc982d517517fc313af9d8d1831f5f22f39c6e2058e5891c3f9adc4304cbb3bb2abc15e2bdb6281cc3c93c2e2c1
6
+ metadata.gz: c07c678f2c6303fcfe4f20990e0c247846da3af1b3d54fb636c0da49cf59ad343987b6c6bfd099851ea5509f3e65981b71e50dda4ae7da05953fdbeefea58c78
7
+ data.tar.gz: ce2c311b7965b947e07089ec32883c036ab04e92e2bb96953e7818b80ac8c6f32a6f96e17284d21466d2cfce3666c141b3c7624c821299d7fae564fee819aaf2
@@ -0,0 +1,490 @@
1
+ require_dependency "educode_sales/application_controller"
2
+
3
+
4
+ module EducodeSales
5
+ class AssessmentsController < ApplicationController
6
+ def index
7
+ respond_to do |format|
8
+ format.html do
9
+ common = Common.find_by(clazz: 'staff_type', name: '销售')
10
+ @staffs = Staff.joins(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id]} # [[], [], ............]
11
+ # 导出
12
+ gon.export_menus = []
13
+ gon.export_menus << { title: '导出到Csv文件', event: 'export_csv' }
14
+ gon.export_menus << { title: '导出到Excel文件', event: 'export_excel' }
15
+ end
16
+ format.json do
17
+
18
+ p '--------------------------admin'
19
+ p @current_admin
20
+ p '----------------admin'
21
+
22
+ @assessments = AssessmentsSetting.all
23
+ @year = params[:q].present? && params[:q][:assessment_year].present? ? params[:q][:assessment_year]:'2022'
24
+ @assessments_id = params[:q].present? && params[:q][:assessment_id].present? ? params[:q][:assessment_id]: '1'
25
+ @assessments = @assessments.where("assessment_year >= ? and assessment_year <= ?", "#{@year}-01-01 00:00:00".to_date, "#{@year}-12-31 23:59:00".to_date)
26
+ @assessments = @assessments.where(assessment: @assessments_id).order("id desc")
27
+ if params[:q].present? && params[:q][:staff_id].present?
28
+ @assessments = @assessments.where(staff_id: params[:q][:staff_id]).order("id desc")
29
+ end
30
+ # 对数据进行分页 默认为page=1 limit=10
31
+ # @assessments = @assessments.order("id desc").page(params[:page]).per(params[:limit])
32
+ end
33
+ end
34
+ end
35
+
36
+
37
+
38
+ # 新增
39
+ def create
40
+ ActiveRecord::Base.transaction do
41
+ demo = AssessmentsSetting.new(params_create)
42
+ demo.user_id = current_user.user_id
43
+ demo.assessment_year = "#{params[:assessment_year]}-01-01"
44
+ demo.save
45
+ p demo.assessment_year,'ok'
46
+ end
47
+ render_success
48
+ end
49
+
50
+
51
+ 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
+ render layout: false
57
+ end
58
+
59
+ #编辑
60
+ def edit
61
+ @assessment = AssessmentsSetting.find_by(id: params[:id])
62
+ @username = @assessment.staff.user.real_name
63
+ @year = @assessment.assessment_year.to_s[0..3]
64
+ case @assessment.assessment
65
+ when "1"
66
+ @assessment_name = "签单金额"
67
+ when "2"
68
+ @assessment_name = "回款金额"
69
+ when "3"
70
+ @assessment_name = "拜访量"
71
+ when "4"
72
+ @assessment_name = "新增商机数"
73
+ end
74
+ render layout: false
75
+ end
76
+
77
+ # 根新数据
78
+ def update
79
+ @assessment = AssessmentsSetting.find_by(id: params[:id])
80
+ @assessment.update_attributes(params_update)
81
+ render_success
82
+ end
83
+
84
+ # 删除接口
85
+ def destroy
86
+ begin
87
+ assessment = AssessmentsSetting.find(params[:id])
88
+ assessment.destroy
89
+ render_success
90
+ rescue ActiveRecord::DeleteRestrictionError => e
91
+ render_failure '渠道下已有关联数据产生,暂不能删除'
92
+ end
93
+ end
94
+
95
+
96
+
97
+
98
+
99
+ # 导出数据
100
+ def get_export_data
101
+ common = Common.find_by(clazz: 'staff_type', name: '销售')
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")
122
+ end
123
+
124
+
125
+
126
+
127
+ # 增加导出记录
128
+ def add_export_records
129
+ end
130
+
131
+
132
+
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)
143
+ @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] : '2022'
145
+ @assessments =AssessmentsSetting.where(assessment: @assessment_id).
146
+ where("assessment_year >= ? and assessment_year <= ?", "#{@assessment_year}-01-01 00:00:00".to_date, "#{@assessment_year}-12-31 23:59:00".to_date)
147
+ if params[:q].present? && params[:q][:staff_id].present?
148
+ @assessment = @assessments.where(staff_id: params[:q][:staff_id]).order("id desc").first
149
+ progress_main
150
+ else
151
+ # @assessments = @assessments.where(staff_id: @staff_ids) 注意 这样写有问题
152
+ @staff_ids.each do |s|
153
+ @assessment = @assessments.where(staff_id: s).order("id desc").first
154
+ progress_main
155
+ end
156
+ 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
+ end
164
+
165
+
166
+
167
+
168
+ # todo 主方法 统计用户的数据
169
+ def progress_main
170
+ if @assessment.present?
171
+ a = []
172
+ case @assessment_id
173
+ when '1' # 签单金额
174
+ busniness_jurisdiction
175
+ signed_amount(a)
176
+ when '2' # 回款金额
177
+ collection_amount(a)
178
+ when '3' # 拜访量
179
+ visits
180
+ school_ids = EducodeSales::CustomerExtension.where(customer_staff_id: @staff_id).pluck(:school_id)
181
+ @customers = @customers.where(id: school_ids)
182
+ busniness_visits(a) # 商机拜访量
183
+ customer_visits(a) # 客户拜访量
184
+ when '4' # 新增商机数
185
+ busniness_jurisdiction
186
+ busniness_add(a)
187
+ end
188
+ update_assessments_progress(a)
189
+ else
190
+ # render layout:false
191
+ end
192
+ end
193
+
194
+
195
+
196
+
197
+ # 签单金额
198
+ def signed_amount(a)
199
+ # 过滤x类商机
200
+ ids = Common.where(extras: %w[a_class b_class c_class d_claass e_class o_class]).pluck(:id)
201
+ @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)
202
+ # 得到最新阶段为已签单商机
203
+ s_stage_ids = Common.where(clazz: '商机阶段', name: ['已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
204
+ @businesses = @businesses.joins("
205
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
206
+ ").where("educode_sales_follow_ups.stage_id IN (?)",s_stage_ids)
207
+ # 得到指定staff的商机------------先暂时指定
208
+ @businesses = @businesses.where(staff_id: @staff_id)
209
+ # 对businesses each操作并 获取最新根新记录
210
+ @businesses.each { |d| d
211
+ @follow_ups = d.follow_ups.where.not(signed_date: nil).order("signed_date desc")
212
+ if @follow_ups.first.present?
213
+ signed_date = @follow_ups.first.signed_date.to_time || '1000-01-01 00:00:00'.to_time
214
+ case signed_date.to_s[0..6]
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
239
+ end
240
+ end
241
+ }
242
+ end
243
+
244
+
245
+ # 回款金额
246
+ def collection_amount(a)
247
+ follow_up_ids = Business.pluck(:last_follow_up_id)
248
+ if @current_admin.is_admin?
249
+ @money_plans = MoneyPlan.joins(:follow_up).where(follow_up_id: follow_up_ids)
250
+ else
251
+ level = @current_admin.role.role_areas.find_by(clazz: '回款管理').level
252
+ case level
253
+ when '自己'
254
+ @money_plans = MoneyPlan.joins(:follow_up).where(follow_up_id: follow_up_ids).where(staff_id: @current_admin.id)
255
+ when '区域'
256
+ a_ids = MoneyPlan.where(follow_up_id: follow_up_ids).where(staff_id: @current_admin.id).pluck(:follow_up_id)
257
+ school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id) + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
258
+ b_ids = Business.where(school_id: school_ids).pluck(:last_follow_up_id)
259
+ ids = a_ids + b_ids
260
+ @money_plans = MoneyPlan.joins(:follow_up).where(follow_up_id: ids)
261
+ else
262
+ @money_plans = MoneyPlan.joins(:follow_up).where(follow_up_id: follow_up_ids)
263
+ end
264
+ end
265
+ # todo 1 :实际回款 0:计划回款 where(clazz: 1 OR 实际回款 ) 先把staff写死
266
+ @money_plans = @money_plans.where(clazz: 1).where.not(date_at: nil ).where(staff_id: @staff_id)
267
+ @money_plans.each do |d|
268
+ case d.date_at.to_s[0..6]
269
+ when "#{@assessment_year}-01"
270
+ a[0] = a[0].to_i + d.amount.to_i
271
+ when "#{@assessment_year}-02"
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
293
+ end
294
+ end
295
+ end
296
+
297
+ # 拜访量
298
+ def visits
299
+ if @current_admin.is_admin?
300
+ @customers = School.all
301
+ else
302
+ level = @current_admin.role.role_areas.find_by(clazz: '客户管理').level
303
+ case level
304
+ when '自己'
305
+ school_ids = CustomerExtension.where(customer_staff_id: @current_admin.id).pluck(:school_id)
306
+ @customers = School.where(id: school_ids)
307
+ when '区域'
308
+ a_school_ids = School.where(province: @current_admin.areas.pluck(:name)).ids
309
+ b_school_ids = CustomerExtension.where(customer_staff_id: @current_admin.id).pluck(:school_id)
310
+ school_ids = a_school_ids + b_school_ids + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
311
+ @customers = School.where(id: school_ids)
312
+ else
313
+ @customers = School.all
314
+ end
315
+ end
316
+ part_a_ids = CustomerFollow.all.pluck(:school_id)
317
+ part_b_ids = Business.where(id: EducodeSales::FollowUp.pluck(:business_id)).pluck(:school_id)
318
+ ids = part_a_ids + part_b_ids + CustomerAdd.all.pluck(:school_id)
319
+ @customers = @customers.where(id: ids)
320
+ end
321
+
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
+
358
+ # 商机拜访量
359
+ def busniness_visits(a)
360
+ @customers.each do |d|
361
+ business_ids = EducodeSales::Business.where(school_id: d.id).ids
362
+ follow_ups = EducodeSales::FollowUp.where(business_id: business_ids)
363
+ follow_ups.each do |f|
364
+ case f.created_at.to_time.to_s[0..6]
365
+ when "#{@assessment_year}-01"
366
+ a[0] = a[0].to_i + 1
367
+ when "#{@assessment_year}-02"
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
390
+ end
391
+ end
392
+ end
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)
397
+
398
+
399
+
400
+
401
+ # 新增商机数
402
+ def busniness_add(a)
403
+ # 1.新增商机数统计在哪一个时间段?以商机的创建时间为准;先默认 过滤2022之前的 businesses -created_et deleted_at follow_ups_count
404
+ @businesses = @businesses.where("follow_ups_count > ?", '0').where("educode_sales_businesses.created_at >= ? and educode_sales_businesses.created_at <= ?", "#{@assessment_year}-01-01 00:00:00".to_date,"#{@assessment_year}-12-31 23:59:00".to_date)
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]
407
+ @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
+ # 先把staff写死
409
+ @businesses = @businesses.where(staff_id: @staff_id)
410
+ @businesses.each do |d|
411
+ case d.created_at.to_time.to_s[0..6]
412
+ when "#{@assessment_year}-01"
413
+ a[0] = a[0].to_i + 1
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
436
+ end
437
+ end
438
+ end
439
+
440
+
441
+ # busniness 权限
442
+ def busniness_jurisdiction
443
+ # busniness 权限
444
+ if @current_admin.is_admin?
445
+ @businesses = Business
446
+ else
447
+ level = @current_admin.role.role_areas.find_by(clazz: '商机管理').level
448
+ case level
449
+ when '自己'
450
+ # Business.joins(Business字段: :表的名称)----> Business表(belongs_to) Business字段关联的表(has_many) Business字段关联的表在关联的表(belongs_to)
451
+ business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
452
+ @businesses = Business.where("educode_sales_businesses.staff_id = ? OR educode_sales_businesses.id in (?)", @current_admin.id, business_ids)
453
+ when '区域'
454
+ school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id) + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
455
+ business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
456
+ @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
+ else
458
+ @businesses = Business
459
+ end
460
+ end
461
+ end
462
+
463
+ # 更新assessments_settings表中数据
464
+ def update_assessments_progress(a)
465
+ a[12] = a[0].to_i + a[1].to_i + a[2].to_i
466
+ a[13] = a[3].to_i + a[4].to_i + a[5].to_i
467
+ a[14] = a[6].to_i + a[7].to_i + a[8].to_i
468
+ a[15] = a[9].to_i + a[10].to_i + a[11].to_i
469
+ a[16] = a[12].to_i + a[13].to_i + a[14].to_i + a[15].to_i
470
+ @assessment.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],
471
+ january_progress: a[0], february_progress: a[1], march_progress: a[2], april_progress: a[3], may_progress: a[4], june_progress: a[5],
472
+ july_progress: a[6], august_progress: a[7], september_progress: a[8], october_progress: a[9], november_progress: a[10], december_progress: a[11])
473
+ end
474
+
475
+
476
+
477
+
478
+ private
479
+ def params_create
480
+ params.permit(:staff_id, :annual, :assessment,:assessment_year, :first_quarter, :second_quarter, :third_quarter, :fourth_quarter,
481
+ :january, :february, :march, :april, :may, :june, :july, :august, :september, :october, :november, :december)
482
+ end
483
+
484
+ def params_update
485
+ params.permit( :annual, :first_quarter, :second_quarter, :third_quarter, :fourth_quarter,
486
+ :january, :february, :march, :april, :may, :june, :july, :august, :september, :october, :november, :december)
487
+ end
488
+
489
+ end
490
+ end
@@ -9,7 +9,7 @@ module EducodeSales
9
9
  respond_to do |format|
10
10
  format.html do
11
11
  common = Common.find_by(clazz: 'staff_type', name: '销售')
12
- @staffs = Staff.joins(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id]}
12
+ @staffs = Staff.joins(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id]} # [[], [], ............]
13
13
  # @more = can?(:create, EducodeSales::SalePlan) || can?(:update, EducodeSales::Business) || can?(:destroy, EducodeSales::Business) || can?(:show_file, EducodeSales::Business)
14
14
  @more = true
15
15
  gon.menus = []
@@ -59,7 +59,6 @@ module EducodeSales
59
59
  @businesses = Business
60
60
  end
61
61
  end
62
-
63
62
  if params[:q].present? && params[:q][:name].present?
64
63
  @year = params[:q][:name].split("-")[1].present? ? params[:q][:name].split("-")[1] : ''
65
64
  end
@@ -208,7 +207,7 @@ module EducodeSales
208
207
  end
209
208
 
210
209
  @business_count = @businesses.count
211
-
210
+ # mysql -select
212
211
  @businesses = @businesses.select("
213
212
  educode_sales_businesses.*,
214
213
  last_follow.invitation_at,
@@ -68,6 +68,9 @@ module EducodeSales
68
68
  @customers = @customers.where("schools.province = ?", "#{params[:q][:area]}")
69
69
  end
70
70
  if params[:q].present? && params[:q][:staff_id].present?
71
+ p "--------------------------------------------------------------------------------------"
72
+ p params[:q][:staff_id]
73
+ p "--------------------------------------------------------------------------------------"
71
74
  school_ids = EducodeSales::CustomerExtension.where(customer_staff_id: params[:q][:staff_id]).pluck(:school_id)
72
75
  @customers = @customers.where(id: school_ids)
73
76
  end
@@ -16,14 +16,15 @@ module EducodeSales
16
16
  end
17
17
 
18
18
  def search
19
+
19
20
  if params[:type] == 'department'
20
21
 
21
- @data = Department.joins(:school).where("schools.name like :q", q: "%#{params[:q]}%").limit(50)
22
+ @data = Department.joins(:school).where("schools.name like :q", q: "%#{params[:q]}%").limit(1000)
22
23
  unless @data.present?
23
- @data = Department.where("name like ?", "%#{params[:q]}%").limit(50)
24
+ @data = Department.where("name like ?", "%#{params[:q]}%").limit(1000)
24
25
  end
25
26
  elsif params[:type] == "school"
26
- data = School.where("name like ? ", "%#{params[:q]}%").limit(50)
27
+ data = School.where("name like ? ", "%#{params[:q]}%").limit(1000)
27
28
  end
28
29
  end
29
30
 
@@ -13,6 +13,8 @@ module EducodeSales
13
13
  end
14
14
  format.json do
15
15
  x_id = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
16
+ p "================================================================================"
17
+ p x_id
16
18
  if @current_admin.is_admin?
17
19
  @money_plans = MoneyPlan.joins(:follow_up).where("educode_sales_follow_ups.clazz_id != ?", x_id).where(follow_up_id: follow_up_ids)
18
20
  else
@@ -36,6 +36,7 @@ module EducodeSales
36
36
  if params[:q].present? && params[:q][:staff_id].present?
37
37
  @sale_plans = @sale_plans.where(staff_id: params[:q][:staff_id])
38
38
  end
39
+ # p "#{params[:q][:year]}-01-01 00:00:00".to_date, "#{params[:q][:year]}-12-31 23:59:00".to_date
39
40
  if params[:q].present? && params[:q][:year].present?
40
41
  @sale_plans = @sale_plans.where("month >= ? and month <= ?", "#{params[:q][:year]}-01-01 00:00:00".to_date, "#{params[:q][:year]}-12-31 23:59:00".to_date)
41
42
  end
@@ -16,7 +16,7 @@ module EducodeSales
16
16
 
17
17
  def create
18
18
  role = Role.new(name: params[:name])
19
- role.role_areas.build([{ clazz: 'Business' }, { clazz: 'SalePlan' }, { clazz: 'Teacher' }, { clazz: 'Operation' }, {clazz:'Customer'}, {clazz:'MoneyPlan'}])
19
+ role.role_areas.build([{ clazz: 'Business' }, { clazz: 'SalePlan' }, { clazz: 'Teacher' }, { clazz: 'Operation' }, { clazz: 'Customer' }, { clazz: 'MoneyPlan' }, { clazz: 'AssessmentsSetting' }])
20
20
  if role.save
21
21
  render_success
22
22
  else
@@ -84,6 +84,9 @@ module EducodeSales
84
84
  r = role.role_areas.find_or_initialize_by(clazz: 'MoneyPlan')
85
85
  r.level = params[:money_plan]
86
86
  r.save
87
+ r = role.role_areas.find_or_initialize_by(clazz: 'AssessmentsSetting')
88
+ r.level = params[:assessments_setting]
89
+ r.save
87
90
  render_success
88
91
  end
89
92
 
@@ -2,7 +2,8 @@ require_dependency "educode_sales/application_controller"
2
2
 
3
3
  module EducodeSales
4
4
  class SessionsController < ApplicationController
5
- layout "educode_sales/login"
5
+ layout "educode_sales/login" #todo 注意 修改模板(感觉是 整个控制器的html下都先导入该模板在导入对应的html)
6
+ # 行 动 前 跳 过
6
7
  skip_before_action :authenticate_request
7
8
 
8
9
  def login