educode_sales 0.7.0 → 0.7.3

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 (52) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/educode_sales/businesses_controller.rb +19 -3
  3. data/app/controllers/educode_sales/follow_ups_controller.rb +15 -3
  4. data/app/controllers/educode_sales/money_plans_controller.rb +2 -2
  5. data/app/controllers/educode_sales/operation_plans_controller.rb +5 -2
  6. data/app/controllers/educode_sales/plans_controller.rb +3 -2
  7. data/app/controllers/educode_sales/results_controller.rb +54 -0
  8. data/app/controllers/educode_sales/sale_trends_controller.rb +116 -116
  9. data/app/controllers/educode_sales/staffs_controller.rb +2 -0
  10. data/app/helpers/educode_sales/follow_up_helper.rb +7 -0
  11. data/app/models/educode_sales/money_plan.rb +3 -3
  12. data/app/models/educode_sales/result.rb +4 -0
  13. data/app/views/educode_sales/businesses/edit_follow_record.html.erb +150 -114
  14. data/app/views/educode_sales/businesses/edit_plan.html.erb +4 -4
  15. data/app/views/educode_sales/businesses/export_records.json.jbuilder +1 -2
  16. data/app/views/educode_sales/businesses/get_export_data.json.jbuilder +2 -1
  17. data/app/views/educode_sales/businesses/index.html.erb +132 -109
  18. data/app/views/educode_sales/businesses/index.json.jbuilder +3 -2
  19. data/app/views/educode_sales/businesses/new_follow_record.html.erb +156 -119
  20. data/app/views/educode_sales/businesses/show_follow.html.erb +37 -25
  21. data/app/views/educode_sales/businesses/show_follow.json.jbuilder +2 -0
  22. data/app/views/educode_sales/businesses/show_follow_record.html.erb +8 -1
  23. data/app/views/educode_sales/customers/index.html.erb +1 -2
  24. data/app/views/educode_sales/customers/show_follow.html.erb +1 -1
  25. data/app/views/educode_sales/follow_ups/index.json.jbuilder +1 -1
  26. data/app/views/educode_sales/follow_ups/money_plans.json.jbuilder +2 -4
  27. data/app/views/educode_sales/money_plans/index.html.erb +1 -1
  28. data/app/views/educode_sales/operation_plans/_monthPlan.html.erb +8 -3
  29. data/app/views/educode_sales/operation_plans/_monthly.html.erb +2 -2
  30. data/app/views/educode_sales/operation_plans/_weekPlan.html.erb +2 -2
  31. data/app/views/educode_sales/operation_plans/_weekly.html.erb +2 -2
  32. data/app/views/educode_sales/plans/_monthPlan.html.erb +8 -3
  33. data/app/views/educode_sales/plans/_monthly.html.erb +2 -2
  34. data/app/views/educode_sales/plans/_weekPlan.html.erb +2 -2
  35. data/app/views/educode_sales/plans/_weekly.html.erb +2 -2
  36. data/app/views/educode_sales/results/edit.html.erb +111 -0
  37. data/app/views/educode_sales/results/index.html.erb +0 -0
  38. data/app/views/educode_sales/results/index.json.jbuilder +13 -0
  39. data/app/views/educode_sales/results/new.html.erb +58 -0
  40. data/app/views/educode_sales/results/show.json.jbuilder +9 -0
  41. data/app/views/educode_sales/roles/edit.html.erb +1 -1
  42. data/app/views/educode_sales/sale_reports/audit.html.erb +2 -0
  43. data/app/views/educode_sales/sale_reports/edit.html.erb +2 -0
  44. data/app/views/educode_sales/sale_reports/show.html.erb +2 -0
  45. data/app/views/educode_sales/sales/index.html.erb +7 -7
  46. data/app/views/educode_sales/teachers/show_follow.html.erb +1 -1
  47. data/app/views/layouts/educode_sales/application.html.erb +9 -3
  48. data/config/routes.rb +7 -1
  49. data/db/migrate/20220314053856_add_service_start_time_to_follow_ups.rb +6 -0
  50. data/db/migrate/20220314074354_add_service_time_long_to_follow_ups.rb +5 -0
  51. data/lib/educode_sales/version.rb +1 -1
  52. metadata +12 -2
@@ -8,14 +8,14 @@ module EducodeSales
8
8
  # authorize! :trends, EducodeSales::SaleTrend
9
9
  @year = params[:year] ? params[:year] : Time.now.year
