educode_sales 0.5.2 → 0.5.6

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 (38) 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 +35 -14
  7. data/app/controllers/educode_sales/upload_files_controller.rb +29 -29
  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 +51 -7
  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 +50 -5
  18. data/app/views/educode_sales/businesses/show_follow.html.erb +4 -4
  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 +89 -29
  27. data/app/views/educode_sales/sales/index.html.erb +7 -7
  28. data/app/views/educode_sales/sales/operations.html.erb +2 -0
  29. data/app/views/educode_sales/teachers/course_list.json.jbuilder +1 -1
  30. data/app/views/educode_sales/teachers/edit.html.erb +53 -7
  31. data/app/views/educode_sales/teachers/index.html.erb +35 -1
  32. data/app/views/educode_sales/teachers/index.json.jbuilder +4 -1
  33. data/app/views/educode_sales/teachers/new.html.erb +55 -17
  34. data/app/views/educode_sales/upload_files/index.json.jbuilder +1 -1
  35. data/config/routes.rb +1 -0
  36. data/db/migrate/20211201023750_create_educode_sales_teacher_assign_follows.rb +11 -0
  37. data/lib/educode_sales/version.rb +1 -1
  38. metadata +7 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ae794ee6831f1fab6465eb9290de9f3155b4a32e13acafe865500e42decaff6
4
- data.tar.gz: cb2e8ea7a97b6cd04942343417a7d427f18657dec46ddc2805d11a876a8672f1
3
+ metadata.gz: a3990eb5d7556c5bab5819c03981769a0385a28d52a8357ca8116cc1083ab6d0
4
+ data.tar.gz: 073e8a50229f8a39a2966fdfad84bd177efceb1101e82c6553dbc3fc905542b2
5
5
  SHA512:
6
- metadata.gz: 72e214c3bca3382997cc389f36eb92747a96323ef141f255154aff068b20c9e5488fe24de4a028bbcb67a6d4c8d457713d078c6c5a70d8be08c311e3402363f4
7
- data.tar.gz: f570a34ca2014691e28f95c758a204a82f3953118deccc89b22650476fc32ca7f5cf7a003758023796f2deccb980fbb609cfd0f99a141cafd027c06f8293ef18
6
+ metadata.gz: 7fefe63cc01a8977e73b6f4f758aee060afe88f6c9706effda0e61ec0ab4cf38a21fa5a825e2ccf7420940a17d3712c91ac2e9a9a5268040d897dae24df55197
7
+ data.tar.gz: 03a089117cb9d969c68e38fb91904983dd978c459a33e8d0a03264355852e3716044fd85e280f5f9d62d54445332e516f4a0d0f324178305d8d988dd8ca3365a
@@ -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 = @follow_ups.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 = @follow_ups.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 = ['#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)+1],
86
- borderColor: colors[sale_names.index(name)+1],
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)+1],
112
- borderColor: colors[sale_names.index(name)+1],
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)+1],
136
- borderColor: colors[sale_names.index(name)+1],
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)%10],
176
- pointBackgroundColor: colors[names.index(name)%10],
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)%10],
193
- pointBackgroundColor: colors[names.index(name)%10],
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)%10],
210
- pointBackgroundColor: colors[names.index(name)%10],
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)
@@ -50,7 +52,17 @@ module EducodeSales
50
52
  @teachers = Teacher.where(is_key: false)
51
53
  end
52
54
  end
53
-
55
+
56
+ public_teacher_ids = EducodeSales::Teacher.where(staff_id: 0).pluck(:id) - EducodeSales::TeacherAssignFollow.all.pluck(:Teacher_id)
57
+ teacher_ids = @teachers.ids
58
+ teacher_ids = teacher_ids + public_teacher_ids + EducodeSales::TeacherAssignFollow.where(staff_id: @current_admin.id).pluck(:teacher_id)
59
+ @teachers = @teachers.where(id: teacher_ids)
60
+
61
+ if params[:q].present? && params[:q][:assist].present?
62
+ staff_id = params[:q][:assist].to_i
63
+ teacher_ids = EducodeSales::TeacherAssignFollow.where(staff_id: staff_id).pluck(:teacher_id)
64
+ @teachers = @teachers.where(id: teacher_ids)
65
+ end
54
66
  if params[:q].present? && params[:q][:name].present?
55
67
  @teachers = @teachers.where("educode_sales_teachers.name like ?", "%#{params[:q][:name]}%")
56
68
  end
@@ -60,6 +72,13 @@ module EducodeSales
60
72
  if params[:q].present? && params[:q][:regist_at].present?
61
73
  @teachers = @teachers.where("educode_sales_teachers.regist_at like ?", "%#{params[:q][:regist_at]}%")
62
74
  end
75
+ if params[:q].present? && params[:q][:status].present?
76
+ if params[:q][:status] == "1"
77
+ @teachers = @teachers.where("educode_sales_teachers.regist_at is not null AND educode_sales_teachers.user_id is not null")
78
+ else
79
+ @teachers = @teachers.where("educode_sales_teachers.regist_at is null OR educode_sales_teachers.user_id is null")
80
+ end
81
+ end
63
82
  if params[:q].present? && params[:q][:attitude].present?
64
83
  # @teachers = @teachers.where("educode_sales_teachers.attitude_id = ?", "#{params[:q][:attitude]}")
