educode_sales 0.6.4 → 0.6.8

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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/educode_sales/activities_controller.rb +0 -2
  3. data/app/controllers/educode_sales/businesses_controller.rb +103 -47
  4. data/app/controllers/educode_sales/money_plans_controller.rb +8 -7
  5. data/app/controllers/educode_sales/sale_trends_controller.rb +105 -18
  6. data/app/controllers/educode_sales/staffs_controller.rb +19 -0
  7. data/app/controllers/educode_sales/teacher_follows_controller.rb +1 -93
  8. data/app/models/educode_sales/business_export_record.rb +5 -0
  9. data/app/views/educode_sales/activities/index.html.erb +7 -1
  10. data/app/views/educode_sales/activities/new.html.erb +1 -1
  11. data/app/views/educode_sales/businesses/edit_follow_record.html.erb +13 -4
  12. data/app/views/educode_sales/businesses/edit_plan.html.erb +5 -2
  13. data/app/views/educode_sales/businesses/export_records.html.erb +53 -0
  14. data/app/views/educode_sales/businesses/export_records.json.jbuilder +11 -0
  15. data/app/views/educode_sales/businesses/file.html.erb +8 -4
  16. data/app/views/educode_sales/businesses/index.html.erb +119 -16
  17. data/app/views/educode_sales/businesses/index.json.jbuilder +37 -7
  18. data/app/views/educode_sales/businesses/new_follow_record.html.erb +10 -5
  19. data/app/views/educode_sales/commons/index.html.erb +7 -1
  20. data/app/views/educode_sales/customers/edit.html.erb +3 -0
  21. data/app/views/educode_sales/customers/edit_follow_record.html.erb +1 -1
  22. data/app/views/educode_sales/customers/new.html.erb +3 -0
  23. data/app/views/educode_sales/customers/new_follow_record.html.erb +1 -1
  24. data/app/views/educode_sales/customers/show_follow.html.erb +1 -1
  25. data/app/views/educode_sales/money_plans/index.html.erb +47 -8
  26. data/app/views/educode_sales/money_plans/index.json.jbuilder +2 -1
  27. data/app/views/educode_sales/places/index.html.erb +16 -2
  28. data/app/views/educode_sales/places/index.json.jbuilder +3 -1
  29. data/app/views/educode_sales/recycles/business.json.jbuilder +2 -2
  30. data/app/views/educode_sales/roles/index.html.erb +7 -1
  31. data/app/views/educode_sales/sale_trends/trends.html.erb +96 -44
  32. data/app/views/educode_sales/sale_trends/trends.json.jbuilder +2 -1
  33. data/app/views/educode_sales/sales/index.json.jbuilder +2 -2
  34. data/app/views/educode_sales/staffs/index.html.erb +68 -2
  35. data/app/views/educode_sales/teachers/index.html.erb +15 -7
  36. data/app/views/layouts/educode_sales/application.html.erb +6 -1
  37. data/config/routes.rb +2 -0
  38. data/db/migrate/20210902064109_create_educode_sales_role_permissions.rb +7 -0
  39. data/db/migrate/20220121060006_create_educode_sales_business_export_records.rb +10 -0
  40. data/lib/educode_sales/version.rb +1 -1
  41. metadata +6 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8cd066340676e40c41aa18730eacf453f8bf228ceb4416179f0e916581525999
4
- data.tar.gz: a30becf3c8cc2c925c21b66948d429a241d3750289f5e921ab3c0cde5aeea3f4
3
+ metadata.gz: 41b7c2e662fd724e27b8a995fe3f8fe5733384fe5454ffff038a22fe7526b6ad
4
+ data.tar.gz: '09abc1d2d95817c2fc4e1dbc73beb1a31beb24239e2401b25c41125bf7864130'
5
5
  SHA512:
6
- metadata.gz: adabc609d925eb080964dc566815134c5384f258fde90b7008296ceacf178a1435be37c553f49291844ce7043f6dfc4745f7713da687f40da40871acc67a6f8e
7
- data.tar.gz: 042b06433756725fad2b2bd4bb612bca89616f3e18e6055e5c2df4a89d8ece4810f9fe80899047a52c86d60c6e263b14bdb92ee9107efe63bb662ee51dd73041
6
+ metadata.gz: 7305c066cefb80249560e179eee5f84caedde9e223cb45311ebca66462251be8280cfb5c577da14d3c946ed485fadcca6342160e571203f0d25ccb987fca0f7b
7
+ data.tar.gz: 3896cf2a1252a590053116ceac804abbc6cdae787b8f055a4258cfc388b8832aea623d561e5fe3ae4ce76e22347aa606f3e0f40e138c4747d535b5d75e2070c3
@@ -19,8 +19,6 @@ module EducodeSales
19
19
  end