10
10
  @years = ['全部'] + (1..(Time.now.year - 2014)).reverse_each.map { |d| 2014 + d }
11
- if(@year == '全部')
11
+ if (@year == '全部')
12
12
  x = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
13
13
  o = Common.find_by(extras: EducodeSales::Common::OTYPE)&.id
14
14
  @business_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).sum(:total_amount).round(2)
15
- stage_ids = Common.where(clazz: '商机阶段', name: ['已中标','已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
15
+ stage_ids = Common.where(clazz: '商机阶段', name: ['已中标', '已签单', '已验收', '回款中', '服务中', '已结束']).pluck(:id)
16
16
  @goal_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.stage_id IN (?)", stage_ids).sum(:total_amount).round(2)
17
17
  @actual_goal_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.stage_id IN (?)", stage_ids).sum(:actual_amount).round(2)
18
- s_stage_ids = Common.where(clazz: '商机阶段', name: ['已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
18
+ s_stage_ids = Common.where(clazz: '商机阶段', name: ['已签单', '已验收', '回款中', '服务中', '已结束']).pluck(:id)
19
19
  @service_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.stage_id IN (?)", s_stage_ids).sum(:total_amount).round(2)
20
20
  @actual_service_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.stage_id IN (?)", s_stage_ids).sum(:actual_amount).round(2)
21
21
  @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).sum(:amount).round(2)
@@ -29,62 +29,63 @@ module EducodeSales
29
29
  x = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
30
30
  o = Common.find_by(extras: EducodeSales::Common::OTYPE)&.id
31
31
  @sale_trend = SaleTrend.find_or_create_by(year: @year)
32
- @business_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.year = ?",@year).sum(:total_amount).round(2)
33
- stage_ids = Common.where(clazz: '商机阶段', name: ['已中标','已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
32
+ @business_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.year = ?", @year).sum(:total_amount).round(2)
33
+ stage_ids = Common.where(clazz: '商机阶段', name: ['已中标', '已签单', '已验收', '回款中', '服务中', '已结束']).pluck(:id)
34
34
  @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)
35
35
  @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)
36
- s_stage_ids = Common.where(clazz: '商机阶段', name: ['已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
36
+ s_stage_ids = Common.where(clazz: '商机阶段', name: ['已签单', '已验收', '回款中', '服务中', '已结束']).pluck(:id)
37
37
  @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)
38
38
  @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)
39
39
  @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)
40
40
  a = Common.where(clazz: '商机类型', name: Common.find_by(extras: EducodeSales::Common::ATYPE)&.name).pluck(:id)
41
- @a_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id IN (?)", a).where("educode_sales_follow_ups.year = ?",@year).sum(:total_amount).round(2)
41
+ @a_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id IN (?)", a).where("educode_sales_follow_ups.year = ?", @year).sum(:total_amount).round(2)
42
42
  b = Common.where(clazz: '商机类型', name: Common.find_by(extras: EducodeSales::Common::BTYPE)&.name).pluck(:id)
43
- @b_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id IN (?)", b).where("educode_sales_follow_ups.year = ?",@year).sum(:total_amount).round(2)
43
+ @b_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id IN (?)", b).where("educode_sales_follow_ups.year = ?", @year).sum(:total_amount).round(2)
44
44
  end
45
45
 
46
46
  count_type = params[:count_type] || "actual_amount"
47
47
  common = Common.find_by(clazz: 'staff_type', name: '销售')
48
48
  names = Staff.includes(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id] }
49
49
  x_business_ids = []
50
- default_dates = (30.day.ago.to_date..Date.today).map { |d| d.strftime("%Y-%W")}.uniq #默认时间范围
50
+ default_dates = (30.day.ago.to_date..Date.today).map { |d| d.strftime("%Y-%W") }.uniq #默认时间范围
51
51
  Business.all.each do |d|
52
52
  if d.last_follow_up&.clazz&.id == x
53
53
  x_business_ids << d.id
54
54
  end
55
55
  end
56
- 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)']
56
+ 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)']
57
57
  @follow_count_range = params[:follow_count_range] || "week"
58
58
  @goal_count_range = params[:goal_count_range] || "month"
59
59
  # 商机跟进数图表
60
- @follow_count_data = week_follow_count_chart(default_dates,names,x_business_ids,colors)
60
+ @follow_count_data = week_follow_count_chart(default_dates, names, x_business_ids, colors)
61
61
  if params[:follow_count_range].present?
62
62
  case params[:follow_count_range]
