educode_sales 0.6.8 → 0.7.2

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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/educode_sales/businesses_controller.rb +191 -7
  3. data/app/controllers/educode_sales/customers_controller.rb +48 -15
  4. data/app/controllers/educode_sales/follow_ups_controller.rb +2 -2
  5. data/app/controllers/educode_sales/home_controller.rb +6 -0
  6. data/app/controllers/educode_sales/money_plans_controller.rb +3 -3
  7. data/app/controllers/educode_sales/operation_plans_controller.rb +4 -1
  8. data/app/controllers/educode_sales/plans_controller.rb +2 -1
  9. data/app/controllers/educode_sales/sale_trends_controller.rb +118 -116
  10. data/app/controllers/educode_sales/staffs_controller.rb +12 -0
  11. data/app/controllers/educode_sales/teachers_controller.rb +1 -1
  12. data/app/helpers/educode_sales/follow_up_helper.rb +7 -0
  13. data/app/models/educode_sales/customer_add.rb +4 -0
  14. data/app/models/educode_sales/money_plan.rb +3 -3
  15. data/app/models/educode_sales/staff.rb +1 -0
  16. data/app/models/educode_sales/staff_school.rb +6 -0
  17. data/app/views/educode_sales/businesses/edit_plan.html.erb +4 -4
  18. data/app/views/educode_sales/businesses/export_records.json.jbuilder +1 -2
  19. data/app/views/educode_sales/businesses/get_export_data.json.jbuilder +30 -0
  20. data/app/views/educode_sales/businesses/index.html.erb +209 -100
  21. data/app/views/educode_sales/businesses/index.json.jbuilder +6 -32
  22. data/app/views/educode_sales/businesses/show_follow.html.erb +49 -8
  23. data/app/views/educode_sales/businesses/show_follow.json.jbuilder +2 -0
  24. data/app/views/educode_sales/customers/index.html.erb +30 -1
  25. data/app/views/educode_sales/customers/index.json.jbuilder +12 -0
  26. data/app/views/educode_sales/customers/new.html.erb +106 -53
  27. data/app/views/educode_sales/customers/show_follow.html.erb +1 -1
  28. data/app/views/educode_sales/follow_ups/index.json.jbuilder +1 -1
  29. data/app/views/educode_sales/follow_ups/money_plans.json.jbuilder +2 -4
  30. data/app/views/educode_sales/home/staff_schools.json.jbuilder +9 -0
  31. data/app/views/educode_sales/money_plans/index.html.erb +1 -1
  32. data/app/views/educode_sales/operation_plans/_monthPlan.html.erb +8 -3
  33. data/app/views/educode_sales/operation_plans/_monthly.html.erb +2 -2
  34. data/app/views/educode_sales/operation_plans/_weekPlan.html.erb +2 -2
  35. data/app/views/educode_sales/operation_plans/_weekly.html.erb +2 -2
  36. data/app/views/educode_sales/plans/_monthPlan.html.erb +8 -3
  37. data/app/views/educode_sales/plans/_monthly.html.erb +2 -2
  38. data/app/views/educode_sales/plans/_weekPlan.html.erb +2 -2
  39. data/app/views/educode_sales/plans/_weekly.html.erb +2 -2
  40. data/app/views/educode_sales/roles/edit.html.erb +17 -11
  41. data/app/views/educode_sales/sale_reports/audit.html.erb +2 -0
  42. data/app/views/educode_sales/sale_reports/edit.html.erb +2 -0
  43. data/app/views/educode_sales/sale_reports/show.html.erb +2 -0
  44. data/app/views/educode_sales/sale_trends/trends.html.erb +1 -1
  45. data/app/views/educode_sales/sales/index.html.erb +7 -7
  46. data/app/views/educode_sales/sales/index.json.jbuilder +1 -1
  47. data/app/views/educode_sales/staffs/edit.html.erb +46 -5
  48. data/app/views/educode_sales/staffs/index.html.erb +6 -0
  49. data/app/views/educode_sales/staffs/index.json.jbuilder +1 -0
  50. data/app/views/educode_sales/teachers/show_follow.html.erb +1 -1
  51. data/config/routes.rb +2 -0
  52. data/db/migrate/20210902064109_create_educode_sales_role_permissions.rb +5 -0
  53. data/db/migrate/20220125013811_create_educode_sales_staff_schools.rb +10 -0
  54. data/db/migrate/20220125033552_create_educode_sales_customer_adds.rb +9 -0
  55. data/lib/educode_sales/version.rb +1 -1
  56. metadata +9 -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