20
20
 
21
21
  def new
22
- # gon.area_ids = @place.area_ids
23
- # gon.areas = Common.where(clazz: 'area').map { |d| { value: d.id, title: d.name } } #.unshift({value: -1, title: '全国'})
24
22
  render layout: false
25
23
  end
26
24
 
@@ -3,29 +3,6 @@ require_dependency "educode_sales/application_controller"
3
3
  module EducodeSales
4
4
  class BusinessesController < ApplicationController
5
5
 
6
- def file
7
- gon.folder = edu_setting('attachment_folder') + '/'
8
- render layout: false
9
- end
10
- def upload_file
11
- render layout: false
12
- end
13
- def time_line
14
- @business = Business.find(params[:business_id])
15
- respond_to do |format|
16
- format.html do
17
- @follow_ups = @business.follow_ups.order(created_at: :desc)
18
- # @latest = @follow_ups.order(created_at: :desc).first
19
- # if params[:field]
20
- # @follow_ups = @follow_ups.order("#{params[:field]} #{params[:order]}")
21
- # else
22
- # @follow_ups = @follow_ups.order("created_at desc")
23
- # end
24
- # @follow_ups = @follow_ups.page(params[:page]).per(params[:limit])
25
- render layout: false
26
- end
27
- end
28
- end
29
6
 
30
7
  def index
31
8
  authorize! :read, Business
@@ -33,21 +10,37 @@ module EducodeSales
33
10
  format.html do
34
11
  common = Common.find_by(clazz: 'staff_type', name: '销售')
35
12
  @staffs = Staff.joins(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id]}
36
- @more = can?(:create, EducodeSales::SalePlan) || can?(:update, EducodeSales::Business) || can?(:destroy, EducodeSales::Business)
13
+ # @more = can?(:create, EducodeSales::SalePlan) || can?(:update, EducodeSales::Business) || can?(:destroy, EducodeSales::Business) || can?(:show_file, EducodeSales::Business)
14
+ @more = true
37
15
  gon.menus = []
16
+ gon.export_menus = []
38
17
  gon.place = params[:place_id].present? ? [{ value: params[:place_id], name: EducodeSales::Place.find(params[:place_id]).name }] : []
18
+ gon.business_type = Common.where(clazz: 'business_type').map do |d|
19
+ {value: d.id, name: d.name}
20
+ end
21
+ gon.type = params[:clazz_id].present? ? [{ value: params[:clazz_id], name: Common.find(params[:clazz_id]).name }] : []
22
+ gon.business_step = Common.where(clazz: 'business_step').map do |d|
23
+ {value: d.id, name: d.name}
24
+ end
39
25
  if can?(:create, EducodeSales::SalePlan)
40
26
  gon.menus << { title: '添加周计划', event: 'week' }
41
27
  gon.menus << { title: '添加月计划', event: 'month' }
42
28
  end
43
29
  gon.menus << { title: '跟进时间线', event: 'time_line' }
44
- gon.menus << { title: '附件管理', event: 'file' }
30
+ if can?(:show_file, EducodeSales::Business)
31
+ gon.menus << { title: '附件管理', event: 'file' }
32
+ end
45
33
  if can?(:update, EducodeSales::Business)
46
34
  gon.menus << { title: '编辑', event: 'edit' }
47
35
  end
48
36
  if can?(:destroy, EducodeSales::Business)
49
37
  gon.menus << { title: '删除', event: 'delete' }
50
38
  end
39
+ if can?(:export_business, EducodeSales::Business)
40
+ gon.export_menus << { title: '导出到Csv文件', event: 'export_csv' }
41
+ gon.export_menus << { title: '导出到Excel文件', event: 'export_excel' }
42
+ end
43
+ gon.export_menus << { title: '导出记录', event: 'export_records' }
51
44
  end
52
45
  format.json do
53
46
  if @current_admin.is_admin?
@@ -71,41 +64,56 @@ module EducodeSales
71
64
  @year = params[:q][:name].split("-")[1].present? ? params[:q][:name].split("-")[1] : ''
