educode_sales 0.5.3 → 0.5.7

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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/educode_sales/businesses_controller.rb +3 -0
  3. data/app/controllers/educode_sales/follow_ups_controller.rb +57 -0
  4. data/app/controllers/educode_sales/home_controller.rb +11 -0
  5. data/app/controllers/educode_sales/sale_trends_controller.rb +108 -84
  6. data/app/controllers/educode_sales/teachers_controller.rb +36 -14
  7. data/app/controllers/educode_sales/upload_files_controller.rb +3 -3
  8. data/app/models/educode_sales/teacher.rb +2 -1
  9. data/app/models/educode_sales/teacher_assign_follow.rb +6 -0
  10. data/app/views/educode_sales/activities/index.html.erb +4 -5
  11. data/app/views/educode_sales/activities/show_teachers.html.erb +1 -1
  12. data/app/views/educode_sales/businesses/_follows.html.erb +233 -0
  13. data/app/views/educode_sales/businesses/edit_follow_record.html.erb +59 -9
  14. data/app/views/educode_sales/businesses/file.html.erb +2 -4
  15. data/app/views/educode_sales/businesses/index.html.erb +137 -62
  16. data/app/views/educode_sales/businesses/index.json.jbuilder +1 -0
  17. data/app/views/educode_sales/businesses/new_follow_record.html.erb +58 -7
  18. data/app/views/educode_sales/businesses/show_follow.html.erb +9 -9
  19. data/app/views/educode_sales/businesses/show_follow_record.html.erb +1 -1
  20. data/app/views/educode_sales/businesses/time_line.html.erb +1 -1
  21. data/app/views/educode_sales/follow_ups/index.json.jbuilder +19 -0
  22. data/app/views/educode_sales/home/sales_place.json.jbuilder +9 -0
  23. data/app/views/educode_sales/places/index.html.erb +14 -4
  24. data/app/views/educode_sales/places/index.json.jbuilder +7 -1
  25. data/app/views/educode_sales/recycles/index.html.erb +1 -1
  26. data/app/views/educode_sales/sale_trends/trends.html.erb +56 -20
  27. data/app/views/educode_sales/sales/operations.html.erb +3 -1
  28. data/app/views/educode_sales/teachers/course_list.json.jbuilder +1 -1
  29. data/app/views/educode_sales/teachers/edit.html.erb +53 -7
  30. data/app/views/educode_sales/teachers/index.html.erb +36 -2
  31. data/app/views/educode_sales/teachers/index.json.jbuilder +4 -1
  32. data/app/views/educode_sales/teachers/new.html.erb +55 -17
  33. data/config/routes.rb +1 -0
  34. data/db/migrate/20211201023750_create_educode_sales_teacher_assign_follows.rb +11 -0
  35. data/lib/educode_sales/version.rb +1 -1
  36. metadata +7 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87e480da43efa545f556407cb3aced122684a09ebba821cc1d5ba1b33013758c
4
- data.tar.gz: f8a1d0d849c2f45fac61856394ebd61fa19c6993349393cf30c73061071e200b
3
+ metadata.gz: ef5373cd46335d53f4f5062b2ac750c01fa8797ddf1626c4373c6997e5e1fa9f
4
+ data.tar.gz: f27164e66b64b22b5b0c889ffb3c5c2c6567559f490a00e4af8a32f4298841dd
5
5
  SHA512:
6
- metadata.gz: 2b9b85218c9ab2ba92752aaac23ed8329bd130c48f27c00488d4e8a484cdb8791b29b9be8bb9ccafa6828ba9bc4500c4365718d5c080cfd789960c5125c2da33
7
- data.tar.gz: 8ae91d1a4d9337886c87067b69728cd93831e8d7a85bf524c6acef57915561726a574d6a3c5a1c2eb4cead28ea6aea1450dd94949920d0113856b7390f418445
6
+ metadata.gz: a9d42047fdaeba4c49096c40dd92b9d33ed77f84ef7a65410f34bab1a0408be55c7db38caa5e30aab0456d1b93af4db2a0c79c953dfdfd9f39579f26e5a1cef2
7
+ data.tar.gz: 2850fa03b263d9a06f0d2af5c9649b9ccd30719a58e5a0f0dac41bb2b495c2745e2ed1b8711ecabdac249166c75dadec3d26b7219800398ee7ff219c6fa167c7
@@ -176,6 +176,7 @@ module EducodeSales
176
176
  last_follow.reception_at,