65
84
  @teachers = @teachers.joins("
@@ -105,6 +124,9 @@ module EducodeSales
105
124
  def create
106
125
  department = Department.find(params[:department_id])
107
126
  teacher = @current_admin.teachers.build(teacher_params)
127
+ params[:teacher_assist].each do |d|
128
+ teacher.teacher_assign_follows.build(staff_id: d)
129
+ end
108
130
  teacher.department_id = department.id
109
131
  if params[:user_id].present?
110
132
  user = User.find(params[:user_id])
@@ -147,6 +169,13 @@ module EducodeSales
147
169
  teacher = Teacher.find(params[:id])
148
170
  teacher.department_id = department.id
149
171
  teacher.assign_attributes(teacher_params)
172
+
173
+ teacher_assists = []
174
+ params[:teacher_assist].each do |d|
175
+ teacher_assists << teacher.teacher_assign_follows.find_or_initialize_by(staff_id: d)
176
+ end
177
+ teacher.teacher_assign_follows = teacher_assists
178
+
150
179
  if params[:user_id].present?
151
180
  user = User.find(params[:user_id])
152
181
  teacher.user_id = user.id
@@ -171,7 +200,10 @@ module EducodeSales
171
200
  end
172
201
 
173
202
  def edit
174
- @teacher = Teacher.find(params[:id])
203
+ load_teacher
204
+ gon.teacher_assist = @teacher.teacher_assign_follows.map do |d|
205
+ {value: d.staff_id, name: d.staff.user.full_name}
206
+ end
175
207
  gon.department = { value: @teacher.department_id, name: "#{@teacher.department&.school&.name}-#{@teacher.department&.name}" }
176
208
  gon.value = @teacher.department_id
177
209
  render layout: false
@@ -256,17 +288,6 @@ module EducodeSales
256
288
  render layout: false
257
289
  end
258
290
 
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
291
  def show_follow_record
271
292
  @follow_up = TeacherFollow.find(params[:id])
272
293
  render layout: false
@@ -294,7 +315,7 @@ module EducodeSales
294
315
 
295
316
  private
296
317
  def teacher_params
297
- params.permit(:name, :professional_title, :job, :source_id)
318
+ params.permit(:name, :professional_title, :job, :source_id, :wechat)
298
319
  end
299
320
 
300
321
  def load_teacher
@@ -20,46 +20,46 @@ module EducodeSales
20
20
  end
21
21
 
22
22
  def create
23
- folder = edu_setting('attachment_folder')
24
- upload_file = params["file"]
25
- raise "未上传文件" unless upload_file
26
- save_path = File.join(folder)
27
- ext = file_ext(upload_file.original_filename)
28
- local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext)
29
- content_type = upload_file.content_type.presence || 'application/octet-stream'
30
- disk_filename = local_path[save_path.size + 1, local_path.size]
31
- @attachment = Attachment.where(disk_filename: disk_filename,
32
- author_id: @current_admin.id).first
33
- if @attachment.blank?
34
- @attachment = Attachment.new
35
- @attachment.filename = upload_file.original_filename
36
- @attachment.description = "business"
37
- @attachment.disk_filename = local_path[save_path.size + 1, local_path.size]
38
- @attachment.filesize = upload_file.tempfile.size
39
- @attachment.content_type = content_type
40
- @attachment.digest = digest
41
- @attachment.author_id = @current_admin.id
42
- @attachment.container_id = params[:business_id]
43
- @attachment.save!
44
- else
45
- logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}"
46
- end
47
- render_success
23
+ folder = File.join(Rails.root, "public", "files", 'educode_sales')
24
+ upload_file = params["file"]
25
+ raise "未上传文件" unless upload_file
26
+ save_path = File.join(folder)
27
+ ext = file_ext(upload_file.original_filename)
28
+ local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext)
29
+ content_type = upload_file.content_type.presence || 'application/octet-stream'
30
+ disk_filename = local_path[save_path.size + 1, local_path.size]
31
+ @attachment = Attachment.where(disk_filename: disk_filename,
32
+ author_id: @current_admin.user_id).first
33
+ if @attachment.blank?
34
+ @attachment = Attachment.new
35
+ @attachment.filename = upload_file.original_filename
36
+ @attachment.description = "business"
37
+ @attachment.disk_filename = local_path[save_path.size + 1, local_path.size]
38
+ @attachment.filesize = upload_file.tempfile.size
39
+ @attachment.content_type = content_type
40
+ @attachment.digest = digest
41
+ @attachment.author_id = @current_admin.user_id
42
+ @attachment.container_id = params[:business_id]
43
+ @attachment.save!
44
+ else
45
+ logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}"
46
+ end
47
+ render_success
48
48
  end
49
49
 
50
50
  def destroy
51
- folder = edu_setting('attachment_folder')
51
+ folder = File.join(Rails.root, "public", "files", 'educode_sales')
52
52
  file = Attachment.find(params[:id])
53
53
  file.destroy
54
- File.delete(folder.to_s + '/' + file.disk_filename) if FileTest::exist?(folder.to_s + '/' + file.disk_filename)
54
+ File.delete(folder + "/" +file.disk_filename) if FileTest::exist?(folder + "/" +file.disk_filename)
55
55
  render_success
56
56
  end
57
57
 
58
58
  def download
59
- folder = edu_setting('attachment_folder')
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
- send_file(folder.to_s + '/' + file.disk_filename, filename: file.title, stream: true, type: file.content_type.presence || 'application/octet-stream')
62
+ send_file(folder + "/" +file.disk_filename, filename: file.title, stream: true, type: file.content_type.presence || 'application/octet-stream')
63
63
  end
64
64
 
65
65
  def edu_setting name
@@ -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>