educode_sales 0.7.1 → 0.7.4

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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/educode_sales/indexlogo.png +0 -0
  3. data/app/controllers/educode_sales/businesses_controller.rb +17 -2
  4. data/app/controllers/educode_sales/follow_ups_controller.rb +14 -2
  5. data/app/controllers/educode_sales/results_controller.rb +54 -0
  6. data/app/controllers/educode_sales/sale_trends_controller.rb +116 -116
  7. data/app/helpers/educode_sales/follow_up_helper.rb +7 -0
  8. data/app/models/educode_sales/money_plan.rb +3 -3
  9. data/app/models/educode_sales/result.rb +4 -0
  10. data/app/views/educode_sales/businesses/edit_follow_record.html.erb +150 -114
  11. data/app/views/educode_sales/businesses/edit_plan.html.erb +4 -4
  12. data/app/views/educode_sales/businesses/export_records.json.jbuilder +1 -2
  13. data/app/views/educode_sales/businesses/get_export_data.json.jbuilder +2 -1
  14. data/app/views/educode_sales/businesses/index.html.erb +131 -109
  15. data/app/views/educode_sales/businesses/index.json.jbuilder +3 -2
  16. data/app/views/educode_sales/businesses/new_follow_record.html.erb +156 -119
  17. data/app/views/educode_sales/businesses/show_follow.html.erb +30 -24
  18. data/app/views/educode_sales/businesses/show_follow.json.jbuilder +1 -0
  19. data/app/views/educode_sales/businesses/show_follow_record.html.erb +8 -1
  20. data/app/views/educode_sales/customers/show_follow.html.erb +1 -1
  21. data/app/views/educode_sales/follow_ups/index.json.jbuilder +1 -1
  22. data/app/views/educode_sales/follow_ups/money_plans.json.jbuilder +2 -4
  23. data/app/views/educode_sales/money_plans/index.html.erb +1 -1
  24. data/app/views/educode_sales/operation_plans/_monthPlan.html.erb +8 -3
  25. data/app/views/educode_sales/operation_plans/_monthly.html.erb +2 -2
  26. data/app/views/educode_sales/operation_plans/_weekPlan.html.erb +2 -2
  27. data/app/views/educode_sales/operation_plans/_weekly.html.erb +2 -2
  28. data/app/views/educode_sales/plans/_monthPlan.html.erb +8 -3
  29. data/app/views/educode_sales/plans/_monthly.html.erb +2 -2
  30. data/app/views/educode_sales/plans/_weekPlan.html.erb +2 -2
  31. data/app/views/educode_sales/plans/_weekly.html.erb +2 -2
  32. data/app/views/educode_sales/results/edit.html.erb +111 -0
  33. data/app/views/educode_sales/results/index.html.erb +0 -0
  34. data/app/views/educode_sales/results/index.json.jbuilder +13 -0
  35. data/app/views/educode_sales/results/new.html.erb +58 -0
  36. data/app/views/educode_sales/results/show.json.jbuilder +9 -0
  37. data/app/views/educode_sales/sale_reports/audit.html.erb +2 -0
  38. data/app/views/educode_sales/sale_reports/edit.html.erb +2 -0
  39. data/app/views/educode_sales/sale_reports/show.html.erb +2 -0
  40. data/app/views/educode_sales/sales/index.html.erb +7 -7
  41. data/app/views/educode_sales/teachers/show_follow.html.erb +1 -1
  42. data/app/views/layouts/educode_sales/application.html.erb +9 -3
  43. data/config/routes.rb +7 -1
  44. data/db/migrate/20220314053856_add_service_start_time_to_follow_ups.rb +6 -0
  45. data/db/migrate/20220314074354_add_service_time_long_to_follow_ups.rb +5 -0
  46. data/lib/educode_sales/version.rb +1 -1
  47. metadata +17 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd1dede8ec609b98a19dcd71c21bac7b6024098a7cdb8bad5c600784bd9a649e
4
- data.tar.gz: 34bdddc9c368c11588d2d9dc0a3307f8cfbc4568489f539e344b13f32bf41702
3
+ metadata.gz: e481393e6e2fb7a42757e804b0e2be3381abad943a7e860c403fe12c655571c1
4
+ data.tar.gz: dad674b1735e1cf66839f0757bc5dba844b15135339ce8fcc92ca71dc894143c
5
5
  SHA512:
6
- metadata.gz: 372e451790e777e0c9df20e7bdd9bc133e4d15351c6ae5b541c53a9761b14c2cbd5645c7517d0ae20ea4301872592fd43de82013ae90166546b5ae647b59db32
7
- data.tar.gz: f9a5c5518474de3e1aa03e2fe1fae7bbede839df9649227e1c0c0ddba1f4aaaf62e3e903c813c3115dd7d792d56e48e9c6659226cf0ed4b29169ac1198dda8a4
6
+ metadata.gz: a6d11197cb72adbfc6e98c448c38a706273fb1c5a4d5ff27c0c153bf056e01dbc4ec6051ead65b27a9796233beac8f475969a68b9921a344a64ddbbce661a481
7
+ data.tar.gz: 7e630350f05c53575453206d8a6df23601911dc982d517517fc313af9d8d1831f5f22f39c6e2058e5891c3f9adc4304cbb3bb2abc15e2bdb6281cc3c93c2e2c1
@@ -152,11 +152,16 @@ module EducodeSales
152
152
  JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
153
153
  ").where("educode_sales_follow_ups.stage_id in (?)", params[:q][:business_step].split(",").map(&:to_i))
154
154
  end