177
177
  last_follow.bidded_date,
178
178
  last_follow.signed_date,
179
+ last_follow.actual_amount,
179
180
  last_follow.total_amount").joins("
180
181
  LEFT JOIN educode_sales_follow_ups AS last_follow ON educode_sales_businesses.last_follow_up_id = last_follow.id
181
182
  ").page(params[:page]).per(params[:limit])
@@ -269,6 +270,7 @@ module EducodeSales
269
270
  gon.sales = @last_follow_up.assign_follow_ups.map do |d|
270
271
  {value: d.staff_id, name: d.staff.user.full_name}
271
272
  end
273
+ gon.place = [{ value: @last_follow_up.place&.id, name: @last_follow_up.place&.name }]
272
274
  end
273
275
  render layout: false
274
276
  end
@@ -302,6 +304,7 @@ module EducodeSales
302
304
  gon.sales = @follow_up.assign_follow_ups.map do |d|
303
305
  {value: d.staff_id, name: d.staff.user.full_name}
304
306
  end
307
+ gon.place = [{ value: @follow_up.place&.id, name: @follow_up.place&.name }]
305
308
  render layout: false
306
309
  end
307
310
 
@@ -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][:follows_business].present?
33
+ @follow_ups = @follow_ups.joins(:business).where("educode_sales_businesses.name LIKE ?", "%#{params[:q][:follows_business]}%")
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][:follows_staff_id].present?
40
+ @follow_ups = @follow_ups.where(staff_id: params[:q][:follows_staff_id])
41
+ end
42
+ if params[:q].present? && params[:q][:follows_department].present?
43
+ departments_ids = Department.joins(:school).where("schools.name like ?", "%#{params[:q][:follows_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][:follows_area].present?
47
+ p = EducodeSales::Common.find(params[:q][:follows_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)
@@ -43,6 +43,9 @@ module EducodeSales
43
43
 
44
44
  def sales_staff
45
45
  common = Common.find_by(clazz: 'staff_type', name: '销售')
46
+ if params[:teacher_assist].present?
47
+ common = Common.find_by(clazz: 'staff_type', name: '运营')
48
+ end
46
49
  @staffs = Staff
47
50
  if params[:q].present?
48
51
  @staffs = @staffs.joins(user: :user_extension).where("concat(lastname, firstname) like :q", q: "%#{params[:q]}%")
@@ -50,5 +53,13 @@ module EducodeSales
50
53
  @staffs = @staffs.where(is_admin: false).where.not(id: @current_admin.id).where(job_type: common.id).page(params[:page]).per(10)
51
54
  end
52
55
 
56
+ def sales_place
57
+ @places = EducodeSales::Place
58
+ if params[:q].present?
59
+ @places = @places.where("name like :q", q: "%#{params[:q]}%")
60
+ end
61
+ @places = @places.page(params[:page]).per(10)
62
+ end
63
+
53
64
  end
54
65
  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,42 @@ 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: "#fff",
175
- borderColor: colors[names.index(name)%15],
176
- pointBackgroundColor: colors[names.index(name)%15],
177
- borderWidth: 1
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,
138
+ datasets:names.map.with_index do |name,i|
139
+ {
140
+ hidden: i < 3 ? false : true,
141
+ label: name[0],
142
+ data: dates.map{ |d|
143
+ d = d.split("-")
144
+ year = d[0].to_i
145
+ week = d[1].to_i
146
+ if week == 0
147
+ @follow_up = 0
148
+ else
149
+ @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
150
+ end
151
+ },
152
+ backgroundColor: "#fff",
153
+ pointBorderColor: colors[i%15+1],
154
+ borderColor: colors[i%15+1],
155
+ pointBackgroundColor: colors[i%15+1],
156
+ borderWidth: 2
178
157
  }
179
158
  end
180
159
  }
@@ -182,16 +161,16 @@ module EducodeSales
182
161
  def month_follow_count_chart(dates,names,x_business_ids,colors)
183
162
  {
184
163
  labels: dates,
185
- datasets:names.map do |name|
164
+ datasets:names.map.with_index do |name,i|
186
165
  {
187
- hidden: names.index(name) < 3 ? false : true,
166
+ hidden: i < 3 ? false : true,
188
167
  label: name[0],
189
168
  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
169
  backgroundColor: "#fff",
191
- pointBorderColor: "#fff",
192
- borderColor: colors[names.index(name)%15],
193
- pointBackgroundColor: colors[names.index(name)%15],
194
- borderWidth: 1
170
+ pointBorderColor: colors[i%15+1],
171
+ borderColor: colors[i%15+1],
172
+ pointBackgroundColor: colors[i%15+1],
173
+ borderWidth: 2,
195
174
  }
196
175
  end
197
176
  }
@@ -199,21 +178,66 @@ module EducodeSales
199
178
  def year_follow_count_chart(dates,names,x_business_ids,colors)
200
179
  {
201
180
  labels: dates,
202
- datasets:names.map do |name|
181
+ datasets:names.map.with_index do |name,i|
203
182
  {
204
- hidden: names.index(name) < 3 ? false : true,
183
+ hidden: i < 3 ? false : true,
205
184
  label: name[0],
206
185
  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
186
  backgroundColor: "#fff",
208
- pointBorderColor: "#fff",
209
- borderColor: colors[names.index(name)%15],
210
- pointBackgroundColor: colors[names.index(name)%15],
211
- borderWidth: 1
187
+ pointBorderColor: colors[i%15+1],
188
+ borderColor: colors[i%15+1],
189
+ pointBackgroundColor: colors[i%15+1],
190
+ borderWidth: 2
212
191
  }
213
192
  end
214
193
  }
215
194
  end
216
195
 
196
+ def month_sale_chart(dates,names,colors,x,stage_ids,s_stage_ids,count_type)
197
+ {
198
+ labels: dates,
199
+ datasets: names.map.with_index do |name,i|{
200
+ label: name,
201
+ data: dates.map{ |d|
202
+ case i
203
+ when 0
204
+ 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)
205
+ when 1
206
+ 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)
207
+ else
208
+ 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)
209
+ end
210
+ },
211
+ backgroundColor: colors[i],
212
+ borderColor: colors[i],
213
+ borderWidth: 1
214
+ }
215
+ end
216
+ }
217
+ end
218
+
219
+ def year_sale_chart(dates,names,colors,x,stage_ids,s_stage_ids,count_type)
220
+ {
221
+ labels: dates,
222
+ datasets:names.map.with_index do |name,i| {
223
+ label: name,
224
+ data: dates.map{ |d|
225
+ case i
226
+ when 0
227
+ 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)
228
+ when 1
229
+ 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)
230
+ else
231
+ 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)
232
+ end },
233
+ backgroundColor: colors[i],
234
+ borderColor: colors[i],
235
+ borderWidth: 1
236
+ }
237
+ end
238
+ }
239
+ end
240
+
217
241
 