63
- when "week" #按周
63
+ when "week" #按周
64
64
  if params[:date_week].present?
65
65
  date = params[:date_week].split(" - ")
66
66
  dates = (date[0].to_date..date[1].to_date).map { |d|
67
- d.strftime("%Y-%W")}.uniq
68
- @follow_count_data = week_follow_count_chart(dates,names,x_business_ids,colors)
67
+ d.strftime("%Y-%W") }.uniq
68
+ @follow_count_data = week_follow_count_chart(dates, names, x_business_ids, colors)
69
69
  end
70
- when "month" #按月
70
+ when "month" #按月
71
71
  if params[:date_month].present?
72
72
  # (Date.new(2020,12,1)..Date.new(2021,12,1)).map { |d| d.strftime("%Y-%m")}.uniq
73
73
  date = params[:date_month].split(" - ")
74
- dates = ((date[0]+"-01").to_date..(date[1]+"-01").to_date).map { |d| d.strftime("%Y-%m")}.uniq
75
- @follow_count_data = month_follow_count_chart(dates,names,x_business_ids,colors)
74
+ dates = ((date[0] + "-01").to_date..(date[1] + "-01").to_date).map { |d| d.strftime("%Y-%m") }.uniq
75
+ @follow_count_data = month_follow_count_chart(dates, names, x_business_ids, colors)
76
76
  end
77
- when "year" #按年
77
+ when "year" #按年
78
78
  if params[:date_year].present?
79
79
  date = params[:date_year].split(" - ")
80
80
  dates = (date[0]..date[1]).to_a
81
- @follow_count_data = year_follow_count_chart(dates,names,x_business_ids,colors)
81
+ @follow_count_data = year_follow_count_chart(dates, names, x_business_ids, colors)
82
82
  end
83
- else #按天
83
+ else
84
+ #按天
84
85
  if params[:date].present?
85
86
  date = params[:date].split(" - ")
86
87
  dates = (date[0].to_date..date[1].to_date).to_a
87
- @follow_count_data = day_follow_count_chart(dates,names,x_business_ids,colors)
88
+ @follow_count_data = day_follow_count_chart(dates, names, x_business_ids, colors)
88
89
  end
89
90
  end
90
91
  end
@@ -92,12 +93,12 @@ module EducodeSales
92
93
  #商机区域分布图表
93
94
  provinces = EducodeSales::Common.where(clazz: 'area').pluck(:name)
94
95
  if params[:business_count_type] == 'money' || params[:business_count_type].blank?