72
65
  end
73
66
 
74
- if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-现有商机)"
75
- a_id = Common.find_by(extras: EducodeSales::Common::ATYPE)&.id
76
- b_id = Common.find_by(extras: EducodeSales::Common::BTYPE)&.id
77
- c_id = Common.find_by(extras: EducodeSales::Common::CTYPE)&.id
78
- d_id = Common.find_by(extras: EducodeSales::Common::DTYPE)&.id
79
- e_id = Common.find_by(extras: EducodeSales::Common::ETYPE)&.id
80
- o_id = Common.find_by(extras: EducodeSales::Common::OTYPE)&.id
81
- ids = [a_id ,b_id ,c_id ,d_id ,e_id ,o_id]
82
- @businesses = @businesses.joins("
67
+ if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-" + @year + "-现有商机)"
68
+ ids = Common.where(extras: %w[a_class b_class c_class d_class e_class o_class]).pluck(:id)
69
+ if @year == '全部'
70
+ @businesses = @businesses.joins("
83
71
  JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
84
72
  ").where("educode_sales_follow_ups.clazz_id in (?)",ids)
73
+ else
74
+ @businesses = @businesses.joins("
75
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
76
+ ").where("educode_sales_follow_ups.clazz_id in (?)",ids).where("educode_sales_follow_ups.year = ?",@year)
77
+ end
78
+
85
79
  end
86
80
 
87
81
  if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-" + @year + "-已中标商机)"
88
82
  stage_ids = Common.where(clazz: '商机阶段', name: ['已中标','已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
89
- @businesses = @businesses.joins("
83
+ if @year == '全部'
84
+ @businesses = @businesses.joins("
85
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
86
+ ").where("educode_sales_follow_ups.stage_id IN (?)",stage_ids)
87
+ else
88
+ @businesses = @businesses.joins("
90
89
  JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
91
90
  ").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)
91
+ end
92
+
92
93
  end
93
94
 
94
95
  if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-" + @year + "-已签单商机)"
95
96
  s_stage_ids = Common.where(clazz: '商机阶段', name: ['已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
96
- @businesses = @businesses.joins("
97
+ if @year == '全部'
98
+ @businesses = @businesses.joins("
99
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
100
+ ").where("educode_sales_follow_ups.stage_id IN (?)",s_stage_ids)
101
+ else
102
+ @businesses = @businesses.joins("
97
103
  JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
98
104
  ").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)
105
+ end
99
106
  end
100
107
 
101
108
  if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-" + @year + "-已回款商机)"
102
109
  x_id = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
103
- # @businesses = @businesses.where("educode_sales_businesses.created_at > ? AND educode_sales_businesses.created_at < ? AND educode_sales_businesses.return_money > 0", "#{@year}-01-01", "#{@year}-12-31").joins("
104
- # JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
105
- # ").where.not("educode_sales_follow_ups.clazz_id = ?",x_id)
106
110
  year_time = "#{@year}-01-01 00:00:00"
107
111
  year_over_time = "#{@year}-12-31 23:59:59"
108
- @businesses = @businesses.joins(follow_ups: :money_plans).where("educode_sales_follow_ups.clazz_id != ?", x_id).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).distinct
112
+ if @year == '全部'
113
+ @businesses = @businesses.joins(follow_ups: :money_plans).where("educode_sales_follow_ups.clazz_id != ?", x_id).where.not("educode_sales_money_plans.clazz!= ?", 1).distinct
114
+ else
115
+ @businesses = @businesses.joins(follow_ups: :money_plans).where("educode_sales_follow_ups.clazz_id != ?", x_id).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).distinct
116
+ end
109
117
  end
110
118
 
111
119
  if params[:q].present? && params[:q][:all].present?
@@ -119,7 +127,7 @@ module EducodeSales
119
127
  end
120
128
 
121
129
  @businesses = @businesses
122
- if params[:q].present? && params[:q][:name].present? && params[:q][:name] != "(销售态势-" + @year + "-已中标商机)" && params[:q][:name] != "(销售态势-" + @year + "-已签单商机)" && params[:q][:name] != "(销售态势-" + @year + "-已回款商机)" && params[:q][:name] != "(销售态势-现有商机)"
130
+ if params[:q].present? && params[:q][:name].present? && params[:q][:name] != "(销售态势-" + @year + "-已中标商机)" && params[:q][:name] != "(销售态势-" + @year + "-已签单商机)" && params[:q][:name] != "(销售态势-" + @year + "-已回款商机)" && params[:q][:name] != "(销售态势-" + @year + "-现有商机)"
123
131
  @businesses = @businesses.where("educode_sales_businesses.name like ?", "%#{params[:q][:name]}%")
124
132
  end
125
133
  if params[:q].present? && params[:q][:department].present?
@@ -137,12 +145,12 @@ module EducodeSales
137
145
  if params[:q].present? && params[:q][:business_type].present?
138
146
  @businesses = @businesses.joins("
139
147
  JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
140
- ").where("educode_sales_follow_ups.clazz_id = ?", params[:q][:business_type])
148
+ ").where("educode_sales_follow_ups.clazz_id in (?)", params[:q][:business_type].split(",").map(&:to_i))
141
149
  end
142
150
  if params[:q].present? && params[:q][:business_step].present?
143
151
  @businesses = @businesses.joins("
144
152
  JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
145
- ").where("educode_sales_follow_ups.stage_id = ?", params[:q][:business_step])
153
+ ").where("educode_sales_follow_ups.stage_id in (?)", params[:q][:business_step].split(",").map(&:to_i))
146
154
  end
147
155
  if params[:q].present? && params[:q][:place_id].present?
148
156
  @businesses = @businesses.joins("
@@ -177,6 +185,13 @@ module EducodeSales
177
185
  @businesses = @businesses.where("educode_sales_businesses.created_at > ? AND educode_sales_businesses.created_at < ?", date[0], date[1] + '23:59:59')
178
186
  end
179
187
 
188
+ if params[:q].present? && params[:q][:invitation_at].present?
189
+ date = params[:q][:invitation_at].split(" - ")
190
+ @businesses = @businesses.joins("
191
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
192
+ ").where("educode_sales_follow_ups.invitation_at > ? AND educode_sales_follow_ups.invitation_at < ?", date[0] + '00:00:00', date[1] + '23:59:59')
193
+ end
194
+
180
195
  if params[:sort].present? && params[:sort][:field]
181
196
  @businesses = @businesses.order("#{params[:sort][:field]} #{params[:sort][:order]}")
182
197
  else
@@ -185,9 +200,7 @@ module EducodeSales
185
200
 
186
201
  @business_count = @businesses.count
187
202
 
188
-
189
-
190
- @businesses = @businesses.select("
203
+ @businesses_exports = @businesses.select("
191
204
  educode_sales_businesses.*,
192
205
  last_follow.invitation_at,
193
206
  last_follow.reception_at,
@@ -195,9 +208,12 @@ module EducodeSales
195
208
  last_follow.signed_date,
196
209
  last_follow.created_at as latest_time,
197
210
  last_follow.actual_amount,
211
+ (last_follow.actual_amount - educode_sales_businesses.return_money) as wait_return_money,
198
212
  last_follow.total_amount").joins("
199
213
  LEFT JOIN educode_sales_follow_ups AS last_follow ON educode_sales_businesses.last_follow_up_id = last_follow.id
200
- ").page(params[:page]).per(params[:limit])
214
+ ")
215
+
216
+ @businesses = @businesses_exports.page(params[:page]).per(params[:limit])
201
217
  end
202
218
  end
203
219
  end
@@ -332,6 +348,46 @@ module EducodeSales
332
348
  render layout: false
333
349
  end
334
350
 
351
+ def file
352
+ gon.folder = edu_setting('attachment_folder') + '/'
353
+ render layout: false
354
+ end
355
+ def upload_file
356
+ render layout: false
357
+ end
358
+ def time_line
359
+ @business = Business.find(params[:business_id])
360
+ respond_to do |format|
361
+ format.html do
362
+ @follow_ups = @business.follow_ups.order(created_at: :desc)
363
+ render layout: false
364
+ end
365
+ end
366
+ end
367
+
368
+ def export_records
369
+ respond_to do |format|
370
+ format.html do
371
+ render layout: false
372
+ end
373
+ format.json do
374
+ @records = BusinessExportRecord.all.page(params[:page]).per(params[:limit])
375
+ end
376
+ end
377
+ end
378
+ def add_export_records
379
+ if params[:type] == 'csv'
380
+ record = BusinessExportRecord.new(name: '商机数据表.csv', staff_id: @current_admin.id)
381
+ else params[:type] == 'excel'
382
+ record = BusinessExportRecord.new(name: '商机数据表.xls', staff_id: @current_admin.id)
383
+ end
384
+ if record.save
385
+ render_success
386
+ else
387
+ render_failure business
388
+ end
389
+ end
390
+
335
391
  private
336
392
 
337
393
  def load_business
@@ -12,21 +12,22 @@ module EducodeSales
12
12
  @staffs = Staff.joins(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id]}
13
13
  end
14
14
  format.json do
15
+ x_id = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
15
16
  if @current_admin.is_admin?
16
- @money_plans = MoneyPlan.where(follow_up_id: follow_up_ids)
17
+ @money_plans = MoneyPlan.joins(:follow_up).where("educode_sales_follow_ups.clazz_id != ?", x_id).where(follow_up_id: follow_up_ids)
17
18
  else
18
19
  level = @current_admin.role.role_areas.find_by(clazz: '回款管理').level
19
20
  case level
20
21
  when '自己'
21
- @money_plans = MoneyPlan.where(follow_up_id: follow_up_ids).where(staff_id: @current_admin.staff_id)
22
+ @money_plans = MoneyPlan.joins(:follow_up).where("educode_sales_follow_ups.clazz_id != ?", x_id).where(follow_up_id: follow_up_ids).where(staff_id: @current_admin.id)
22
23
  when '区域'
23
- a_ids = MoneyPlan.where(follow_up_id: follow_up_ids).where(staff_id: @current_admin.staff_id).ids
24
+ a_ids = MoneyPlan.where(follow_up_id: follow_up_ids).where(staff_id: @current_admin.id).ids
24
25
  school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id)
25
26
  b_ids = Business.where(school_id: school_ids).pluck(:last_follow_up_id)
26
27
  ids = a_ids + b_ids
27
- @money_plans = MoneyPlan.where(id: ids)
28
+ @money_plans = MoneyPlan.joins(:follow_up).where("educode_sales_follow_ups.clazz_id != ?", x_id).where(id: ids)
28
29
  else
29
- @money_plans = MoneyPlan.where(follow_up_id: follow_up_ids)
30
+ @money_plans = MoneyPlan.joins(:follow_up).where("educode_sales_follow_ups.clazz_id != ?", x_id).where(follow_up_id: follow_up_ids)
30
31
  end
31
32
  end
32
33
 
@@ -47,13 +48,13 @@ module EducodeSales
47
48
  end
48
49
  if params[:q].present? && params[:q][:date].present?
49
50
  date = params[:q][:date].split(" - ")
50
- @money_plans = @money_plans.where("educode_sales_money_plans.created_at > ? AND educode_sales_money_plans.created_at < ?", date[0], date[1] + '23:59:59')
51
+ @money_plans = @money_plans.where("educode_sales_money_plans.date_at >= ? AND educode_sales_money_plans.date_at < ?", date[0], date[1] + '23:59:59')
51
52
  end
52
53
 
53
54
  if params[:sort].present? && params[:sort][:field]
54
55
  @money_plans = @money_plans.order("#{params[:sort][:field]} #{params[:sort][:order]}")
55
56
  else
56
- @money_plans = @money_plans.order(created_at: :desc)
57
+ @money_plans = @money_plans.order(date_at: :desc)
57
58
  end
58
59
  @total_amount = @money_plans.sum(:amount)
59
60
  @money_plans = @money_plans.page(params[:page]).per(params[:limit])
@@ -7,24 +7,41 @@ module EducodeSales
7
7
  def trends
8
8
  # authorize! :trends, EducodeSales::SaleTrend
9
9
  @year = params[:year] ? params[:year] : Time.now.year
10
- @years = (1..(Time.now.year - 2014)).reverse_each.map { |d| 2014 + d }
11
- year_time = "#{@year}-01-01 00:00:00"
12
- year_over_time = "#{@year}-12-31 23:59:59"
13
- x = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
14
- o = Common.find_by(extras: EducodeSales::Common::OTYPE)&.id
15
- @sale_trend = SaleTrend.find_or_create_by(year: @year)
16
- @business_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).sum(:total_amount).round(2)
17
- stage_ids = Common.where(clazz: '商机阶段', name: ['已中标','已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
18
- @goal_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.bidded_date >= ? AND educode_sales_follow_ups.bidded_date <= ? AND educode_sales_follow_ups.stage_id IN (?)", "#{@year}-01-01", "#{@year}-12-31", stage_ids).sum(:total_amount).round(2)
19
- @actual_goal_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.bidded_date >= ? AND educode_sales_follow_ups.bidded_date <= ? AND educode_sales_follow_ups.stage_id IN (?)", "#{@year}-01-01", "#{@year}-12-31", stage_ids).sum(:actual_amount).round(2)
20
- s_stage_ids = Common.where(clazz: '商机阶段', name: ['已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
21
- @service_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.signed_date >= ? AND educode_sales_follow_ups.signed_date <= ? AND educode_sales_follow_ups.stage_id IN (?)", "#{@year}-01-01", "#{@year}-12-31", s_stage_ids).sum(:total_amount).round(2)
22
- @actual_service_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.signed_date >= ? AND educode_sales_follow_ups.signed_date <= ? AND educode_sales_follow_ups.stage_id IN (?)", "#{@year}-01-01", "#{@year}-12-31", s_stage_ids).sum(:actual_amount).round(2)
23
- @return_amount = Business.joins(last_follow_up: :money_plans).where("educode_sales_follow_ups.clazz_id != ?", x).where.not("educode_sales_money_plans.clazz!= ?", 1).where("educode_sales_money_plans.date_at >= ? AND educode_sales_money_plans.date_at <= ? ", year_time, year_over_time).sum(:amount).round(2)
24
- a = Common.where(clazz: '商机类型', name: Common.find_by(extras: EducodeSales::Common::ATYPE)&.name).pluck(:id)
25
- @a_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id IN (?)", a).sum(:total_amount).round(2)
26
- b = Common.where(clazz: '商机类型', name: Common.find_by(extras: EducodeSales::Common::BTYPE)&.name).pluck(:id)
27
- @b_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id IN (?)", b).sum(:total_amount).round(2)
10
+ @years = ['全部'] + (1..(Time.now.year - 2014)).reverse_each.map { |d| 2014 + d }
11
+ if(@year == '全部')
12
+ x = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
13
+ o = Common.find_by(extras: EducodeSales::Common::OTYPE)&.id
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)
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
+ @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)
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
+ @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
+ @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)
22
+ a = Common.where(clazz: '商机类型', name: Common.find_by(extras: EducodeSales::Common::ATYPE)&.name).pluck(:id)
23
+ @a_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id IN (?)", a).sum(:total_amount).round(2)
24
+ b = Common.where(clazz: '商机类型', name: Common.find_by(extras: EducodeSales::Common::BTYPE)&.name).pluck(:id)
25
+ @b_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id IN (?)", b).sum(:total_amount).round(2)
26
+ else
27
+ year_time = "#{@year}-01-01 00:00:00"
28
+ year_over_time = "#{@year}-12-31 23:59:59"
29
+ x = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
30
+ o = Common.find_by(extras: EducodeSales::Common::OTYPE)&.id
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)
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
+ @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)
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
+ @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
+ @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
+ 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)
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)
44
+ end
28
45
 
29
46
  count_type = params[:count_type] || "actual_amount"
30
47
  common = Common.find_by(clazz: 'staff_type', name: '销售')
@@ -116,6 +133,76 @@ module EducodeSales
116
133
 
117
134
 
118
135
 
136
+ # 销售人员跟进分析
137
+ begin_time = Time.now.at_beginning_of_year.to_s
138
+ end_time = Time.now.at_end_of_year.to_s
139
+ customer_time_range = params[:customer_time_range]
140
+ case customer_time_range
141
+ when 'last_week'
142
+ begin_time = (Time.now - 1.week).at_beginning_of_week.to_s
143
+ end_time = (Time.now - 1.week).at_end_of_week.to_s
144
+ when 'this_week'
145
+ begin_time = Time.now.at_beginning_of_week.to_s
146
+ end_time = Time.now.at_end_of_week.to_s
147
+ when 'last_month'
148
+ begin_time = (Time.now - 1.month).at_beginning_of_month.to_s
149
+ end_time = (Time.now - 1.month).at_end_of_month.to_s
150
+ when 'this_month'
151
+ begin_time = Time.now.at_beginning_of_month.to_s
152
+ end_time = Time.now.at_end_of_month.to_s
153
+ when 'last_year'
154
+ begin_time = (Time.now - 1.year).at_beginning_of_year.to_s
155
+ end_time = (Time.now - 1.year).at_end_of_year.to_s
156
+ when 'this_year'
157
+ begin_time = Time.now.at_beginning_of_year.to_s
158
+ end_time = Time.now.at_end_of_year.to_s
159
+ when 'all'
160
+ begin_time = (Time.now - 5.year).at_beginning_of_year.to_s
161
+ end_time = (Time.now + 5.year).at_end_of_year.to_s
162
+ when 'diy'
163
+ if params[:customer_date].present?
164
+ date = params[:customer_date].split(" - ")
165
+ begin_time = date[0]
166
+ end_time = date[1]
167
+ end
168
+ end
169
+ 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}
171
+ staff_ids = Staff.joins(:user).where(job_type: common.id).pluck(:id)
172
+ if params[:customer_count_type] == 'money' || params[:customer_count_type].blank?
173
+ @customer_data = {
174
+ labels: staff_names,
175
+ datasets:[
176
+ {
177
+ label: "跟进客户数",
178
+ data: staff_ids.map{|staff_id|
179
+ (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
+ },
181
+ backgroundColor: colors[0],
182
+ borderColor: colors[0],
183
+ borderWidth: 1
184
+ }
185
+ ]
186
+ }
187
+ else
188
+ @customer_data = {
189
+ labels: staff_names,
190
+ datasets:[
191
+ {
192
+ label: "跟进客户次数",
193
+ data: staff_ids.map{|staff_id|
194
+ 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
+ },
196
+ backgroundColor: colors[0],
197
+ borderColor: colors[0],
198
+ borderWidth: 1
199
+ }
200
+ ]
201
+ }
202
+ end
203
+
204
+
205
+
119
206
  # 已中标图表
120
207
  goal_default_dates = ("#{Time.now.year}-01".."#{Time.now.year}-#{Time.now.month}").to_a
121
208
  sale_names = ['已中标','已签单','已回款']
@@ -9,6 +9,25 @@ module EducodeSales
9
9
  end
10
10
  format.json do
11
11
  @staffs = Staff.where(is_admin: false, deleted_at: nil).page(params[:page]).per(params[:limit])
12
+ if params[:q].present? && params[:q][:name].present?
13
+ @staffs = @staffs.joins(:user).where('CONCAT(lastname, firstname) LIKE :name', name: "%#{params[:q][:name]}%")
14
+ end
15
+ if params[:q].present? && params[:q][:role].present?
16
+ @staffs = @staffs.where(role: params[:q][:role])
17
+ end
18
+ if params[:q].present? && params[:q][:staff_id].present?
19
+ @staffs = @staffs.where(staff_id: params[:q][:staff_id])
20
+ end
21
+ if params[:q].present? && params[:q][:staff_type].present?
22
+ @staffs = @staffs.where(job_type: params[:q][:staff_type])
23
+ end
24
+ if params[:q].present? && params[:q][:banned].present?
25
+ if params[:q][:banned] == "0"
26
+ @staffs = @staffs.where("educode_sales_staffs.expired_at is null or educode_sales_staffs.expired_at > ?", Time.now)
27
+ else
28
+ @staffs = @staffs.where("educode_sales_staffs.expired_at is null or educode_sales_staffs.expired_at < ?", Time.now)
29
+ end
30
+ end
12
31
  end
13
32
  end
14
33
  end
@@ -34,114 +34,22 @@ module EducodeSales
34
34
  def update
35
35
  follow_up = TeacherFollow.find(params[:id])
36
36
  follow_up.assign_attributes(follow_up_params)
37
- # follow_up.profit_amount = follow_up.actual_amount * (100-follow_up.divide_amount.to_i) * 0.01 if follow_up.actual_amount
38
37
  if follow_up.save
39
38
  render_success
40
39
  else
41
40
  render_failure follow_up
42
41
  end
43
42
  end
44
- #
45
- # def teachers
46
- # follow_up = @current_admin.follow_ups.find_by(id: params[:id])
47
- # if follow_up.present?
48
- # @teachers = follow_up.key_person.includes(:teacher).page(params[:page]).per(params[:limit])
49
- # else
50
- # @teachers = FollowUp.none
51
- # end
52
- # end
53
- #
54
- # def money_plans
55
- # follow_up = @current_admin.follow_ups.find_by(id: params[:id])
56
- # @money_plans = follow_up.money_plans.page(params[:page]).per(params[:limit])
57
- # end
58
- #
59
- # def add_money
60
- # follow_up = @current_admin.follow_ups.find(params[:id])
61
- # money_plan = follow_up.money_plans.build(date_at: params[:date_at], amount: params[:amount], clazz: params[:clazz])
62
- # money_plan.staff = @current_admin
63
- # if money_plan.save
64
- # render_success
65
- # else
66
- # render_failure money_plan
67
- # end
68
- # end
69
- #
70
- # def update_money
71
- # follow_up = @current_admin.follow_ups.find_by(id: params[:id])
72
- # money_plan = follow_up.money_plans.find(params[:plan_id])
73
- # if money_plan.update(date_at: params[:date_at], amount: params[:amount], clazz: params[:clazz])
74
- # render_success
75
- # else
76
- # render_failure money_plan
77
- # end
78
- # end
79
- #
80
- # def delete_money
81
- # follow_up = @current_admin.follow_ups.find_by(id: params[:id])
82
- # money_plan = follow_up.money_plans.find(params[:plan_id])
83
- # if money_plan.destroy
84
- # render_success
85
- # else
86
- # render_failure money_plan
87
- # end
88
- # end
89
- #
90
- # def add_keys
91
- # follow_up = @current_admin.follow_ups.find(params[:id])
92
- # if params[:name].blank?
93
- # return render_failure '请从平台里选择教师'
94
- # end
95
- #
96
- # names = params[:name].split("-")
97
- # if names[0] == 't'
98
- # # 从教师列表里选择的用户
99
- # teacher = Teacher.find(names[1])
100
- # key_peprson = KeyPerson.new(teacher_params)
101
- # key_peprson.teacher = teacher
102
- # else
103
- # # 从头歌平台选择的用户
104
- # user = User.find(names[1])
105
- # teacher = Teacher.new(staff: @current_admin,
106
- # professional_title: params[:professional_title],
107
- # job: params[:job],
108
- # user_id: user.id,
109
- # is_key: true,
110
- # department_id: user.department_id,
111
- # name: user.real_name
112
- # )
113
- # teacher.save
114
- # key_peprson = KeyPerson.new(teacher_params)
115
- # key_peprson.teacher = teacher
116
- # end
117
- #
118
- # follow_up.key_person << key_peprson
119
- # if follow_up.save!
120
- # render_success
121
- # else
122
- # render_failure follow_up
123
- # end
124
- # rescue ActiveRecord::RecordInvalid => e
125
- # if e.message.include?("Teacher已经被使用") || e.message.include?('Key person是无效的')
126
- # render_failure '该老师已在关键人列表中'
127
- # else
128
- # render_failure e.message
129
- # end
130
- # end
131
43
 
132
44
  private
133
45
 
134
46
  def load_teacher
135
47
  @teacher = Teacher.find(params[:teacher_id])
136
48
  end
137
- #
49
+
138
50
  def follow_up_params
139
51
  params.permit(:attitude_id, :follow_id, :course_plan_id, :course_build_id, :description)
140
52
  end
141
- #
142
- # def teacher_params
143
- # params.permit(:professional_title, :job, :attitude_id, :sex, :birth_date, :remark)
144
- # end
145
53
 
146
54
  end
147
55
  end
@@ -0,0 +1,5 @@
1
+ module EducodeSales
2
+ class BusinessExportRecord < ApplicationRecord
3
+ belongs_to :staff
4
+ end
5
+ end
@@ -223,4 +223,10 @@
223
223
  });
224
224
 
225
225
  });
226
- </script>
226
+ </script>
227
+ <style>
228
+ .layui-table-tool-temp{
229
+ padding-right: 0px; !important;
230
+ }
231
+
232
+ </style>
@@ -12,7 +12,7 @@
12
12
  <div class="layui-inline">
13
13
  <label class="layui-form-label required">活动时间</label>
14
14
  <div class="layui-input-block">
15
- <input type="text" name="start_at" required lay-verify="required" class="layui-input" id="new_time" placeholder="请选择时间">
15
+ <input type="text" name="start_at" autocomplete="off" required lay-verify="required" class="layui-input" id="new_time" placeholder="请选择时间">
16
16
  </div>
17
17
  </div>
18
18
  <div class="layui-inline">