@@ -162,20 +161,20 @@ module EducodeSales
162
161
  when 'diy'
163
162
  if params[:customer_date].present?
164
163
  date = params[:customer_date].split(" - ")
165
- begin_time = date[0]
166
- end_time = date[1]
164
+ begin_time = date[0] + "00:00:00"
165
+ end_time = date[1] + "23:59:59"
167
166
  end
168
167
  end
169
168
  common = Common.find_by(clazz: 'staff_type', name: '销售')
170
- 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 }
171
170
  staff_ids = Staff.joins(:user).where(job_type: common.id).pluck(:id)
172
171
  if params[:customer_count_type] == 'money' || params[:customer_count_type].blank?
173
- @customer_data = {
172
+ @customer_data = {
174
173
  labels: staff_names,
175
- datasets:[
174
+ datasets: [
176
175
  {
177
176
  label: "跟进客户数",
178
- data: staff_ids.map{|staff_id|
177
+ data: staff_ids.map { |staff_id|
179
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
180
179
  },
181
180
  backgroundColor: colors[0],
@@ -185,12 +184,12 @@ module EducodeSales
185
184
  ]
186
185
  }
187
186
  else
188
- @customer_data = {
187
+ @customer_data = {
189
188
  labels: staff_names,
190
- datasets:[
189
+ datasets: [
191
190
  {
192
191
  label: "跟进客户次数",
193
- data: staff_ids.map{|staff_id|
192
+ data: staff_ids.map { |staff_id|
194
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
195
194
  },
196
195
  backgroundColor: colors[0],
@@ -201,26 +200,25 @@ module EducodeSales
201
200
  }
202
201
  end
203
202
 
204
-
205
-
206
- # 已中标图表
207
- goal_default_dates = ("#{Time.now.year}-01".."#{Time.now.year}-#{Time.now.month}").to_a
208
- sale_names = ['已中标','已签单','已回款']
209
- @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)
210
207
  if params[:goal_count_range].present?
211
208
  case params[:goal_count_range]
212
209
  when "week"
213
- when "month" #按月
210
+ when "month" #按月
214
211
  if params[:goal_date_month].present?
215
212
  date = params[:goal_date_month].split(" - ")
216
- dates = ((date[0]+"-01").to_date..(date[1]+"-01").to_date).map { |d| d.strftime("%Y-%m")}.uniq
217
- @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)
218
215
  end
219
- else #按年
216
+ else
217
+ #按年
220
218
  if params[:goal_date_year].present?
221
219
  date = params[:goal_date_year].split(" - ")
222
220
  dates = (date[0]..date[1]).to_a
223
- @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)
224
222
  end
225
223
  end
226
224
  end
@@ -245,140 +243,144 @@ module EducodeSales
245
243
  params.permit(:chance_money, :ballot_money, :sign_money, :returned_money)
246
244
  end
247
245
 
248
- def day_follow_count_chart(dates,names,x_business_ids,colors)
246
+ def day_follow_count_chart(dates, names, x_business_ids, colors)
249
247
  {
250
248
  labels: dates,
251
- datasets:names.map.with_index do |name,i|
249
+ datasets: names.map.with_index do |name, i|
252
250
  {
253
251
  # hidden: i < 3 ? false : true,
254
252
  label: name[0],
255
- 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 },
256
254
  backgroundColor: "#fff",
257
- pointBorderColor: colors[i%15+1],
258
- borderColor: colors[i%15+1],
259
- pointBackgroundColor: colors[i%15+1],
255
+ pointBorderColor: colors[i % 15 + 1],
256
+ borderColor: colors[i % 15 + 1],
257
+ pointBackgroundColor: colors[i % 15 + 1],
260
258
  borderWidth: 2
261
259
  }
262
260
  end
263
261
  }
264
262
  end
265
- def week_follow_count_chart(dates,names,x_business_ids,colors)
263
+
264
+ def week_follow_count_chart(dates, names, x_business_ids, colors)
266
265
  {
267
- labels: dates.map{ |date|
266
+ labels: dates.map { |date|
268
267
  d = date.split("-")
269
268
  year = d[0].to_i
270
269
  week = d[1].to_i
271
270
  if week == 0
272
271
  0
273
272
  else
274
- month = Date.commercial(year,week).strftime("%m月%d日")
275
- 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日")
276
275
  date.to_s + "(#{month}-#{day})"
277
276
  end
278
277
  } - [0],
279
- datasets:names.map.with_index do |name,i|
278
+ datasets: names.map.with_index do |name, i|
280
279
  {
281
280
  # hidden: i < 3 ? false : true,
282
281
  label: name[0],
283
- data: dates.map{ |d|
282
+ data: dates.map { |d|
284
283
  d = d.split("-")
285
284
  year = d[0].to_i
286
285
  week = d[1].to_i
287
- if week == 0
288
- @follow_up = 999999
289
- else
290
- @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
291
- end
292
- } - [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],
293
292
  backgroundColor: "#fff",
294
- pointBorderColor: colors[i%15+1],
295
- borderColor: colors[i%15+1],
296
- pointBackgroundColor: colors[i%15+1],
293
+ pointBorderColor: colors[i % 15 + 1],
294
+ borderColor: colors[i % 15 + 1],
295
+ pointBackgroundColor: colors[i % 15 + 1],
297
296
  borderWidth: 2
298
297
  }
299
298
  end
300
299
  }
301
300
  end
302
- def month_follow_count_chart(dates,names,x_business_ids,colors)
301
+
302
+ def month_follow_count_chart(dates, names, x_business_ids, colors)
303
303
  {
304
304
  labels: dates,
305
- datasets:names.map.with_index do |name,i|
305
+ datasets: names.map.with_index do |name, i|
306
306
  {
307
307
  # hidden: i < 3 ? false : true,
308
308
  label: name[0],
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 },
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 },
310
310
  backgroundColor: "#fff",
311
- pointBorderColor: colors[i%15+1],
312
- borderColor: colors[i%15+1],
313
- pointBackgroundColor: colors[i%15+1],
311
+ pointBorderColor: colors[i % 15 + 1],
312
+ borderColor: colors[i % 15 + 1],
313
+ pointBackgroundColor: colors[i % 15 + 1],
314
314
  borderWidth: 2,
315
315
  }
316
316
  end
317
317
  }
318
318
  end
319
- def year_follow_count_chart(dates,names,x_business_ids,colors)
319
+
320
+ def year_follow_count_chart(dates, names, x_business_ids, colors)
320
321
  {
321
322
  labels: dates,
322
- datasets:names.map.with_index do |name,i|
323
+ datasets: names.map.with_index do |name, i|
323
324
  {
324
325
  # hidden: i < 3 ? false : true,
325
326
  label: name[0],
326
- 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 },
327
328
  backgroundColor: "#fff",
328
- pointBorderColor: colors[i%15+1],
329
- borderColor: colors[i%15+1],
330
- pointBackgroundColor: colors[i%15+1],
329
+ pointBorderColor: colors[i % 15 + 1],
330
+ borderColor: colors[i % 15 + 1],
331
+ pointBackgroundColor: colors[i % 15 + 1],
331
332
  borderWidth: 2
332
333
  }
333
334
  end
334
335
  }
335
336
  end
336
337
 
337
- 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)
338
339
  {
339
340
  labels: dates,
340
- datasets: names.map.with_index do |name,i|{
341
- label: name,
342
- data: dates.map{ |d|
343
- case i
344
- when 0
345
- 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)
346
- when 1
347
- 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)
348
- else
349
- 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)
350
- end
351
- },
352
- backgroundColor: colors[i],
353
- borderColor: colors[i],
354
- borderWidth: 1
355
- }
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
+ }
356
358
  end
