educode_sales 0.5.4 → 0.5.8

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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/educode_sales/businesses_controller.rb +20 -1
  3. data/app/controllers/educode_sales/follow_ups_controller.rb +58 -1
  4. data/app/controllers/educode_sales/home_controller.rb +18 -2
  5. data/app/controllers/educode_sales/sale_trends_controller.rb +119 -84
  6. data/app/controllers/educode_sales/sales_controller.rb +3 -0
  7. data/app/controllers/educode_sales/teachers_controller.rb +41 -14
  8. data/app/controllers/educode_sales/upload_files_controller.rb +3 -3
  9. data/app/models/educode_sales/teacher.rb +2 -1
  10. data/app/models/educode_sales/teacher_assign_follow.rb +6 -0
  11. data/app/views/educode_sales/activities/index.html.erb +4 -5
  12. data/app/views/educode_sales/activities/show_teachers.html.erb +1 -1
  13. data/app/views/educode_sales/businesses/_follows.html.erb +255 -0
  14. data/app/views/educode_sales/businesses/edit_follow_record.html.erb +69 -6
  15. data/app/views/educode_sales/businesses/file.html.erb +2 -4
  16. data/app/views/educode_sales/businesses/index.html.erb +161 -66
  17. data/app/views/educode_sales/businesses/index.json.jbuilder +2 -1
  18. data/app/views/educode_sales/businesses/new_follow_record.html.erb +70 -6
  19. data/app/views/educode_sales/businesses/show_follow.html.erb +9 -9
  20. data/app/views/educode_sales/businesses/show_follow_record.html.erb +8 -0
  21. data/app/views/educode_sales/businesses/time_line.html.erb +1 -1
  22. data/app/views/educode_sales/follow_ups/index.json.jbuilder +20 -0
  23. data/app/views/educode_sales/home/sales_place.json.jbuilder +9 -0
  24. data/app/views/educode_sales/operation_plans/_monthPlan.html.erb +6 -0
  25. data/app/views/educode_sales/operation_plans/_monthly.html.erb +2 -0
  26. data/app/views/educode_sales/operation_plans/_weekPlan.html.erb +6 -0
  27. data/app/views/educode_sales/operation_plans/_weekly.html.erb +2 -0
  28. data/app/views/educode_sales/places/index.html.erb +14 -4
  29. data/app/views/educode_sales/places/index.json.jbuilder +7 -1
  30. data/app/views/educode_sales/plans/_monthPlan.html.erb +5 -0
  31. data/app/views/educode_sales/plans/_monthly.html.erb +1 -0
  32. data/app/views/educode_sales/plans/_weekPlan.html.erb +5 -0
  33. data/app/views/educode_sales/plans/_weekly.html.erb +1 -0
  34. data/app/views/educode_sales/recycles/index.html.erb +1 -1
  35. data/app/views/educode_sales/sale_trends/trends.html.erb +54 -5
  36. data/app/views/educode_sales/sales/index.html.erb +18 -3
  37. data/app/views/educode_sales/sales/index.json.jbuilder +27 -14
  38. data/app/views/educode_sales/sales/operations.html.erb +4 -1
  39. data/app/views/educode_sales/teachers/course_list.json.jbuilder +1 -1
  40. data/app/views/educode_sales/teachers/edit.html.erb +53 -7
  41. data/app/views/educode_sales/teachers/index.html.erb +42 -3
  42. data/app/views/educode_sales/teachers/index.json.jbuilder +4 -1
  43. data/app/views/educode_sales/teachers/new.html.erb +55 -17
  44. data/config/routes.rb +1 -0
  45. data/db/migrate/20211201023750_create_educode_sales_teacher_assign_follows.rb +11 -0
  46. data/db/migrate/20211206054756_add_year_to_follow_ups.rb +5 -0
  47. data/lib/educode_sales/version.rb +1 -1
  48. metadata +8 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 660c43183c6a1edf9d5aab4b549bce9d2b68edf789010d85379198372be1a120
4
- data.tar.gz: 28beeb3a7026076f4e6da6dc966bf75523e7be06717b787041d2e14500902532
3
+ metadata.gz: cb7ba8647915177726d6f9f525ea700b0e7ca469bf8ff7460d27a8d3e5204c28
4
+ data.tar.gz: d56bb7b39f7f44dc59b2d733ae60af4d3aee9135f8ee60e0721a5723bf20fc7a
5
5
  SHA512:
6
- metadata.gz: d7f6b1515f819aac77b135ba6d52a3562c4fef76d650fd1a74c44bf3dcaffacc41ec34e1623337538a36bf40cff2591d14d40e83575cd7920a69fcfadb5662c4
7
- data.tar.gz: ff102c87e89e482809f4b8e84e0f27c5f42a3dd22863f6ebfe0a4fd115eae1d026de70cd738c5b0d83e9e3ab78aee3a276eb0fed4f6a66c467ab8926c7737ed2
6
+ metadata.gz: 7b2d57743dbf47151f106931393b6e4e9671a8bba6b8393e3769954ddb8a82cb914c85ee926c16595ec546f2e7826a569590d6d9589d12d67d0858a77c2effc6
7
+ data.tar.gz: 96d8209f672ee5118f30da45bb672db2139f9890148c0bfff46873df59329d8aa5b1c9e1763e7c063048e994f03399706fd8e850a8502e8cd8d08bcae3e44dc0
@@ -149,10 +149,24 @@ module EducodeSales
149
149
 