218
242
  end
219
243
  end
@@ -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,25 @@ 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
+
61
+
62
+ if params[:q].present? && params[:q][:assist].present?
63
+ staff_id = params[:q][:assist].to_i
64
+ teacher_ids = EducodeSales::TeacherAssignFollow.where(staff_id: staff_id).pluck(:teacher_id)
65
+ @teachers = @teachers.where(id: teacher_ids)
66
+ end
54
67
  if params[:q].present? && params[:q][:name].present?
55
68
  @teachers = @teachers.where("educode_sales_teachers.name like ?", "%#{params[:q][:name]}%")
56
69
  end
@@ -60,6 +73,13 @@ module EducodeSales
60
73
  if params[:q].present? && params[:q][:regist_at].present?
61
74
  @teachers = @teachers.where("educode_sales_teachers.regist_at like ?", "%#{params[:q][:regist_at]}%")
62
75
  end
76
+ if params[:q].present? && params[:q][:status].present?
77
+ if params[:q][:status] == "1"
78
+ @teachers = @teachers.where("educode_sales_teachers.user_id is not null")
79
+ else
80
+ @teachers = @teachers.where("educode_sales_teachers.user_id is null")
81
+ end
82
+ end
63
83
  if params[:q].present? && params[:q][:attitude].present?
