educode_sales 0.6.6 → 0.6.7

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 (27) 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 +81 -43
  4. data/app/controllers/educode_sales/money_plans_controller.rb +2 -2
  5. data/app/controllers/educode_sales/sale_trends_controller.rb +105 -18
  6. data/app/controllers/educode_sales/teacher_follows_controller.rb +1 -93
  7. data/app/models/educode_sales/business_export_record.rb +5 -0
  8. data/app/views/educode_sales/activities/index.html.erb +7 -1
  9. data/app/views/educode_sales/activities/new.html.erb +1 -1
  10. data/app/views/educode_sales/businesses/edit_follow_record.html.erb +4 -4
  11. data/app/views/educode_sales/businesses/edit_plan.html.erb +5 -2
  12. data/app/views/educode_sales/businesses/export_records.html.erb +53 -0
  13. data/app/views/educode_sales/businesses/export_records.json.jbuilder +11 -0
  14. data/app/views/educode_sales/businesses/index.html.erb +66 -5
  15. data/app/views/educode_sales/businesses/index.json.jbuilder +31 -2
  16. data/app/views/educode_sales/businesses/new_follow_record.html.erb +6 -5
  17. data/app/views/educode_sales/commons/index.html.erb +7 -1
  18. data/app/views/educode_sales/money_plans/index.html.erb +2 -2
  19. data/app/views/educode_sales/roles/index.html.erb +7 -1
  20. data/app/views/educode_sales/sale_trends/trends.html.erb +96 -44
  21. data/app/views/educode_sales/sale_trends/trends.json.jbuilder +2 -1
  22. data/app/views/educode_sales/teachers/index.html.erb +1 -1
  23. data/app/views/layouts/educode_sales/application.html.erb +1 -1
  24. data/config/routes.rb +2 -0
  25. data/db/migrate/20210902064109_create_educode_sales_role_permissions.rb +2 -0
  26. data/lib/educode_sales/version.rb +1 -1
  27. metadata +5 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10da162d2ac59ca7795046ebe7239e9c3b64851c4b0ea8fb519eaf0667cd78bf
4
- data.tar.gz: faf089944ea187641184a31781c809597ca0327eb3b9af8a553391c4d07366b3
3
+ metadata.gz: f6dbbb6a86049648541dc1d2fb1ec36eec9e24562bd17693725b1e3b498be3c0
4
+ data.tar.gz: 7d4dffa34c61c38e66664d685244f4485d1cf7021c7115fb52903155efd3aac8
5
5
  SHA512:
6
- metadata.gz: 17fe4f762532aa69ab8f29e5c9c7f23aca27f0c22ac38fd7570d6a435039dd2a5b344db15104c2e15de9f0032a7e30f2b3c135cad7385bbb961cb3dd7e6eb167
7
- data.tar.gz: 69fba60e0c97e2c9fbb1debf1ce4a1fab27527260ee87696b7d5861fa0c0ec6deb500efaa1eeafdebdaa3f19a0713e9ddb64c11317a608850c199e7a4bde78ec
6
+ metadata.gz: dc84606ad701fb65520d5be1d79f59c83bad909b93fb3d6b4b61b7bc22e037c7b58a94bd9f13f9d8f9bfc6a37d891a168e04c23453fb5590fb4e479878025ed2
7
+ data.tar.gz: fefca5856e9a3c84876b2dcff7fd9c7415ca1d935f141a367b4dcc3c6b549965febef90454afcfe6462b93fd716a38b21b1899947fe0292353c5dc9f7dfaaaf3
@@ -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
@@ -36,6 +13,7 @@ module EducodeSales
36
13
  # @more = can?(:create, EducodeSales::SalePlan) || can?(:update, EducodeSales::Business) || can?(:destroy, EducodeSales::Business) || can?(:show_file, EducodeSales::Business)
37
14
  @more = true
38
15
  gon.menus = []
16
+ gon.export_menus = []
39
17
  gon.place = params[:place_id].present? ? [{ value: params[:place_id], name: EducodeSales::Place.find(params[:place_id]).name }] : []
40
18
  gon.business_type = Common.where(clazz: 'business_type').map do |d|
41
19
  {value: d.id, name: d.name}
@@ -58,6 +36,11 @@ module EducodeSales
58
36
  if can?(:destroy, EducodeSales::Business)
59
37
  gon.menus << { title: '删除', event: 'delete' }
60
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' }
61
44
  end