150
150
  if params[:q].present? && params[:q][:area].present?
151
151
  p = EducodeSales::Common.find(params[:q][:area]).name
152
- @businesses = @businesses.joins("
152
+ if @current_admin.is_admin?
153
+ @businesses = @businesses.joins("
154
+ JOIN departments ON educode_sales_businesses.department_id = departments.id
155
+ JOIN schools ON departments.school_id = schools.id
156
+ ").where("province = ?", p)
157
+ else
158
+ level = @current_admin.role.role_areas.find_by(clazz: '商机管理').level
159
+ if level == "区域"
160
+ @businesses = @businesses.joins("
161
+ JOIN schools ON departments.school_id = schools.id
162
+ ").where("province = ?", p)
163
+ else
164
+ @businesses = @businesses.joins("
153
165
  JOIN departments ON educode_sales_businesses.department_id = departments.id
154
166
  JOIN schools ON departments.school_id = schools.id
155
167
  ").where("province = ?", p)
168
+ end
169
+ end
156
170
  end
157
171
 
158
172
  if params[:q].present? && params[:q][:date].present?
@@ -176,6 +190,7 @@ module EducodeSales
176
190
  last_follow.reception_at,
177
191
  last_follow.bidded_date,
178
192
  last_follow.signed_date,
193
+ last_follow.actual_amount,
179
194
  last_follow.total_amount").joins("
180
195
  LEFT JOIN educode_sales_follow_ups AS last_follow ON educode_sales_businesses.last_follow_up_id = last_follow.id
181
196
  ").page(params[:page]).per(params[:limit])
@@ -260,6 +275,7 @@ module EducodeSales
260
275
 
261
276
  def new_follow_record
262
277
  load_business
278
+ @years = (2015..Time.now.year).to_a.reverse
263
279
  @o_name = EducodeSales::Common.find_by(extras: EducodeSales::Common::OTYPE)&.name
264
280
  @clazz = Common.where(clazz: 'business_type').order("position").pluck(:name, :id)
265
281
  @stages = Common.where(clazz: 'business_step').order("position").pluck(:name, :id)
@@ -269,6 +285,7 @@ module EducodeSales
269
285
  gon.sales = @last_follow_up.assign_follow_ups.map do |d|
270
286
  {value: d.staff_id, name: d.staff.user.full_name}
271
287
  end
288
+ gon.place = @last_follow_up.place.present? ? [{ value: @last_follow_up.place&.id, name: @last_follow_up.place&.name }] : []
272
289
  end
273
290
  render layout: false
274
291
  end
@@ -294,6 +311,7 @@ module EducodeSales
294
311
  end
295
312
 
296
313
  def edit_follow_record
314
+ @years = (2015..Time.now.year).to_a.reverse
297
315
  @o_name = EducodeSales::Common.find_by(extras: EducodeSales::Common::OTYPE)&.name
298
316
  @follow_up = FollowUp.find(params[:follow_up_id])
299
317
  @clazz = Common.where(clazz: 'business_type').order("position").pluck(:name, :id)
@@ -302,6 +320,7 @@ module EducodeSales
302
320
  gon.sales = @follow_up.assign_follow_ups.map do |d|
303
321
  {value: d.staff_id, name: d.staff.user.full_name}
304
322
  end
323
+ gon.place = @follow_up.place.present? ? [{ value: @follow_up.place&.id, name: @follow_up.place&.name }] : [value: '', name: '']
305
324
  render layout: false
306
325
  end
307
326
 
@@ -3,6 +3,63 @@ require_dependency "educode_sales/application_controller"
3
3
  module EducodeSales
4
4
  class FollowUpsController < ApplicationController
5
5
 
6
+ def index
7
+ authorize! :read, Business
8
+ respond_to do |format|
9
+ format.html do
10
+ end
11
+ format.json do
12
+ if @current_admin.is_admin?
13
+ @follow_ups = FollowUp.all
14
+ else
15
+ level = @current_admin.role.role_areas.find_by(clazz: '商机管理').level
16
+ case level
17
+ when '自己'
18
+ business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
19
+ @businesses = Business.where("educode_sales_businesses.staff_id = ? OR educode_sales_businesses.id in (?)", @current_admin.id, business_ids)
20
+ business_ids = @businesses.pluck(:id)
21
+ @follow_ups = FollowUp.where(business_id: business_ids)
22
+ when '区域'
23
+ school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id)
24
+ business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
25
+ @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)
26
+ business_ids = @businesses.pluck(:id)
27
+ @follow_ups = FollowUp.where(business_id: business_ids)
28
+ else
29
+ @follow_ups = FollowUp.all
30
+ end
31
+ end
32
+ if params[:q].present? && params[:q][:name].present?
33
+ @follow_ups = @follow_ups.joins(:business).where("educode_sales_businesses.name LIKE ?", "%#{params[:q][:name]}%")
34
+ end
35
+ if params[:q].present? && params[:q][:follows_date].present?
36
+ date = params[:q][:follows_date].split(" - ")
37
+ @follow_ups = @follow_ups.where("educode_sales_follow_ups.created_at > ? AND educode_sales_follow_ups.created_at < ?", date[0], date[1])
38
+ end
39
+ if params[:q].present? && params[:q][:staff_id].present?
40
+ @follow_ups = @follow_ups.where(staff_id: params[:q][:staff_id])
41
+ end
42
+ if params[:q].present? && params[:q][:department].present?
43
+ departments_ids = Department.joins(:school).where("schools.name like ?", "%#{params[:q][:department]}%").pluck(:id)
44
+ @follow_ups = @follow_ups.joins(business: :department).where("departments.id in (?)", departments_ids)
45
+ end
46
+ if params[:q].present? && params[:q][:area].present?
47
+ p = EducodeSales::Common.find(params[:q][:area]).name
48
+ @follow_ups = @follow_ups.joins(:business).joins("
49
+ JOIN departments ON educode_sales_businesses.department_id = departments.id
50
+ JOIN schools ON departments.school_id = schools.id
51
+ ").where("province = ?", p)
52
+ end
53
+ if params[:sort].present? && params[:sort][:field]
54
+ @follow_ups = @follow_ups.order("#{params[:sort][:field]} #{params[:sort][:order]}")
55
+ else
56
+ @follow_ups = @follow_ups.order("educode_sales_follow_ups.created_at desc")
57
+ end
58
+ @follow_ups = @follow_ups.page(params[:page]).per(params[:limit])
59
+ end
60
+ end
61
+ end
62
+
6
63
  def create
7
64
  load_business
8
65
  follow_up = @business.follow_ups.build(follow_up_params)
@@ -157,7 +214,7 @@ module EducodeSales
157
214
  end
158
215
 
159
216
  def follow_up_params
160
- params.permit(:clazz_id, :stage_id, :invitation_at, :reception_at, :total_amount, :actual_amount, :divide_amount, :description, :advise, :place_id, :bidded_date, :signed_date)
217
+ params.permit(:clazz_id, :stage_id, :invitation_at, :reception_at, :total_amount, :actual_amount, :divide_amount, :description, :advise, :place_id, :bidded_date, :signed_date, :year)
161
218
  end
162
219
 
163
220
  def teacher_params
@@ -42,12 +42,28 @@ module EducodeSales
42
42
  end
43
43
 
44
44
  def sales_staff
45
- common = Common.find_by(clazz: 'staff_type', name: '销售')
46
45
  @staffs = Staff
46
+ if params[:teacher_assist].present?
47
+ common = Common.find_by(clazz: 'staff_type', name: '运营')
48
+ else
49
+ common = Common.find_by(clazz: 'staff_type', name: '销售')
50
+ end
47
51
  if params[:q].present?
48
52
  @staffs = @staffs.joins(user: :user_extension).where("concat(lastname, firstname) like :q", q: "%#{params[:q]}%")
49
53
  end
50
- @staffs = @staffs.where(is_admin: false).where.not(id: @current_admin.id).where(job_type: common.id).page(params[:page]).per(10)
54
+ if params[:teacher_assist].present?
55
+ @staffs = @staffs.where(is_admin: false).where(job_type: common.id).page(params[:page]).per(10)
56
+ else
57
+ @staffs = @staffs.where(is_admin: false).where.not(id: @current_admin.id).where(job_type: common.id).page(params[:page]).per(10)
58
+ end
59
+ end
60
+
61
+ def sales_place
62
+ @places = EducodeSales::Place
63
+ if params[:q].present?
64
+ @places = @places.where("name like :q", q: "%#{params[:q].strip}%")
65
+ end
66
+ @places = @places.page(params[:page]).per(10)
51
67
  end
52
68
 
53
69
  end
@@ -16,31 +16,40 @@ module EducodeSales
16
16
  @business_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ? AND educode_sales_follow_ups.clazz_id != ?", x, o).sum(:total_amount).round(2)
17
17
  stage_ids = Common.where(clazz: '商机阶段', name: ['已中标','已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
18
18
  @goal_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.bidded_date >= ? AND educode_sales_follow_ups.bidded_date <= ? AND educode_sales_follow_ups.stage_id IN (?)", "#{@year}-01-01", "#{@year}-12-31", stage_ids).sum(:total_amount).round(2)
19
+ @actual_goal_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.bidded_date >= ? AND educode_sales_follow_ups.bidded_date <= ? AND educode_sales_follow_ups.stage_id IN (?)", "#{@year}-01-01", "#{@year}-12-31", stage_ids).sum(:actual_amount).round(2)
19
20
  s_stage_ids = Common.where(clazz: '商机阶段', name: ['已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
20
21
  @service_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.signed_date >= ? AND educode_sales_follow_ups.signed_date <= ? AND educode_sales_follow_ups.stage_id IN (?)", "#{@year}-01-01", "#{@year}-12-31", s_stage_ids).sum(:total_amount).round(2)
22
+ @actual_service_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.signed_date >= ? AND educode_sales_follow_ups.signed_date <= ? AND educode_sales_follow_ups.stage_id IN (?)", "#{@year}-01-01", "#{@year}-12-31", s_stage_ids).sum(:actual_amount).round(2)
21
23
  @return_amount = Business.joins(last_follow_up: :money_plans).where("educode_sales_follow_ups.clazz_id != ?", x).where.not("educode_sales_money_plans.clazz!= ?", 1).where("educode_sales_money_plans.date_at >= ? AND educode_sales_money_plans.date_at <= ? ", year_time, year_over_time).sum(:amount).round(2)
22
24
  a = Common.where(clazz: '商机类型', name: Common.find_by(extras: EducodeSales::Common::ATYPE)&.name).pluck(:id)
23
25
  @a_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id IN (?)", a).sum(:total_amount).round(2)
24
26
  b = Common.where(clazz: '商机类型', name: Common.find_by(extras: EducodeSales::Common::BTYPE)&.name).pluck(:id)
25
27
  @b_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id IN (?)", b).sum(:total_amount).round(2)
26
28
 
29
+ count_type = params[:count_type] || "actual_amount"
27
30
  common = Common.find_by(clazz: 'staff_type', name: '销售')
28
31
  names = Staff.includes(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id] }
29
32
  x_business_ids = []
30
- default_dates = (7.day.ago.to_date..Date.today).to_a #默认时间范围
33
+ default_dates = (30.day.ago.to_date..Date.today).map { |d| d.strftime("%Y-%W")}.uniq #默认时间范围
31
34
  Business.all.each do |d|
32
35
  if d.last_follow_up&.clazz&.id == x
33
36
  x_business_ids << d.id
34
37
  end
35
38
  end
36
- colors = ['#44D7B6','#4CACFF','#F7B500','#FF0000', '#FF7F00', '#FFFF00', '#00FF00', '#00FFFF', '#0000FF', '#8B00FF', 'rgba(255, 99, 132, 1)', 'rgba(54, 162, 235, 1)', 'rgba(255, 206, 86, 1)', 'rgba(75, 192, 192, 1)', 'rgba(153, 102, 255, 1)', 'rgba(255, 159, 64, 1)']
37
- @follow_count_range = params[:follow_count_range] || "day"
38
- @goal_count_range = params[:goal_count_range] || "day"
39
+ colors = ['#44D7B6','#4CACFF','#F7B500','#FF0000', '#FF7F00', '#FFFF00', '#00FF00', '#00FFFF', '#0000FF', '#8B00FF', 'rgba(255, 99, 132, 1)', 'rgba(54, 162, 235, 1)', 'rgba(255, 206, 86, 1)', 'rgba(75, 192, 192, 1)', 'rgba(153, 102, 255, 1)', 'rgba(255, 159, 64, 1)' ,'rgba(255, 0, 250, 1)']
40
+ @follow_count_range = params[:follow_count_range] || "week"
41
+ @goal_count_range = params[:goal_count_range] || "month"
39
42
  # 商机跟进数图表
40
- @follow_count_data = day_follow_count_chart(default_dates,names,x_business_ids,colors)
43
+ @follow_count_data = week_follow_count_chart(default_dates,names,x_business_ids,colors)
41
44
  if params[:follow_count_range].present?
42
45
  case params[:follow_count_range]
43
- when "week"
46
+ when "week" #按周
47
+ if params[:date_week].present?
48
+ date = params[:date_week].split(" - ")
49
+ dates = (date[0].to_date..date[1].to_date).map { |d|
50
+ d.strftime("%Y-%W")}.uniq
51
+ @follow_count_data = week_follow_count_chart(dates,names,x_business_ids,colors)
52
+ end
44
53
  when "month" #按月
45
54
  if params[:date_month].present?
46
55
  # (Date.new(2020,12,1)..Date.new(2021,12,1)).map { |d| d.strftime("%Y-%m")}.uniq
@@ -67,27 +76,7 @@ module EducodeSales
67
76
  # 已中标图表
68
77
  goal_default_dates = ("#{Time.now.year}-01".."#{Time.now.year}-#{Time.now.month}").to_a
69
78
  sale_names = ['已中标','已签单','已回款']
70
- @goal_count_data =
71
- {
72
- labels: goal_default_dates,
73
- datasets: sale_names.map do |name|{
74
- label: name,
75
- data: goal_default_dates.map{ |d|
76
- case sale_names.index(name)
77
- when 0
78
- Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.bidded_date >= ? AND educode_sales_follow_ups.bidded_date <= ? AND educode_sales_follow_ups.stage_id IN (?)", "#{d}-01", "#{d}-31", stage_ids).sum(:total_amount).round(2)
79
- when 1
80
- Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.signed_date >= ? AND educode_sales_follow_ups.signed_date <= ? AND educode_sales_follow_ups.stage_id IN (?)", "#{d}-01", "#{d}-31", s_stage_ids).sum(:total_amount).round(2)
81
- else
82
- Business.joins(last_follow_up: :money_plans).where("educode_sales_follow_ups.clazz_id != ?", x).where.not("educode_sales_money_plans.clazz!= ?", 1).where("educode_sales_money_plans.date_at >= ? AND educode_sales_money_plans.date_at <= ? ", "#{d}-01", "#{d}-31").sum(:amount).round(2)
83
- end
84
- },
85
- backgroundColor: colors[sale_names.index(name)],
86
- borderColor: colors[sale_names.index(name)],
87
- borderWidth: 1
88
- }
89
- end
90
- }
79
+ @goal_count_data = month_sale_chart(goal_default_dates,sale_names,colors,x,stage_ids,s_stage_ids,count_type)
91
80
  if params[:goal_count_range].present?
92
81
  case params[:goal_count_range]
93
82
  when "week"
@@ -95,49 +84,13 @@ module EducodeSales
95
84
  if params[:goal_date_month].present?
96
85
  date = params[:goal_date_month].split(" - ")
97
86
  dates = ((date[0]+"-01").to_date..(date[1]+"-01").to_date).map { |d| d.strftime("%Y-%m")}.uniq
98
- @goal_count_data = {
99
- labels: dates,
100
- datasets: sale_names.map do |name|{
101
- label: name,
102
- data: dates.map{ |d|
103
- case sale_names.index(name)
104
- when 0
105
- Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.bidded_date >= ? AND educode_sales_follow_ups.bidded_date <= ? AND educode_sales_follow_ups.stage_id IN (?)", "#{d}-01", "#{d}-31", stage_ids).sum(:total_amount).round(2)
106
- when 1
107
- Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.signed_date >= ? AND educode_sales_follow_ups.signed_date <= ? AND educode_sales_follow_ups.stage_id IN (?)", "#{d}-01", "#{d}-31", s_stage_ids).sum(:total_amount).round(2)
108
- else
109
- Business.joins(last_follow_up: :money_plans).where("educode_sales_follow_ups.clazz_id != ?", x).where.not("educode_sales_money_plans.clazz!= ?", 1).where("educode_sales_money_plans.date_at >= ? AND educode_sales_money_plans.date_at <= ? ", "#{d}-01", "#{d}-31").sum(:amount).round(2)
110
- end },
111
- backgroundColor: colors[sale_names.index(name)],
112
- borderColor: colors[sale_names.index(name)],
113
- borderWidth: 1
114
- }
115
- end
116
- }
87
+ @goal_count_data = month_sale_chart(dates,sale_names,colors,x,stage_ids,s_stage_ids,count_type)
117
88
  end
118
- else #按年
89
+ else #按年
119
90
  if params[:goal_date_year].present?
120
91
  date = params[:goal_date_year].split(" - ")
121
92
  dates = (date[0]..date[1]).to_a
122
- @goal_count_data = {
123
- labels: dates,
124
- datasets:sale_names.map do |name| {
125
- label: name,
126
- data: dates.map{ |d|
127
- case sale_names.index(name)
128
- when 0
129
- Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.bidded_date >= ? AND educode_sales_follow_ups.bidded_date <= ? AND educode_sales_follow_ups.stage_id IN (?)", "#{d}-01-01", "#{d}-12-31", stage_ids).sum(:total_amount).round(2)
130
- when 1
131
- Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.signed_date >= ? AND educode_sales_follow_ups.signed_date <= ? AND educode_sales_follow_ups.stage_id IN (?)", "#{d}-01-01", "#{d}-12-31", s_stage_ids).sum(:total_amount).round(2)
132
- else
133
- Business.joins(last_follow_up: :money_plans).where("educode_sales_follow_ups.clazz_id != ?", x).where.not("educode_sales_money_plans.clazz!= ?", 1).where("educode_sales_money_plans.date_at >= ? AND educode_sales_money_plans.date_at <= ? ", "#{d}-01-01", "#{d}-12-31").sum(:amount).round(2)
134
- end },
135
- backgroundColor: colors[sale_names.index(name)],
136
- borderColor: colors[sale_names.index(name)],
137
- borderWidth: 1
138
- }
139
- end
140
- }
93
+ @goal_count_data = year_sale_chart(dates,sale_names,colors,x,stage_ids,s_stage_ids,count_type)
141
94
  end
142
95
  end
143
96
  end
@@ -165,16 +118,53 @@ module EducodeSales
165
118
  def day_follow_count_chart(dates,names,x_business_ids,colors)
166
119
  {
167
120
  labels: dates,
168
- datasets:names.map do |name|
121
+ datasets:names.map.with_index do |name,i|
169
122
  {
170
- hidden: names.index(name) < 3 ? false : true,
123
+ # hidden: i < 3 ? false : true,
171
124
  label: name[0],
172
125
  data: dates.map{ |d| @follow_up = FollowUp.where(staff_id: name[1], created_at: d.beginning_of_day..d.end_of_day).where.not(business: x_business_ids).count },
173
126
  backgroundColor: "#fff",
174
- pointBorderColor: colors[names.index(name)%15],
175
- borderColor: colors[names.index(name)%15],
176
- pointBackgroundColor: colors[names.index(name)%15],
177
- borderWidth: 4
127
+ pointBorderColor: colors[i%15+1],
128
+ borderColor: colors[i%15+1],
129
+ pointBackgroundColor: colors[i%15+1],
130
+ borderWidth: 2
131
+ }
132
+ end
133
+ }
134
+ end
135
+ def week_follow_count_chart(dates,names,x_business_ids,colors)
136
+ {
137
+ labels: dates.map{ |date|
138
+ d = date.split("-")
139
+ year = d[0].to_i
140
+ week = d[1].to_i
141
+ if week == 0
142
+ 0
143
+ else
144
+ month = Date.commercial(year,week).strftime("%m月%d日")
145
+ day = Date.commercial(year,week,7).strftime("%m月%d日")
146
+ date.to_s + "(#{month}-#{day})"
147
+ end
148
+ } - [0],
149
+ datasets:names.map.with_index do |name,i|
150
+ {
151
+ # hidden: i < 3 ? false : true,
152
+ label: name[0],
153
+ data: dates.map{ |d|
154
+ d = d.split("-")
155
+ year = d[0].to_i
156
+ week = d[1].to_i
157
+ if week == 0
158
+ @follow_up = 999999
159
+ else
160
+ @follow_up = FollowUp.where(staff_id: name[1]).where("created_at >= ? AND created_at <= ?", Date.commercial(year,week).strftime("%Y-%m-%d"), Date.commercial(year,week,7).strftime("%Y-%m-%d")).where.not(business: x_business_ids).count
161
+ end
162
+ } - [999999],
163
+ backgroundColor: "#fff",
164
+ pointBorderColor: colors[i%15+1],
165
+ borderColor: colors[i%15+1],
166
+ pointBackgroundColor: colors[i%15+1],
167
+ borderWidth: 2
178
168
  }
179
169
  end
180
170
  }
@@ -182,16 +172,16 @@ module EducodeSales
182
172
  def month_follow_count_chart(dates,names,x_business_ids,colors)
183
173
  {
184
174
  labels: dates,
185
- datasets:names.map do |name|
175
+ datasets:names.map.with_index do |name,i|
186
176
  {
187
- hidden: names.index(name) < 3 ? false : true,
177
+ # hidden: i < 3 ? false : true,
188
178
  label: name[0],
189
179
  data: dates.map { |d| @follow_up = FollowUp.where( staff_id: name[1]).where("created_at >= ? AND created_at <= ?", "#{d}-01", "#{d}-31").where.not(business: x_business_ids).count },
190
180
  backgroundColor: "#fff",
191
- pointBorderColor: colors[names.index(name)%15],
192
- borderColor: colors[names.index(name)%15],
193
- pointBackgroundColor: colors[names.index(name)%15],
194
- borderWidth: 4,
181
+ pointBorderColor: colors[i%15+1],
182
+ borderColor: colors[i%15+1],
183
+ pointBackgroundColor: colors[i%15+1],
184
+ borderWidth: 2,
195
185
  }
196
186
  end
197
187
  }
@@ -199,21 +189,66 @@ module EducodeSales
199
189
  def year_follow_count_chart(dates,names,x_business_ids,colors)
200
190
  {
201
191
  labels: dates,
202
- datasets:names.map do |name|
192
+ datasets:names.map.with_index do |name,i|
203
193
  {
204
- hidden: names.index(name) < 3 ? false : true,
194
+ # hidden: i < 3 ? false : true,
205
195
  label: name[0],
206
196
  data: dates.map { |d| @follow_up = FollowUp.where( staff_id: name[1]).where("created_at >= ? AND created_at <= ?", "#{d}-01-01", "#{d}-12-31").where.not(business: x_business_ids).count },
207
197
  backgroundColor: "#fff",
208
- pointBorderColor: colors[names.index(name)%15],
209
- borderColor: colors[names.index(name)%15],
210
- pointBackgroundColor: colors[names.index(name)%15],
211
- borderWidth: 4
198
+ pointBorderColor: colors[i%15+1],
199
+ borderColor: colors[i%15+1],
200
+ pointBackgroundColor: colors[i%15+1],
201
+ borderWidth: 2
212
202
  }
213
203
  end
214
204
  }
215
205
  end
216
206
 
207
+ def month_sale_chart(dates,names,colors,x,stage_ids,s_stage_ids,count_type)
208
+ {
209
+ labels: dates,
210
+ datasets: names.map.with_index do |name,i|{
211
+ label: name,
212
+ data: dates.map{ |d|
213
+ case i
214
+ when 0
215
+ Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.bidded_date >= ? AND educode_sales_follow_ups.bidded_date <= ? AND educode_sales_follow_ups.stage_id IN (?)", "#{d}-01", "#{d}-31", stage_ids).sum(count_type).round(2)
216
+ when 1
217
+ Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.signed_date >= ? AND educode_sales_follow_ups.signed_date <= ? AND educode_sales_follow_ups.stage_id IN (?)", "#{d}-01", "#{d}-31", s_stage_ids).sum(count_type).round(2)
218
+ else
219
+ Business.joins(last_follow_up: :money_plans).where("educode_sales_follow_ups.clazz_id != ?", x).where.not("educode_sales_money_plans.clazz!= ?", 1).where("educode_sales_money_plans.date_at >= ? AND educode_sales_money_plans.date_at <= ? ", "#{d}-01", "#{d}-31").sum(:amount).round(2)
220
+ end
221
+ },
222
+ backgroundColor: colors[i],
223
+ borderColor: colors[i],
224
+ borderWidth: 1
225
+ }
226
+ end
227
+ }
228
+ end
229
+
230
+ def year_sale_chart(dates,names,colors,x,stage_ids,s_stage_ids,count_type)
231
+ {
232
+ labels: dates,
233
+ datasets:names.map.with_index do |name,i| {
234
+ label: name,
235
+ data: dates.map{ |d|
236
+ case i
237
+ when 0
238
+ Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.bidded_date >= ? AND educode_sales_follow_ups.bidded_date <= ? AND educode_sales_follow_ups.stage_id IN (?)", "#{d}-01-01", "#{d}-12-31", stage_ids).sum(count_type).round(2)
239
+ when 1
240
+ Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.signed_date >= ? AND educode_sales_follow_ups.signed_date <= ? AND educode_sales_follow_ups.stage_id IN (?)", "#{d}-01-01", "#{d}-12-31", s_stage_ids).sum(count_type).round(2)
241
+ else
242
+ Business.joins(last_follow_up: :money_plans).where("educode_sales_follow_ups.clazz_id != ?", x).where.not("educode_sales_money_plans.clazz!= ?", 1).where("educode_sales_money_plans.date_at >= ? AND educode_sales_money_plans.date_at <= ? ", "#{d}-01-01", "#{d}-12-31").sum(:amount).round(2)
243
+ end },
244
+ backgroundColor: colors[i],
245
+ borderColor: colors[i],
246
+ borderWidth: 1
247
+ }
248
+ end
249
+ }
250
+ end
251
+
217
252
 
218
253
  end
219
254
  end
@@ -9,8 +9,11 @@ module EducodeSales
9
9
  authorize! :sales, Staff
10
10
  respond_to do |format|
11
11
  format.html do
12
+ @year = params[:year] ? params[:year] : "全部"
13
+ @years = ["全部"]+(2015..Time.now.year).to_a.reverse
12
14
  end
13
15
  format.json do
16
+ @year = params[:year] ? params[:year] : "全部"
14
17
  common = Common.find_by(clazz: 'staff_type', name: '销售')
15
18
  @a_clazz = Common.find_by(clazz: 'business_type', name: Common.find_by(extras: EducodeSales::Common::ATYPE)&.name)
16
19
  @b_clazz = Common.find_by(clazz: 'business_type', name: Common.find_by(extras: EducodeSales::Common::BTYPE)&.name)
@@ -21,6 +21,8 @@ module EducodeSales
21
21
  def index
22
22
  respond_to do |format|
23
23
  format.html do
24
+ common = Common.find_by(clazz: 'staff_type', name: '运营')
25
+ @staffs = Staff.joins(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id]}
24
26
  @more = can?(:create, EducodeSales::OperationPlan) || can?(:update, EducodeSales::Teacher) || can?(:destroy, EducodeSales::Teacher)
25
27
  gon.menus = []
26
28
  if can?(:create, EducodeSales::OperationPlan)
@@ -43,14 +45,30 @@ module EducodeSales
43
45
  when '自己'
44
46
  @teachers = Teacher.where(is_key: false)
45
47
  @teachers = @teachers.where(staff_id: @current_admin.id)
48
+ teacher_ids = EducodeSales::Teacher.where(staff_id: 0).pluck(:id) - EducodeSales::TeacherAssignFollow.all.pluck(:Teacher_id) + EducodeSales::TeacherAssignFollow.where(staff_id: @current_admin.id).pluck(:teacher_id) + @teachers.ids
49
+ @teachers = Teacher.where(id: teacher_ids)
46
50
  when '区域'
47
51
  school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id)
48
52
  @teachers = Teacher.joins("JOIN departments ON educode_sales_teachers.department_id = departments.id").where(is_key: false).where("departments.school_id in (?) OR educode_sales_teachers.staff_id = #{@current_admin.id}", school_ids)
53
+ teacher_ids = EducodeSales::Teacher.where(staff_id: 0).pluck(:id) - EducodeSales::TeacherAssignFollow.all.pluck(:Teacher_id) + EducodeSales::TeacherAssignFollow.where(staff_id: @current_admin.id).pluck(:teacher_id) + @teachers.ids
54
+ @teachers = Teacher.where(id: teacher_ids)
49
55
  else
50
56
  @teachers = Teacher.where(is_key: false)
51
57
  end
52
58
  end
53
-
59
+
60
+ if @current_admin.job_type == Common.find_by(clazz: 'staff_type', name: '销售').id
61
+ public_teacher_ids = EducodeSales::Teacher.where(staff_id: 0).pluck(:id) - EducodeSales::TeacherAssignFollow.where(staff_id: @current_admin.id).pluck(:teacher_id)
62
+ @teachers = @teachers.where.not(id: public_teacher_ids)
63
+ end
64
+
65
+
66
+
67
+ if params[:q].present? && params[:q][:assist].present?
68
+ staff_id = params[:q][:assist].to_i
69
+ teacher_ids = EducodeSales::TeacherAssignFollow.where(staff_id: staff_id).pluck(:teacher_id)
70
+ @teachers = @teachers.where(id: teacher_ids)
71
+ end
54
72
  if params[:q].present? && params[:q][:name].present?
55
73
  @teachers = @teachers.where("educode_sales_teachers.name like ?", "%#{params[:q][:name]}%")
56
74
  end
@@ -60,6 +78,13 @@ module EducodeSales
60
78
  if params[:q].present? && params[:q][:regist_at].present?
61
79
  @teachers = @teachers.where("educode_sales_teachers.regist_at like ?", "%#{params[:q][:regist_at]}%")
62
80
  end
81
+ if params[:q].present? && params[:q][:status].present?
82
+ if params[:q][:status] == "1"
83
+ @teachers = @teachers.where("educode_sales_teachers.user_id is not null")
84
+ else
85
+ @teachers = @teachers.where("educode_sales_teachers.user_id is null")
86
+ end
87
+ end
63
88
  if params[:q].present? && params[:q][:attitude].present?
64
89
  # @teachers = @teachers.where("educode_sales_teachers.attitude_id = ?", "#{params[:q][:attitude]}")
65
90
  @teachers = @teachers.joins("
@@ -105,6 +130,9 @@ module EducodeSales
105
130
  def create
106
131
  department = Department.find(params[:department_id])
107
132
  teacher = @current_admin.teachers.build(teacher_params)
133
+ params[:teacher_assist].each do |d|
134
+ teacher.teacher_assign_follows.build(staff_id: d)
135
+ end
108
136
  teacher.department_id = department.id
109
137
  if params[:user_id].present?
110
138
  user = User.find(params[:user_id])
@@ -147,6 +175,13 @@ module EducodeSales
147
175
  teacher = Teacher.find(params[:id])
148
176
  teacher.department_id = department.id
149
177
  teacher.assign_attributes(teacher_params)
178
+
179
+ teacher_assists = []
180
+ params[:teacher_assist].each do |d|
181
+ teacher_assists << teacher.teacher_assign_follows.find_or_initialize_by(staff_id: d)
182
+ end
183
+ teacher.teacher_assign_follows = teacher_assists
184
+
150
185
  if params[:user_id].present?
151
186
  user = User.find(params[:user_id])
152
187
  teacher.user_id = user.id
@@ -171,7 +206,10 @@ module EducodeSales
171
206
  end
172
207
 
173
208
  def edit
174
- @teacher = Teacher.find(params[:id])
209
+ load_teacher
210
+ gon.teacher_assist = @teacher.teacher_assign_follows.map do |d|
211
+ {value: d.staff_id, name: d.staff.user.full_name}
212
+ end
175
213
  gon.department = { value: @teacher.department_id, name: "#{@teacher.department&.school&.name}-#{@teacher.department&.name}" }
176
214
  gon.value = @teacher.department_id
177
215
  render layout: false
@@ -256,17 +294,6 @@ module EducodeSales
256
294
  render layout: false
257
295
  end
258
296
 
259
- # def create_follow_record
260
- #
261
- # end
262
- #
263
- # def update_follow_record
264
- #
265
- # end
266
- # def delete_follow_record
267
- #
268
- # end
269
-
270
297
  def show_follow_record
271
298
  @follow_up = TeacherFollow.find(params[:id])
272
299
  render layout: false
@@ -294,7 +321,7 @@ module EducodeSales
294
321
 
295
322
  private
296
323
  def teacher_params
297
- params.permit(:name, :professional_title, :job, :source_id)
324
+ params.permit(:name, :professional_title, :job, :source_id, :wechat)
298
325
  end
299
326
 
300
327
  def load_teacher
@@ -20,7 +20,7 @@ module EducodeSales
20
20
  end
21
21
 
22
22
  def create
23
- folder = File.join(Rails.root, "public", "images", 'educode_sales')
23
+ folder = File.join(Rails.root, "public", "files", 'educode_sales')
24
24
  upload_file = params["file"]
25
25
  raise "未上传文件" unless upload_file
26
26
  save_path = File.join(folder)
@@ -48,7 +48,7 @@ module EducodeSales
48
48
  end
49
49
 
50
50
  def destroy
51
- folder = File.join(Rails.root, "public", "images", 'educode_sales')
51
+ folder = File.join(Rails.root, "public", "files", 'educode_sales')
52
52
  file = Attachment.find(params[:id])
53
53
  file.destroy
54
54
  File.delete(folder + "/" +file.disk_filename) if FileTest::exist?(folder + "/" +file.disk_filename)
@@ -56,7 +56,7 @@ module EducodeSales
56
56
  end
57
57
 
58
58
  def download
59
- folder = File.join(Rails.root, "public", "images", 'educode_sales')
59
+ folder = File.join(Rails.root, "public", "files", 'educode_sales')
60
60
  file = Attachment.find_by_id(params[:id])
61
61
  raise "未找到文件" unless file
62
62
  send_file(folder + "/" +file.disk_filename, filename: file.title, stream: true, type: file.content_type.presence || 'application/octet-stream')
@@ -6,8 +6,9 @@ module EducodeSales
6
6
  has_many :operation_plans, dependent: :destroy
7
7
  has_many :course_subjects, dependent: :destroy
8
8
  has_many :key_person, dependent: :destroy
9
+ has_many :teacher_assign_follows
9
10
  belongs_to :department, optional: true
10
- belongs_to :staff
11
+ belongs_to :staff, optional: true
11
12
  belongs_to :user, optional: true
12
13
  # belongs_to :follow_up, counter_cache: true, optional: true
13
14
  belongs_to :follow_up, class_name: 'TeacherFollow', optional: true
@@ -0,0 +1,6 @@
1
+ module EducodeSales
2
+ class TeacherAssignFollow < ApplicationRecord
3
+ belongs_to :staff
4
+ belongs_to :teacher
5
+ end
6
+ end