64
84
  # @teachers = @teachers.where("educode_sales_teachers.attitude_id = ?", "#{params[:q][:attitude]}")
65
85
  @teachers = @teachers.joins("
@@ -105,6 +125,9 @@ module EducodeSales
105
125
  def create
106
126
  department = Department.find(params[:department_id])
107
127
  teacher = @current_admin.teachers.build(teacher_params)
128
+ params[:teacher_assist].each do |d|
129
+ teacher.teacher_assign_follows.build(staff_id: d)
130
+ end
108
131
  teacher.department_id = department.id
109
132
  if params[:user_id].present?
110
133
  user = User.find(params[:user_id])
@@ -147,6 +170,13 @@ module EducodeSales
147
170
  teacher = Teacher.find(params[:id])
148
171
  teacher.department_id = department.id
149
172
  teacher.assign_attributes(teacher_params)
173
+
174
+ teacher_assists = []
175
+ params[:teacher_assist].each do |d|
176
+ teacher_assists << teacher.teacher_assign_follows.find_or_initialize_by(staff_id: d)
177
+ end
178
+ teacher.teacher_assign_follows = teacher_assists
179
+
150
180
  if params[:user_id].present?
151
181
  user = User.find(params[:user_id])
152
182
  teacher.user_id = user.id
@@ -171,7 +201,10 @@ module EducodeSales
171
201
  end
172
202
 
173
203
  def edit
174
- @teacher = Teacher.find(params[:id])
204
+ load_teacher
205
+ gon.teacher_assist = @teacher.teacher_assign_follows.map do |d|
206
+ {value: d.staff_id, name: d.staff.user.full_name}
207
+ end
175
208
  gon.department = { value: @teacher.department_id, name: "#{@teacher.department&.school&.name}-#{@teacher.department&.name}" }
176
209
  gon.value = @teacher.department_id
177
210
  render layout: false
@@ -256,17 +289,6 @@ module EducodeSales
256
289
  render layout: false
257
290
  end
258
291
 
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
292
  def show_follow_record
271
293
  @follow_up = TeacherFollow.find(params[:id])
272
294
  render layout: false
@@ -294,7 +316,7 @@ module EducodeSales
294
316
 
295
317
  private
296
318
  def teacher_params
297
- params.permit(:name, :professional_title, :job, :source_id)
319
+ params.permit(:name, :professional_title, :job, :source_id, :wechat)
298
320
  end
299
321
 
300
322
  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
@@ -52,24 +52,23 @@
52
52
  {
53
53
  field: 'name',
54
54
  title: '活动名称',
55
- width: 400,
56
55
  templet: '#teachers'
57
56
  },
58
57
  {
59
58
  field: 'start_at',
60
- width: 120,
59
+ width: 200,
61
60
  title: '时间',
62
61
  sort: true,
63
62
  },
64
63
  {
65
64
  field: 'days',
66
65
  title: '天数',
67
- width: 100
66
+ width: 200
68
67
  },
69
68
  {
70
69
  field: 'teachers_count',
71
70
  title: '教师数',
72
- width: 100,
71
+ width: 200,
73
72
  totalRow:true,
74
73
  templet: '#teachers_count'
75
74
  },
@@ -77,7 +76,7 @@
77
76
  field: 'students_count',
78
77
  title: '学生数',
79
78
  totalRow:'{{ parseInt(d.TOTAL_NUMS) }}',
80
- width: 100
79
+ width: 200
81
80
  },
82
81
  {
83
82
  title: '操作',
@@ -2,7 +2,7 @@
2
2
  <script type="text/html" id="teacher_toolbar">
3
3
  <div class="layui-btn-container">
4
4
  <span class="table-label">教师列表</span>
5
- <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn pull-right" lay-event="search_new"> 添加
5
+ <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn pull-right" lay-event="search_new"> 添加教师
6
6
  </button>
7
7
  </div>
8
8
  </script>