155
- if params[:q].present? && params[:q][:place_id].present?
155
+ if params[:q].present? && params[:q][:place_id].present?
156
156
  @businesses = @businesses.joins("
157
157
  JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
158
158
  ").where("educode_sales_follow_ups.place_id = ?", params[:q][:place_id])
159
159
  end
160
+ if params[:q].present? && params[:q][:business_year].present?
161
+ @businesses = @businesses.joins("
162
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
163
+ ").where("educode_sales_follow_ups.year = ?", params[:q][:business_year])
164
+ end
160
165
 
161
166
  if params[:q].present? && params[:q][:area].present?
162
167
  p = EducodeSales::Common.find(params[:q][:area]).name
@@ -193,7 +198,11 @@ module EducodeSales
193
198
  end
194
199
 
195
200
  if params[:sort].present? && params[:sort][:field]
196
- @businesses = @businesses.order("#{params[:sort][:field]} #{params[:sort][:order]}")
201
+ if params[:sort][:field] = "service_end_time"
202
+ @businesses = @businesses.order("service_time_long #{params[:sort][:order]}")
203
+ else
204
+ @businesses = @businesses.order("#{params[:sort][:field]} #{params[:sort][:order]}")
205
+ end
197
206
  else
198
207
  @businesses = @businesses.order("educode_sales_businesses.created_at desc")
199
208
  end
@@ -203,6 +212,9 @@ module EducodeSales
203
212
  @businesses = @businesses.select("
204
213
  educode_sales_businesses.*,
205
214
  last_follow.invitation_at,
215
+ last_follow.service_time_long,
216
+ last_follow.service_end_time,
217
+ last_follow.service_start_time,
206
218
  last_follow.reception_at,
207
219
  last_follow.bidded_date,
208
220
  last_follow.signed_date,
@@ -554,6 +566,9 @@ module EducodeSales
554
566
  educode_sales_businesses.*,
555
567
  last_follow.invitation_at,
556
568
  last_follow.reception_at,
569
+ last_follow.service_time_long,
570
+ last_follow.service_end_time,
571
+ last_follow.service_start_time,
557
572
  last_follow.bidded_date,
558
573
  last_follow.signed_date,
559
574
  last_follow.created_at as latest_time,
@@ -63,11 +63,17 @@ module EducodeSales
63
63
  def create
64
64
  load_business
65
65
  follow_up = @business.follow_ups.build(follow_up_params)
66
+ if params[:service_time].present?
67
+ date = params[:service_time].split(" - ")
68
+ follow_up.service_start_time = date[0]
69
+ follow_up.service_end_time = date[1]
70
+ follow_up.service_time_long = (date[1].to_date - date[0].to_date).to_i
71
+ end
66
72
  follow_up.staff = @current_admin
67
73
  params[:assign_follow_up].each do |d|
68
74
  follow_up.assign_follow_ups.build(staff_id: d)
69
75
  end
70
-
76
+
71
77
  follow_up.profit_amount = follow_up.actual_amount - (follow_up.divide_amount.to_i) if follow_up.actual_amount
72
78
  if follow_up.save
73
79
  if @business.last_follow_up.present?
@@ -95,7 +101,7 @@ module EducodeSales
95
101
  business = follow_up.business
96
102
  if follow_up.soft_destroy(@current_admin.id)
97
103
  if follow_up.id == business.last_follow_up_id
98
- business.update(last_follow_up: business.follow_ups.last, return_money: MoneyPlan.where(clazz: '已完成', follow_up_id: business.follow_ups.last&.id).sum(:amount))
104
+ business.update(last_follow_up: business.follow_ups.last, return_money: MoneyPlan.where(clazz: '实际回款', follow_up_id: business.follow_ups.last&.id).sum(:amount))
99
105
  end
100
106
  render_success
101
107
  else
@@ -106,6 +112,12 @@ module EducodeSales
106
112
  def update
107
113
  follow_up = FollowUp.find(params[:id])
108
114
  follow_up.assign_attributes(follow_up_params)
115
+ if params[:service_time].present?
116
+ date = params[:service_time].split(" - ")
117
+ follow_up.service_start_time = date[0]
118
+ follow_up.service_end_time = date[1]
119
+ follow_up.service_time_long = (date[1].to_date - date[0].to_date).to_i
120
+ end
109
121
  assign_follow_ups = []
110
122
  params[:assign_follow_up].each do |d|
111
123
  assign_follow_ups << follow_up.assign_follow_ups.find_or_initialize_by(staff_id: d)
@@ -0,0 +1,54 @@
1
+ require_dependency "educode_sales/application_controller"
2
+
3
+ module EducodeSales
4
+ class ResultsController < ApplicationController
5
+
6
+ def index
7
+ respond_to do |format|
8
+ format.html do
9
+ end
10
+ format.json do
11
+ # @commons = Common.group("clazz").page(params[:page]).per(params[:limit])
12
+ end
13
+ end
14
+ end
15
+
16
+ # def create
17
+ # common = Common.new(name: params[:name], clazz: params[:clazz])
18
+ # if common.save
19
+ # render_success
20
+ # else
21
+ # render_failure common
22
+ # end
23
+ # end
24
+ #
25
+ # def edit
26
+ # @common = Common.find(params[:id])
27
+ # render layout: false
28
+ # end
29
+ #
30
+ # def update
31
+ # common = Common.find(params[:id])
32
+ # if common.update(common_params)
33
+ # render_success
34
+ # else
35
+ # render_failure common
36
+ # end
37
+ # end
38
+ #
39
+ # def new
40
+ # render layout: false
41
+ # end
42
+ #
43
+ # def show
44
+ # commons = Common.find(params[:id])
45
+ # @commons = Common.where(clazz: commons.clazz).order('position')
46
+ # end
47
+ #
48
+ # private
49
+ #
50
+ # def common_params
51
+ # params.permit(:name, :position)
52
+ # end
53
+ end
54
+ end
@@ -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
@@ -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