357
359
  }
358
360
  end
359
361
 
360
- 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)
361
363
  {
362
364
  labels: dates,
363
- datasets:names.map.with_index do |name,i| {
364
- label: name,
365
- data: dates.map{ |d|
366
- case i
367
- when 0
368
- 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)
369
- when 1
370
- 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)
371
- else
372
- 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)
373
- end },
374
- backgroundColor: colors[i],
375
- borderColor: colors[i],
376
- borderWidth: 1
377
- }
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
+ }
378
381
  end
379
382
  }
380
383
  end
381
384
 
382
-
383
385
  end
384
386
  end
@@ -46,6 +46,10 @@ module EducodeSales
46
46
  @staff = Staff.find(params[:id])
47
47
  gon.area_ids = @staff.area_ids
48
48
  gon.areas = Common.where(clazz: 'area').map { |d| { value: d.id, title: d.name } } #.unshift({value: -1, title: '全国'})
49
+ gon.school_ids = @staff.staff_schools.ids
50
+ gon.schools = @staff.staff_schools.pluck(:school_id).map { |d| { value: d, name: "#{School.find(d)&.name}-#{School.find(d)&.province}" } } #.unshift({value: -1, title: '全国'})
51
+ # gon.school_ids = School.all.ids
52
+ # gon.schools = School.all.first(100).map { |d| { value: d.id, title: d.name } } #.unshift({value: -1, title: '全国'})
49
53
  @staff_types = Common.where(clazz: 'staff_type').pluck(:name, :id)