62
45
  format.json do
63
46
  if @current_admin.is_admin?
@@ -81,41 +64,56 @@ module EducodeSales
81
64
  @year = params[:q][:name].split("-")[1].present? ? params[:q][:name].split("-")[1] : ''
82
65
  end
83
66
 
84
- if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-现有商机)"
85
- a_id = Common.find_by(extras: EducodeSales::Common::ATYPE)&.id
86
- b_id = Common.find_by(extras: EducodeSales::Common::BTYPE)&.id
87
- c_id = Common.find_by(extras: EducodeSales::Common::CTYPE)&.id
88
- d_id = Common.find_by(extras: EducodeSales::Common::DTYPE)&.id
89
- e_id = Common.find_by(extras: EducodeSales::Common::ETYPE)&.id
90
- o_id = Common.find_by(extras: EducodeSales::Common::OTYPE)&.id
91
- ids = [a_id ,b_id ,c_id ,d_id ,e_id ,o_id]
92
- @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("
93
71
  JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
94
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
+
95
79
  end
96
80
 
97
81
  if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-" + @year + "-已中标商机)"
98
82
  stage_ids = Common.where(clazz: '商机阶段', name: ['已中标','已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
99
- @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("
100
89
  JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
101
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
+
102
93
  end
103
94
 
104
95
  if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-" + @year + "-已签单商机)"
105
96
  s_stage_ids = Common.where(clazz: '商机阶段', name: ['已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
106
- @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("
107
103
  JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
108
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
109
106
  end
110
107
 
111
108
  if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-" + @year + "-已回款商机)"
112
109
  x_id = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
113
- # @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("
114
- # JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
115
- # ").where.not("educode_sales_follow_ups.clazz_id = ?",x_id)
116
110
  year_time = "#{@year}-01-01 00:00:00"
117
111
  year_over_time = "#{@year}-12-31 23:59:59"
118
- @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
119
117
  end
120
118
 
121
119
  if params[:q].present? && params[:q][:all].present?
@@ -129,7 +127,7 @@ module EducodeSales
129
127
  end
130
128
 
131
129
  @businesses = @businesses
132
- 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 + "-现有商机)"
133
131
  @businesses = @businesses.where("educode_sales_businesses.name like ?", "%#{params[:q][:name]}%")
134
132
  end
135
133
  if params[:q].present? && params[:q][:department].present?
@@ -202,9 +200,7 @@ module EducodeSales
202
200
 
203
201
  @business_count = @businesses.count
204
202
 
205
-
206
-
207
- @businesses = @businesses.select("
203
+ @businesses_exports = @businesses.select("
208
204
  educode_sales_businesses.*,
209
205
  last_follow.invitation_at,
210
206
  last_follow.reception_at,
@@ -215,7 +211,9 @@ module EducodeSales
215
211
  (last_follow.actual_amount - educode_sales_businesses.return_money) as wait_return_money,
216
212
  last_follow.total_amount").joins("
217
213
  LEFT JOIN educode_sales_follow_ups AS last_follow ON educode_sales_businesses.last_follow_up_id = last_follow.id
218
- ").page(params[:page]).per(params[:limit])
214
+ ")
215
+
216
+ @businesses = @businesses_exports.page(params[:page]).per(params[:limit])
219
217
  end
220
218
  end
221
219
  end
@@ -350,6 +348,46 @@ module EducodeSales
350
348
  render layout: false
351
349
  end
352
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
+
353
391
  private
354
392
 
355
393
  def load_business
@@ -19,9 +19,9 @@ module EducodeSales
19
19
  level = @current_admin.role.role_areas.find_by(clazz: '回款管理').level
20
20
  case level
21
21
  when '自己'
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.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)
23
23
  when '区域'
24
- 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
25
25
  school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id)
26
26
  b_ids = Business.where(school_id: school_ids).pluck(:last_follow_up_id)
27
27
  ids = a_ids + b_ids
@@ -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 = ['已中标','已签单','已回款']
@@ -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">
@@ -81,10 +81,9 @@
81
81
  <br>
82
82
  <div class="layui-inline place_select">
83
83
  <label class="layui-form-label">渠道</label>
84
- <div class="layui-input-inline" style="z-index: 101">
84
+ <div class="layui-input-inline" style="">
85
85
  <div id="edit_place" style="width: 190px;"></div>
86
86
  </div>
87
- 总额里,渠道拿到的部分。
88
87
  </div>
89
88
  <br>
90
89
  <div class="layui-inline">
@@ -92,6 +91,7 @@
92
91
  <div class="layui-input-inline">
93
92
  <input name="divide_amount" class="layui-input" value="<%= @follow_up.divide_amount%>">
94
93
  </div>
94
+ 总额里,渠道拿到的部分。
95
95
  </div>
96
96
  <div class="layui-form-item">
97
97
  <div class="layui-inline">
@@ -105,10 +105,10 @@
105
105
  </div>
106
106
  <div class="layui-form-item">
107
107
  <label class="layui-form-label">指定跟进人</label>
108
- <div class="layui-input-inline" style="z-index: 102">
108
+ <div class="layui-input-inline" style="">
109
109
  <div id="edit_assign_follow" style="width: 512px;"></div>
110
110
  </div>
111
- <div class="layui-inline" style="padding: 9px 15px">
111
+ <div class="layui-inline" style="padding: 9px 15px;z-index: -1">
112
112
  <label class="layui-form-label" style="padding-left: 220px"></label>
113
113
  指定跟进人和商机创建者,同时拥有对该商机的管理权限
114
114
  </div>
@@ -12,12 +12,15 @@
12
12
  </div>
13
13
  </div>
14
14
  <div class="layui-input-inline" style="width: 300px;">
15
- <label class="layui-form-label required">回款金额(万)</label>
15
+ <label class="layui-form-label required">回款金额</label>
16
16
  <div class="layui-input-block">
17
17
  <input type="number" name="amount" autocomplete="off" lay-verify="required" lay-reqtext="回款金额不能为空"
18
18
  placeholder="请输入回款金额" value="" class="layui-input" id="return_money_amount">
19
19
  </div>
20
20
  </div>
21
+ <div class="layui-input-inline" style="width: 0;!important;">
22
+ <label class="layui-form-label" style="padding-left: 0;width: 10px;!important;">万</label>
23
+ </div>
21
24
  <div class="layui-input-inline" style="width: 300px;" id="professional_title_div">
22
25
  <label class="layui-form-label required">状态</label>
23
26
  <div class="layui-input-block">
@@ -115,7 +118,7 @@
115
118
  }, {
116
119
  field: 'amount',
117
120
  width: 200,
118
- title: '回款金额',
121
+ title: '回款金额(万)',
119
122
  edit: true
120
123
  }, {
121
124
  field: 'clazz',
@@ -0,0 +1,53 @@
1
+ <script type="text/html" id="activity_toolbar">
2
+ <div class="layui-btn-container">
3
+ <span class="table-label">导出记录</span>
4
+ </div>
5
+ </script>
6
+ <div class="min-height-table">
7
+ <table class="layui-hide" id="activities_table" lay-filter="activities_table"></table>
8
+ </div>
9
+
10
+ <script type="text/html" id="currentTableBar">
11
+ </script>
12
+
13
+ <script>
14
+ layui.use(['form', 'table', 'miniPage', 'element', 'request'], function () {
15
+ var $ = layui.jquery,
16
+ form = layui.form,
17
+ table = layui.table,
18
+ request = layui.request,
19
+ miniPage = layui.miniPage;
20
+
21
+ table.render({
22
+ elem: '#activities_table',
23
+ url: '/missions/businesses/export_records',
24
+ toolbar: '#activity_toolbar',
25
+ defaultToolbar: [],
26
+ cols: [
27
+ [
28
+ {
29
+ field: 'id',
30
+ title:'序号',type: 'numbers',
31
+ },
32
+ {
33
+ field: 'name',
34
+ title: '文件名',
35
+ },
36
+ {
37
+ field: 'staff',
38
+ title: '导出人',
39
+ },
40
+ {
41
+ field: 'created_at',
42
+ title: '导出时间',
43
+ },
44
+ ]
45
+ ],
46
+ limit: 20,
47
+ limits: [10,15,20,30,40,50,60,70,80,90],
48
+ page: true
49
+ });
50
+
51
+
52
+ });
53
+ </script>
@@ -0,0 +1,11 @@
1
+ json.data do
2
+ json.array! @records do |d|
3
+ json.id d.id
4
+ json.name d.name
5
+ json.staff d.staff&.user&.real_name
6
+ json.created_at d.created_at.to_s
7
+ end
8
+ end
9
+ json.code 0
10
+ json.count @records.total_count
11
+ json.msg 'succcess'