95
- @business_data = {
96
+ @business_data = {
96
97
  labels: provinces,
97
- datasets:[
98
+ datasets: [
98
99
  {
99
100
  label: "商机总额",
100
- data: provinces.map{|province|
101
+ data: provinces.map { |province|
101
102
  if params[:business_type].blank?
102
103
  Business.joins(:last_follow_up).where("educode_sales_businesses.department_id in (?)", School.joins(:departments).where(province: province).pluck("departments.id")).where("educode_sales_follow_ups.clazz_id != ?", x).sum(:total_amount).round(2)
103
104
  else
@@ -111,12 +112,12 @@ module EducodeSales
111
112
  ]
112
113
  }
113
114
  else
114
- @business_data = {
115
+ @business_data = {
115
116
  labels: provinces,
116
- datasets:[
117
+ datasets: [
117
118
  {
118
119
  label: "商机数量",
119
- data: provinces.map{|province|
120
+ data: provinces.map { |province|
120
121
  if params[:business_type].blank?
121
122
  Business.joins(:last_follow_up).where("educode_sales_businesses.department_id in (?)", School.joins(:departments).where(province: province).pluck("departments.id")).where("educode_sales_follow_ups.clazz_id != ?", x).count
122
123
  else
@@ -131,8 +132,6 @@ module EducodeSales
131
132
  }
132
133
  end
133
134
 
134
-
135
-
136
135
  # 销售人员跟进分析
137
136
  begin_time = Time.now.at_beginning_of_year.to_s
138
137
  end_time = Time.now.at_end_of_year.to_s
@@ -166,18 +165,16 @@ module EducodeSales
166
165
  end_time = date[1] + "23:59:59"
167
166
  end
168
167
  end
169
- 100.times{p begin_time}
170
- 100.times{p end_time}
171
168
  common = Common.find_by(clazz: 'staff_type', name: '销售')
172
- staff_names = Staff.joins(:user).where(job_type: common.id).map { |d| d.user.real_name}
169
+ staff_names = Staff.joins(:user).where(job_type: common.id).map { |d| d.user.real_name }
173
170
  staff_ids = Staff.joins(:user).where(job_type: common.id).pluck(:id)
174
171
  if params[:customer_count_type] == 'money' || params[:customer_count_type].blank?
175
- @customer_data = {
172
+ @customer_data = {
176
173
  labels: staff_names,
177
- datasets:[
174
+ datasets: [
178
175
  {
179
176
  label: "跟进客户数",
180
- data: staff_ids.map{|staff_id|
177
+ data: staff_ids.map { |staff_id|
181
178
  (EducodeSales::CustomerFollow.where(staff_id: staff_id).where("created_at >= ? AND created_at <= ?", begin_time, end_time).pluck(:school_id) + EducodeSales::Business.where(id: EducodeSales::FollowUp.where(staff_id: staff_id).where("created_at >= ? AND created_at <= ?", begin_time, end_time).pluck(:business_id).uniq).pluck(:school_id)).uniq.size
182
179
  },
183
180
  backgroundColor: colors[0],
@@ -187,12 +184,12 @@ module EducodeSales
187
184
  ]
188
185
  }
189
186
  else
190
- @customer_data = {
187
+ @customer_data = {
191
188
  labels: staff_names,
192
- datasets:[
189
+ datasets: [
193
190
  {
194
191
  label: "跟进客户次数",
195
- data: staff_ids.map{|staff_id|
192
+ data: staff_ids.map { |staff_id|
196
193
  EducodeSales::CustomerFollow.where(staff_id: staff_id).where("created_at >= ? AND created_at <= ?", begin_time, end_time).size + EducodeSales::FollowUp.where(staff_id: staff_id).where("created_at >= ? AND created_at <= ?", begin_time, end_time).size
197
194
  },
198
195
  backgroundColor: colors[0],
@@ -203,26 +200,25 @@ module EducodeSales
203
200
  }
204
201
  end
205
202
 
206
-
207
-
208
- # 已中标图表
209
- goal_default_dates = ("#{Time.now.year}-01".."#{Time.now.year}-#{Time.now.month}").to_a
210
- sale_names = ['已中标','已签单','已回款']
211
- @goal_count_data = month_sale_chart(goal_default_dates,sale_names,colors,x,stage_ids,s_stage_ids,count_type)
203
+ # 销售额分析
204
+ goal_default_dates = ("#{Time.now.year}-01-01".to_date.."#{Time.now.year}-#{Time.now.month}-01".to_date).map { |d| d.strftime("%Y-%m") }.uniq
205
+ sale_names = ['已中标', '已签单', '已回款']
206
+ @goal_count_data = month_sale_chart(goal_default_dates, sale_names, colors, x, stage_ids, s_stage_ids, count_type)
212
207
  if params[:goal_count_range].present?
213
208
  case params[:goal_count_range]
214
209
  when "week"
215
- when "month" #按月
210
+ when "month" #按月
216
211
  if params[:goal_date_month].present?
217
212
  date = params[:goal_date_month].split(" - ")
218
- dates = ((date[0]+"-01").to_date..(date[1]+"-01").to_date).map { |d| d.strftime("%Y-%m")}.uniq
219
- @goal_count_data = month_sale_chart(dates,sale_names,colors,x,stage_ids,s_stage_ids,count_type)
213
+ dates = ((date[0] + "-01").to_date..(date[1] + "-01").to_date).map { |d| d.strftime("%Y-%m") }.uniq
214
+ @goal_count_data = month_sale_chart(dates, sale_names, colors, x, stage_ids, s_stage_ids, count_type)
220
215
  end
221
- else #按年
216
+ else
217
+ #按年
222
218
  if params[:goal_date_year].present?
223
219
  date = params[:goal_date_year].split(" - ")
224
220
  dates = (date[0]..date[1]).to_a
225
- @goal_count_data = year_sale_chart(dates,sale_names,colors,x,stage_ids,s_stage_ids,count_type)
221
+ @goal_count_data = year_sale_chart(dates, sale_names, colors, x, stage_ids, s_stage_ids, count_type)
226
222
  end
227
223
  end
228
224
  end
@@ -247,140 +243,144 @@ module EducodeSales
247
243
  params.permit(:chance_money, :ballot_money, :sign_money, :returned_money)
248
244
  end
249
245
 
250
- def day_follow_count_chart(dates,names,x_business_ids,colors)
246
+ def day_follow_count_chart(dates, names, x_business_ids, colors)
251
247
  {
252
248
  labels: dates,
253
- datasets:names.map.with_index do |name,i|
249
+ datasets: names.map.with_index do |name, i|
254
250
  {
255
251
  # hidden: i < 3 ? false : true,
256
252
  label: name[0],
257
- 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 },
253
+ 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 },
258
254
  backgroundColor: "#fff",
259
- pointBorderColor: colors[i%15+1],
260
- borderColor: colors[i%15+1],
261
- pointBackgroundColor: colors[i%15+1],
255
+ pointBorderColor: colors[i % 15 + 1],
256
+ borderColor: colors[i % 15 + 1],
257
+ pointBackgroundColor: colors[i % 15 + 1],
262
258
  borderWidth: 2
263
259
  }
264
260
  end
265
261
  }
266
262
  end
267
- def week_follow_count_chart(dates,names,x_business_ids,colors)
263
+
264
+ def week_follow_count_chart(dates, names, x_business_ids, colors)
268
265
  {
269
- labels: dates.map{ |date|
266
+ labels: dates.map { |date|
270
267
  d = date.split("-")
271
268
  year = d[0].to_i
272
269
  week = d[1].to_i
273
270
  if week == 0
274
271
  0
275
272
  else
276
- month = Date.commercial(year,week).strftime("%m月%d日")
277
- day = Date.commercial(year,week,7).strftime("%m月%d日")
273
+ month = Date.commercial(year, week).strftime("%m月%d日")
274
+ day = Date.commercial(year, week, 7).strftime("%m月%d日")
278
275
  date.to_s + "(#{month}-#{day})"
279
276
  end
280
277
  } - [0],
281
- datasets:names.map.with_index do |name,i|
278
+ datasets: names.map.with_index do |name, i|
282
279
  {
283
280
  # hidden: i < 3 ? false : true,
284
281
  label: name[0],
285
- data: dates.map{ |d|
282
+ data: dates.map { |d|
286
283
  d = d.split("-")
287
284
  year = d[0].to_i
288
285
  week = d[1].to_i
289
- if week == 0
290
- @follow_up = 999999
291
- else
292
- @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
293
- end
294
- } - [999999],
286
+ if week == 0
287
+ @follow_up = 999999
288
+ else
289
+ @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
290
+ end
291
+ } - [999999],
295
292
  backgroundColor: "#fff",
296
- pointBorderColor: colors[i%15+1],
297
- borderColor: colors[i%15+1],
298
- pointBackgroundColor: colors[i%15+1],
293
+ pointBorderColor: colors[i % 15 + 1],
294
+ borderColor: colors[i % 15 + 1],
295
+ pointBackgroundColor: colors[i % 15 + 1],
299
296
  borderWidth: 2
300
297
  }
301
298
  end
302
299
  }
303
300
  end
304
- def month_follow_count_chart(dates,names,x_business_ids,colors)
301
+
302
+ def month_follow_count_chart(dates, names, x_business_ids, colors)
305
303
  {
306
304
  labels: dates,
307
- datasets:names.map.with_index do |name,i|
305
+ datasets: names.map.with_index do |name, i|
308
306
  {
309
307
  # hidden: i < 3 ? false : true,
310
308
  label: name[0],
311
- 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 },
309
+ 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 },
312
310
  backgroundColor: "#fff",
313
- pointBorderColor: colors[i%15+1],
314
- borderColor: colors[i%15+1],
315
- pointBackgroundColor: colors[i%15+1],
311
+ pointBorderColor: colors[i % 15 + 1],
312
+ borderColor: colors[i % 15 + 1],
313
+ pointBackgroundColor: colors[i % 15 + 1],
316
314
  borderWidth: 2,
317
315
  }
318
316
  end
319
317
  }
320
318
  end
321
- def year_follow_count_chart(dates,names,x_business_ids,colors)
319
+
320
+ def year_follow_count_chart(dates, names, x_business_ids, colors)
322
321
  {
323
322
  labels: dates,
324
- datasets:names.map.with_index do |name,i|
323
+ datasets: names.map.with_index do |name, i|
325
324
  {
326
325
  # hidden: i < 3 ? false : true,
327
326
  label: name[0],
328
- 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 },
327
+ 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 },
329
328
  backgroundColor: "#fff",
330
- pointBorderColor: colors[i%15+1],
331
- borderColor: colors[i%15+1],
332
- pointBackgroundColor: colors[i%15+1],
329
+ pointBorderColor: colors[i % 15 + 1],
330
+ borderColor: colors[i % 15 + 1],
331
+ pointBackgroundColor: colors[i % 15 + 1],
333
332
  borderWidth: 2
334
333
  }
335
334
  end
336
335
  }
337
336
  end
338
337
 
339
- def month_sale_chart(dates,names,colors,x,stage_ids,s_stage_ids,count_type)
338
+ def month_sale_chart(dates, names, colors, x, stage_ids, s_stage_ids, count_type)
340
339
  {
341
340
  labels: dates,
342
- datasets: names.map.with_index do |name,i|{
343
- label: name,
344
- data: dates.map{ |d|
345
- case i
346
- when 0
347
- 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)
348
- when 1
349
- 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)
350
- else
351
- 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)
352
- end
353
- },
354
- backgroundColor: colors[i],
355
- borderColor: colors[i],
356
- borderWidth: 1
357
- }
341
+ datasets: names.map.with_index do |name, i|
342
+ {
343
+ label: name,
344
+ data: dates.map { |d|
345
+ case i
346
+ when 0
347
+ 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)
348
+ when 1
349
+ 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)
350
+ else
351
+ 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)
352
+ end
353
+ },
354
+ backgroundColor: colors[i],
355
+ borderColor: colors[i],
356
+ borderWidth: 1
357
+ }
358
358
  end
359
359
  }
360
360
  end
361
361
 
362
- def year_sale_chart(dates,names,colors,x,stage_ids,s_stage_ids,count_type)
362
+ def year_sale_chart(dates, names, colors, x, stage_ids, s_stage_ids, count_type)
363
363
  {
364
364
  labels: dates,
365
- datasets:names.map.with_index do |name,i| {
366
- label: name,
367
- data: dates.map{ |d|
368
- case i
369
- when 0
370
- 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)
371
- when 1
372
- 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)
373
- else
374
- 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)
375
- end },
376
- backgroundColor: colors[i],
377
- borderColor: colors[i],
378
- borderWidth: 1
379
- }
365
+ datasets: names.map.with_index do |name, i|
366
+ {
367
+ label: name,
368
+ data: dates.map { |d|
369
+ case i
370
+ when 0
371
+ 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)
372
+ when 1
373
+ 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)
374
+ else
375
+ 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)
376
+ end },
377
+ backgroundColor: colors[i],
378
+ borderColor: colors[i],
379
+ borderWidth: 1
380
+ }
380
381
  end
381
382
  }
382
383
  end
383
384
 
384
-
385
385
  end
386
386
  end
@@ -86,6 +86,8 @@ module EducodeSales
86
86
  params[:school_ids].each do |d|
87
87
  staff.staff_schools.create(school_id: d)
88
88
  end
89
+ else
90
+ staff.staff_schools.destroy_all
89
91
  end
90
92
  if staff.save
91
93
  render_success
@@ -0,0 +1,7 @@
1
+ module EducodeSales
2
+ module FollowUpHelper
3
+ def key_people(teacher_ids)
4
+ EducodeSales::Teacher.where(id: teacher_ids).pluck(:name).join('、')
5
+ end
6
+ end
7
+ end
@@ -3,7 +3,7 @@ module EducodeSales
3
3
  belongs_to :staff
4
4
  belongs_to :follow_up, counter_cache: true
5
5
 
6
- enum clazz: ['未完成', '已完成']
6
+ enum clazz: ['计划回款', '实际回款']
7
7
 
8
8
  after_save :update_return_money
9
9
  after_destroy :update_return_money
@@ -13,9 +13,9 @@ module EducodeSales
13
13
 
14
14
  def update_return_money
15
15
  if follow_up.business.last_follow_up_id == self.follow_up_id
16
- follow_up.business.update(return_money: MoneyPlan.where(clazz: '已完成', follow_up_id: self.follow_up_id).sum(:amount))
16
+ follow_up.business.update(return_money: MoneyPlan.where(clazz: '实际回款', follow_up_id: self.follow_up_id).sum(:amount))
17
17
  else
18
- follow_up.update(return_money: follow_up.money_plans.where(clazz: '已完成').sum(:amount))
18
+ follow_up.update(return_money: follow_up.money_plans.where(clazz: '实际回款').sum(:amount))
19
19
  end
20
20
  end
21
21
  end
@@ -0,0 +1,4 @@
1
+ module EducodeSales
2
+ class Result < ApplicationRecord
3
+ end
4
+ end