50
54
  render layout: false
51
55
  end
@@ -77,6 +81,14 @@ module EducodeSales
77
81
  commons << Common.find(d)
78
82
  end
79
83
  staff.areas = commons
84
+ if params[:school_ids].present?
85
+ staff.staff_schools.destroy_all
86
+ params[:school_ids].each do |d|
87
+ staff.staff_schools.create(school_id: d)
88
+ end
89
+ else
90
+ staff.staff_schools.destroy_all
91
+ end
80
92
  if staff.save
81
93
  render_success
82
94
  else
@@ -48,7 +48,7 @@ module EducodeSales
48
48
  teacher_ids = EducodeSales::Teacher.where(staff_id: 0).pluck(:id) - EducodeSales::TeacherAssignFollow.all.pluck(:Teacher_id) + EducodeSales::TeacherAssignFollow.where(staff_id: @current_admin.id).pluck(:teacher_id) + @teachers.ids
49
49
  @teachers = Teacher.where(id: teacher_ids)
50
50
  when '区域'
51
- school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id)
51
+ school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id) + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
52
52
  @teachers = Teacher.joins("JOIN departments ON educode_sales_teachers.department_id = departments.id").where(is_key: false).where("departments.school_id in (?) OR educode_sales_teachers.staff_id = #{@current_admin.id}", school_ids)
53
53
  teacher_ids = EducodeSales::Teacher.where(staff_id: 0).pluck(:id) - EducodeSales::TeacherAssignFollow.all.pluck(:Teacher_id) + EducodeSales::TeacherAssignFollow.where(staff_id: @current_admin.id).pluck(:teacher_id) + @teachers.ids
54
54
  @teachers = Teacher.where(id: teacher_ids)
@@ -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
@@ -0,0 +1,4 @@
1
+ module EducodeSales
2
+ class CustomerAdd < ApplicationRecord
3
+ end
4
+ 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
@@ -14,6 +14,7 @@ module EducodeSales
14
14
  has_many :businesses, dependent: :destroy
15
15
  has_many :activities, dependent: :destroy
16
16
  has_many :sale_plans, dependent: :destroy
17
+ has_many :staff_schools, dependent: :destroy
17
18
 
18
19
  has_many :areas, through: :market_areas
19
20
  validates :user_id, uniqueness: { message: '已存在' }
@@ -0,0 +1,6 @@
1
+ module EducodeSales
2
+ class StaffSchool < ApplicationRecord
3
+ belongs_to :school
4
+ belongs_to :staff
5
+ end
6
+ end
@@ -24,7 +24,7 @@
24
24
  <div class="layui-input-inline" style="width: 300px;" id="professional_title_div">
25
25
  <label class="layui-form-label required">状态</label>
26
26
  <div class="layui-input-block">
27
- <%= select_tag "clazz", options_for_select(['未完成', '已完成']), class: 'required' %>
27
+ <%= select_tag "clazz", options_for_select(['计划回款', '实际回款']), class: 'required' %>
28
28
  </div>
29
29
  </div>
30
30
  </div>
@@ -43,7 +43,7 @@
43
43
  <script type="text/html" id="return_money_select">
44
44
  <div class="layui-input-block table-select">
45
45
  <select name="clazz" lay-filter="return_money_select">
46
- {{# layui.each(['未完成', '已完成'], function(i, data) { }}
46
+ {{# layui.each(['计划回款', '实际回款'], function(i, data) { }}
47
47
  {{# if (data == d.clazz) { }}
48
48
  <option value="{{data}}" selected="{{d.clazz}}">{{data}}</option>
49
49
  {{# } else { }}
@@ -90,8 +90,8 @@
90
90
  layer.alert(res.msg)
91
91
  } else {
92
92
  // layer.close(parent.plan_index);
93
- parent.table.reload('sale_plan_follow_table');
94
- parent.table.reload('businesses_table');
93
+ table.reload('sale_plan_follow_table');
94
+ table.reload('businesses_table');
95
95
  table.reload('return_money_list');
96
96
  }
97
97
  })
@@ -1,7 +1,6 @@
1
1
  json.data do
2
2
  json.array! @records do |d|
3
- json.id d.id
4
- json.name d.name
3
+ json.(d, :id, :name)
5
4
  json.staff d.staff&.user&.real_name
6
5
  json.created_at d.created_at.to_s
7
6
  end
@@ -0,0 +1,30 @@
1
+ json.data do
2
+ json.array! @businesses do |d|
3
+ json.id d.id
4
+ json.name d.name
5
+ json.department d.department.name
6
+ json.school d.department.school.name
7
+ json.school_id d.department.school.id
8
+ follow_ups_count = d.follow_ups.where(deleted_at: nil).size
9
+ json.follow_ups_count follow_ups_count
10
+ json.follow_up_id d.last_follow_up_id
11
+ json.clazz d.last_follow_up&.clazz&.name || ""
12
+ json.stage d.last_follow_up&.stage&.name
13
+ json.invitation_at d.last_follow_up&.invitation_at.to_s
14
+ json.reception_at d.last_follow_up&.reception_at.to_s
15
+ json.bidded_date d.last_follow_up&.bidded_date.to_s
16
+ json.signed_date d.last_follow_up&.signed_date.to_s
17
+ json.total_amount d.last_follow_up&.total_amount
18
+ json.actual_amount d.last_follow_up&.actual_amount
19
+ json.return_money d.return_money
20
+ json.wait_return_money d.wait_return_money.to_i.round(2)
21
+ json.return_money_days d.last_follow_up&.reception_at.present? && d.last_follow_up.money_plans.where(clazz: '实际回款').present? ? (d.last_follow_up.money_plans.where(clazz: '实际回款').order(created_at: :asc).first.date_at.to_s(:date).to_date - d.last_follow_up&.reception_at).to_i : ''
22
+ json.place d.last_follow_up&.place&.name
23
+ json.last_follow_person d.last_follow_up.present? ? d.last_follow_up.staff.user.real_name : EducodeSales::Staff.find(d.staff_id).user.real_name
24
+ json.source d.source
25
+ json.assign_follow_ups d.last_follow_up.present? ? d.last_follow_up.assign_follow_ups.pluck(:staff_id) : []
26
+ json.current_staff_id @current_admin.id
27
+ json.staff_id d.staff_id
28
+ json.latest_time d.last_follow_up.present? ? d.last_follow_up.created_at.to_s : ''
29
+ end
30
+ end