educode_sales 0.4.5 → 0.4.9

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 (65) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/educode_sales/indexLogo.png +0 -0
  3. data/app/controllers/educode_sales/businesses_controller.rb +67 -2
  4. data/app/controllers/educode_sales/follow_ups_controller.rb +1 -1
  5. data/app/controllers/educode_sales/home_controller.rb +4 -0
  6. data/app/controllers/educode_sales/operation_plans_controller.rb +17 -6
  7. data/app/controllers/educode_sales/operation_reports_controller.rb +9 -3
  8. data/app/controllers/educode_sales/operations_controller.rb +1 -1
  9. data/app/controllers/educode_sales/plans_controller.rb +30 -15
  10. data/app/controllers/educode_sales/sale_reports_controller.rb +9 -3
  11. data/app/controllers/educode_sales/sale_trends_controller.rb +8 -7
  12. data/app/controllers/educode_sales/sales_controller.rb +2 -2
  13. data/app/controllers/educode_sales/upload_files_controller.rb +99 -0
  14. data/app/models/educode_sales/common.rb +4 -0
  15. data/app/models/educode_sales/sale_plan.rb +1 -0
  16. data/app/views/educode_sales/activities/show_teachers.html.erb +16 -16
  17. data/app/views/educode_sales/businesses/edit_follow_record.html.erb +15 -0
  18. data/app/views/educode_sales/businesses/file.html.erb +140 -0
  19. data/app/views/educode_sales/businesses/index.html.erb +64 -10
  20. data/app/views/educode_sales/businesses/index.json.jbuilder +3 -1
  21. data/app/views/educode_sales/businesses/new_follow_record.html.erb +17 -0
  22. data/app/views/educode_sales/businesses/show_follow.html.erb +47 -11
  23. data/app/views/educode_sales/businesses/show_follow.json.jbuilder +2 -0
  24. data/app/views/educode_sales/businesses/show_follow_record.html.erb +79 -1
  25. data/app/views/educode_sales/businesses/time_line.html.erb +58 -0
  26. data/app/views/educode_sales/businesses/upload_file.html.erb +43 -0
  27. data/app/views/educode_sales/home/index.html.erb +1 -1
  28. data/app/views/educode_sales/home/search_operation_teacher.json.jbuilder +12 -0
  29. data/app/views/educode_sales/operation_plans/_monthPlan.html.erb +7 -7
  30. data/app/views/educode_sales/operation_plans/_monthly.html.erb +8 -8
  31. data/app/views/educode_sales/operation_plans/_weekPlan.html.erb +8 -8
  32. data/app/views/educode_sales/operation_plans/_weekly.html.erb +9 -9
  33. data/app/views/educode_sales/operation_plans/edit_month.html.erb +6 -6
  34. data/app/views/educode_sales/operation_plans/edit_week.html.erb +7 -7
  35. data/app/views/educode_sales/operation_plans/new_month.html.erb +50 -4
  36. data/app/views/educode_sales/operation_plans/new_monthly.html.erb +12 -0
  37. data/app/views/educode_sales/operation_plans/new_week.html.erb +47 -4
  38. data/app/views/educode_sales/operation_plans/new_weekly.html.erb +12 -0
  39. data/app/views/educode_sales/operation_reports/audit.html.erb +22 -10
  40. data/app/views/educode_sales/operation_reports/edit.html.erb +22 -10
  41. data/app/views/educode_sales/operation_reports/show.html.erb +22 -10
  42. data/app/views/educode_sales/plans/_monthPlan.html.erb +8 -8
  43. data/app/views/educode_sales/plans/_monthly.html.erb +7 -7
  44. data/app/views/educode_sales/plans/_weekPlan.html.erb +7 -7
  45. data/app/views/educode_sales/plans/_weekly.html.erb +8 -8
  46. data/app/views/educode_sales/plans/edit_month.html.erb +7 -7
  47. data/app/views/educode_sales/plans/edit_week.html.erb +8 -8
  48. data/app/views/educode_sales/plans/new_month.html.erb +2 -2
  49. data/app/views/educode_sales/plans/new_monthly.html.erb +12 -0
  50. data/app/views/educode_sales/plans/new_week.html.erb +2 -2
  51. data/app/views/educode_sales/plans/new_weekly.html.erb +12 -0
  52. data/app/views/educode_sales/sale_reports/audit.html.erb +20 -8
  53. data/app/views/educode_sales/sale_reports/edit.html.erb +20 -8
  54. data/app/views/educode_sales/sale_reports/show.html.erb +20 -9
  55. data/app/views/educode_sales/sale_trends/trends.html.erb +6 -6
  56. data/app/views/educode_sales/sales/operations.html.erb +0 -4
  57. data/app/views/educode_sales/teachers/index.html.erb +14 -14
  58. data/app/views/educode_sales/teachers/show_follow.html.erb +10 -4
  59. data/app/views/educode_sales/upload_files/index.json.jbuilder +13 -0
  60. data/app/views/layouts/educode_sales/application.html.erb +11 -3
  61. data/config/routes.rb +13 -0
  62. data/db/migrate/20211102085743_add_bidded_date_educode_sales_follow_ups.rb +6 -0
  63. data/lib/educode_sales/version.rb +1 -1
  64. metadata +10 -3
  65. data/app/assets/images/educode_sales/indexlogo.png +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 685592848049f4a9fbcb75c52c46eb4a1ad1ee9cf14725b44a7c79ad0e0714d1
4
- data.tar.gz: 8b3ac5946bdb350f6bb92b79f7ab9a5ba91678e24c24ae70b06766709f84fb3d
3
+ metadata.gz: e75cbf87f4530e2665dd16d6fa56d82a14a0479ba0ce6f9f2cb39f5282ddb034
4
+ data.tar.gz: b4ab6a572903f23688eeb0441f66776f43ca4cabc70467cb013fff2f1c922473
5
5
  SHA512:
6
- metadata.gz: 14cdf1d7faa137de66574701ff7e13e76820bfed31e92960118a1407358c69134c07e51f251532e38de575064d667ab9f2c54d9299a6f59f51a150ffd1b73d83
7
- data.tar.gz: 15b1c39abb61f478992198b04698af35cc90e1a6077b697c83d107e1d47c448fbc571436681b630e147aee10fbcb73607e0f7aae5567359e2ceeab4188959f98
6
+ metadata.gz: 05cac4d3624e3c08a12957400aef7a091ef51b7edd288e767a6f31f8f8bdfdab6af587335abac527005ed657d115d8a938ef6a8e62f0c6c33514041857335309
7
+ data.tar.gz: d23d1bd4ce8bcb827e5423e01351eb5c661b95cb64f4c61076cf974752c360b35587c74263e69f6a6392255d08686edc77a4e5813032534f00663afe8724ca2b
@@ -3,6 +3,30 @@ require_dependency "educode_sales/application_controller"
3
3
  module EducodeSales
4
4
  class BusinessesController < ApplicationController
5
5
 
6
+ def file
7
+ @root = Rails.root
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
  def index
7
31
  authorize! :read, Business
8
32
  respond_to do |format|
@@ -15,6 +39,8 @@ module EducodeSales
15
39
  gon.menus << { title: '添加周计划', event: 'week' }
16
40
  gon.menus << { title: '添加月计划', event: 'month' }
17
41
  end
42
+ gon.menus << { title: '跟进时间线', event: 'time_line' }
43
+ gon.menus << { title: '附件管理', event: 'file' }
18
44
  if can?(:update, EducodeSales::Business)
19
45
  gon.menus << { title: '编辑', event: 'edit' }
20
46
  end
@@ -40,6 +66,36 @@ module EducodeSales
40
66
  end
41
67
  end
42
68
 
69
+ if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-现有商机)"
70
+ a_id = Common.find_by(extras: EducodeSales::Common::ATYPE)&.id
71
+ b_id = Common.find_by(extras: EducodeSales::Common::BTYPE)&.id
72
+ c_id = Common.find_by(extras: EducodeSales::Common::CTYPE)&.id
73
+ d_id = Common.find_by(extras: EducodeSales::Common::DTYPE)&.id
74
+ ids = [a_id ,b_id ,c_id ,d_id]
75
+ @businesses = @businesses.joins("
76
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
77
+ ").where("educode_sales_follow_ups.clazz_id in (?)",ids)
78
+ end
79
+
80
+ if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-已中标商机)"
81
+ @businesses = @businesses.joins("
82
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
83
+ ").where("educode_sales_follow_ups.bidded_date > ? AND educode_sales_follow_ups.bidded_date < ?", "#{Time.now.year}-01-01", "#{Time.now.year}-12-31")
84
+ end
85
+
86
+ if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-已签单商机)"
87
+ @businesses = @businesses.joins("
88
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
89
+ ").where("educode_sales_follow_ups.signed_date > ? AND educode_sales_follow_ups.signed_date < ?", "#{Time.now.year}-01-01", "#{Time.now.year}-12-31")
90
+ end
91
+
92
+ if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-已回款商机)"
93
+ x_id = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
94
+ @businesses = @businesses.where("educode_sales_businesses.created_at > ? AND educode_sales_businesses.created_at < ? AND educode_sales_businesses.return_money > 0", "#{Time.now.year}-01-01", "#{Time.now.year}-12-31").joins("
95
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
96
+ ").where.not("educode_sales_follow_ups.clazz_id = ?",x_id)
97
+ end
98
+
43
99
  if params[:q].present? && params[:q][:all].present?
44
100
  @businesses = @businesses
45
101
  end
@@ -51,7 +107,7 @@ module EducodeSales
51
107
  end
52
108
 
53
109
  @businesses = @businesses
54
- if params[:q].present? && params[:q][:name].present?
110
+ if params[:q].present? && params[:q][:name].present? && params[:q][:name] != "(销售态势-已中标商机)" && params[:q][:name] != "(销售态势-已签单商机)" && params[:q][:name] != "(销售态势-已回款商机)" && params[:q][:name] != "(销售态势-现有商机)"
55
111
  @businesses = @businesses.where("educode_sales_businesses.name like ?", "%#{params[:q][:name]}%")
56
112
  end
57
113
  if params[:q].present? && params[:q][:department].present?
@@ -213,7 +269,16 @@ module EducodeSales
213
269
  end
214
270
 
215
271
  def show_follow_record
216
- @follow_up = FollowUp.find(params[:follow_up_id])
272
+ follow_up_id = params[:follow_up_id]
273
+ @follow_up = FollowUp.find(follow_up_id)
274
+ id = @follow_up.id
275
+ @follow_ups = Business.find(@follow_up.business_id).follow_ups
276
+ ids = @follow_ups.ids
277
+ size = ids.size
278
+ ids = ids.reverse
279
+ index = ids.index(id)
280
+ @next_id = (index != size - 1 && size > 1) ? ids[index + 1] : 0
281
+ @pre_id = (index != 0 && size > 1) ? ids[index - 1] : 0
217
282
  render layout: false
218
283
  end
219
284
 
@@ -156,7 +156,7 @@ module EducodeSales
156
156
  end
157
157
 
158
158
  def follow_up_params
159
- params.permit(:clazz_id, :stage_id, :invitation_at, :reception_at, :total_amount, :actual_amount, :divide_amount, :description, :advise, :place_id)
159
+ params.permit(:clazz_id, :stage_id, :invitation_at, :reception_at, :total_amount, :actual_amount, :divide_amount, :description, :advise, :place_id, :bidded_date, :signed_date)
160
160
  end
161
161
 
162
162
  def teacher_params
@@ -33,6 +33,10 @@ module EducodeSales
33
33
  @data += User.joins(:user_extension).where.not(id: user_ids).where("identity='teacher'", user_ids).where("lastname like ?", "%#{params[:q]}%").limit(50)
34
34
  end
35
35
 
36
+ def search_operation_teacher
37
+ @data = @current_admin.teachers.where("name like ? and is_key = false", "%#{params[:q]}%").limit(20)
38
+ end
39
+
36
40
  def search_edu_teacher
37
41
  @data = User.joins(:user_extension).where("identity='teacher'").where("concat(lastname, firstname) like :q OR phone like :q OR mail like :q", q: "%#{params[:q]}%").limit(50)
38
42
  end
@@ -21,7 +21,7 @@ module EducodeSales
21
21
  @sale_plans = OperationPlan.where(staff_id: @current_admin.id)
22
22
  when '区域'
23
23
  staff_ids = Staff.joins(user: [user_extension: [department: :school]]).where("schools.province in (?)", @current_admin.areas.pluck(:name)).pluck(:id)
24
- @sale_plans = OperationPlan.where("staff_id in (?)", staff_ids)
24
+ @sale_plans = OperationPlan.where("staff_id in (?) OR educode_sales_operation_plans.staff_id = ?", staff_ids, @current_admin.id)
25
25
  else
26
26
  @sale_plans = OperationPlan
27
27
  end
@@ -44,7 +44,7 @@ module EducodeSales
44
44
  if params[:sort].present? && params[:sort][:field]
45
45
  @sale_plans = @sale_plans.order("#{params[:sort][:field]} #{params[:sort][:order]}")
46
46
  else
47
- @sale_plans = @sale_plans.order("updated_at desc")
47
+ @sale_plans = @sale_plans.order("created_at desc")
48
48
  end
49
49
  @sale_plans = @sale_plans.page(params[:page]).per(params[:limit])
50
50
  end
@@ -54,11 +54,11 @@ module EducodeSales
54
54
  @teacher = Teacher.find_by(id: params[:teacher_id])
55
55
  week = Time.now.strftime('%W').to_i
56
56
  if week > 3
57
- @weeks = [week, week - 1, week - 2]
57
+ @weeks = [[week+2,week+2], [week+1,week+1], [week.to_s + ' 本周',week], [week - 1,week - 1], [week - 2,week - 2]]
58
58
  elsif week == 2
59
- @weeks = [week, week - 1]
59
+ @weeks = [[week.to_s + ' 本周',week], [week - 1,week - 1]]
60
60
  else
61
- @weeks = [week]
61
+ @weeks = [[week.to_s + ' 本周',week]]
62
62
  end
63
63
  @teachers = @current_admin.teachers.where(is_key: 0).pluck(:name, :id)
64
64
  render layout: false
@@ -77,6 +77,8 @@ module EducodeSales
77
77
  end
78
78
 
79
79
  def new_weekly
80
+ @area =@current_admin.areas.present? ? @current_admin.areas.pluck(:name).join("、") : ''
81
+ @name = @current_admin.user.real_name
80
82
  sale_plans = OperationPlan.where(month: Time.now.strftime("%Y-%m") + "-01 00:00:00", weekly: Time.now.strftime('%W').to_i, staff_id: @current_admin.id)
81
83
  @rate = sale_plans.present? ? (sale_plans.sum("finish_rate") / sale_plans.size) : 0
82
84
  @departments_count = sale_plans.joins(:teacher).count("distinct(department_id)")
@@ -92,6 +94,8 @@ module EducodeSales
92
94
  end
93
95
 
94
96
  def new_monthly
97
+ @area =@current_admin.areas.present? ? @current_admin.areas.pluck(:name).join("、") : ''
98
+ @name = @current_admin.user.real_name
95
99
  sale_plans = OperationPlan.where(month: Time.now.strftime("%Y-%m") + "-01 00:00:00", staff_id: @current_admin.id, weekly: nil)
96
100
  @rate = sale_plans.present? ? (sale_plans.sum("finish_rate") / sale_plans.size) : 0
97
101
  @departments_count = sale_plans.joins(:teacher).count("distinct(department_id)")
@@ -131,7 +135,7 @@ module EducodeSales
131
135
  if @sale_plan.weekly.present?
132
136
  week = Time.now.strftime('%W').to_i
133
137
  if week > 3
134
- @weeks = [week, week - 1, week - 2]
138
+ @weeks = [week+2, week+1, week, week - 1, week - 2]
135
139
  elsif week == 2
136
140
  @weeks = [week, week - 1]
137
141
  else
@@ -139,6 +143,13 @@ module EducodeSales
139
143
  end
140
144
  @weeks << @sale_plan.weekly
141
145
  @weeks = @weeks.uniq.sort
146
+ @weeks = @weeks.map do |d|
147
+ if d == week
148
+ ["#{d} 本周", d]
149
+ else
150
+ [d, d]
151
+ end
152
+ end
142
153
  end
143
154
  @months = [Time.now.strftime("%Y-%m"), Time.now.months_ago(1).strftime("%Y-%m")]
144
155
  @months << @sale_plan.month.strftime("%Y-%m")
@@ -18,7 +18,7 @@ module EducodeSales
18
18
  @sale_reports = OperationReport.where(staff_id: @current_admin.id)
19
19
  when '区域'
20
20
  staff_ids = Staff.joins(user: [user_extension: [department: :school]]).where("schools.province in (?)", @current_admin.areas.pluck(:name)).pluck(:id)
21
- @sale_reports = OperationReport.where("staff_id in (?)", staff_ids)
21
+ @sale_reports = OperationReport.where("staff_id in (?) OR educode_sales_operation_reports.staff_id = ?", staff_ids, @current_admin.id)
22
22
  else
23
23
  @sale_reports = OperationReport
24
24
  end
@@ -40,7 +40,7 @@ module EducodeSales
40
40
  if params[:sort].present? && params[:sort][:field]
41
41
  @sale_reports = @sale_reports.order("#{params[:sort][:field]} #{params[:sort][:order]}")
42
42
  else
43
- @sale_reports = @sale_reports.order("updated_at desc")
43
+ @sale_reports = @sale_reports.order("created_at desc")
44
44
  end
45
45
  @sale_reports = @sale_reports.page(params[:page]).per(params[:limit])
46
46
  end
@@ -67,6 +67,8 @@ module EducodeSales
67
67
 
68
68
  def show
69
69
  @sale_report = OperationReport.find(params[:id])
70
+ @name = @sale_report.staff.user.real_name
71
+ @area = @sale_report.staff.areas.present? ? @sale_report.staff.areas.pluck(:name).join("、") : ''
70
72
  render layout: false
71
73
  end
72
74
 
@@ -78,6 +80,8 @@ module EducodeSales
78
80
 
79
81
  def edit
80
82
  @sale_report = OperationReport.find(params[:id])
83
+ @name = @sale_report.staff.user.real_name
84
+ @area = @sale_report.staff.areas.present? ? @sale_report.staff.areas.pluck(:name).join("、") : ''
81
85
  render layout: false
82
86
  end
83
87
 
@@ -113,6 +117,8 @@ module EducodeSales
113
117
 
114
118
  def audit
115
119
  @sale_report = OperationReport.find(params[:id])
120
+ @name = @sale_report.staff.user.real_name
121
+ @area = @sale_report.staff.areas.present? ? @sale_report.staff.areas.pluck(:name).join("、") : ''
116
122
  render layout: false
117
123
  end
118
124
 
@@ -126,6 +132,6 @@ module EducodeSales
126
132
  params.permit(:level1_opinion, :level2_opinion, :level3_opinion, :level1_score, :level2_score, :level3_score)
127
133
  end
128
134
 
129
-
135
+
130
136
  end
131
137
  end
@@ -4,7 +4,7 @@ module EducodeSales
4
4
  class OperationsController < ApplicationController
5
5
 
6
6
  def trends
7
- @years = (1..(Time.now.year - 2020)).map { |d| 2020 + d }
7
+ @years = (1..(Time.now.year - 2014)).reverse_each.map { |d| 2014 + d }
8
8
  @year = params[:year] ? params[:year] : Time.now.year
9
9
  @operation_trend = OperationTrend.find_or_create_by(year: @year)
10
10
  @inc_users_count = User.where("created_on > ? AND created_on <= ?", "#{@year}-01-01 00:00:00", "#{@year}-12-31 23:59:59").count
@@ -22,7 +22,7 @@ module EducodeSales
22
22
  @sale_plans = SalePlan.where(staff_id: @current_admin.id)
23
23
  when '区域'
24
24
  staff_ids = Staff.joins(user: [user_extension: [department: :school]]).where("schools.province in (?)", @current_admin.areas.pluck(:name)).pluck(:id)
25
- @sale_plans = SalePlan.where("staff_id in (?)", staff_ids)
25
+ @sale_plans = SalePlan.where("staff_id in (?) OR educode_sales_sale_plans.staff_id = ?", staff_ids, @current_admin.id)
26
26
  else
27
27
  @sale_plans = SalePlan
28
28
  end
@@ -44,7 +44,7 @@ module EducodeSales
44
44
  if params[:sort].present? && params[:sort][:field]
45
45
  @sale_plans = @sale_plans.order("#{params[:sort][:field]} #{params[:sort][:order]}")
46
46
  else
47
- @sale_plans = @sale_plans.order("updated_at desc")
47
+ @sale_plans = @sale_plans.order("created_at desc")
48
48
  end
49
49
 
50
50
  @sale_plans = @sale_plans.page(params[:page]).per(params[:limit])
@@ -59,7 +59,7 @@ module EducodeSales
59
59
  def create
60
60
  plan = @current_admin.sale_plans.build(plan_params)
61
61
  plan.month = params["month"] + "-1"
62
- plan.business = @current_admin.businesses.find_by(id: params[:business_id])
62
+ plan.business = Business.find_by(id: params[:business_id])
63
63
  if plan.save
64
64
  render_success
65
65
  else
@@ -72,19 +72,21 @@ module EducodeSales
72
72
  @business = Business.find_by(id: params[:business_id])
73
73
  week = Time.now.strftime('%W').to_i
74
74
  if week > 3
75
- @weeks = [week, week - 1, week - 2]
75
+ @weeks = [[week+2,week+2], [week+1,week+1], [week.to_s + ' 本周',week], [week - 1,week - 1], [week - 2,week - 2]]
76
76
  elsif week == 2
77
- @weeks = [week, week - 1]
77
+ @weeks = [[week.to_s + ' 本周',week], [week - 1,week - 1]]
78
78
  else
79
- @weeks = [week]
79
+ @weeks = [[week.to_s + ' 本周',week]]
80
80
  end
81
- ids = AssignFollowUp.where(staff_id: @current_admin.id).pluck(:follow_up_id)
82
- ids1 = FollowUp.where(id: ids).pluck(:business_id)
83
- @businesses =Business.where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", ids1, @current_admin.id).pluck(:name, :id)
81
+ business_ids = EducodeSales::AssignFollowUp.joins(:follow_up).where(staff_id: @current_admin.id).pluck :business_id
82
+ @businesses = Business.includes(:department, :last_follow_up).where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", business_ids, @current_admin.id).order(created_at: :desc)
83
+ @businesses = @businesses.map { |b| [b.name + "(" + b.department.school.name + ")" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : '无'), b.id] }
84
84
  render layout: false
85
85
  end
86
86
 
87
87
  def new_weekly
88
+ @area =@current_admin.areas.present? ? @current_admin.areas.pluck(:name).join("、") : ''
89
+ @name = @current_admin.user.real_name
88
90
  sale_plans = SalePlan.where(month: Time.now.strftime("%Y-%m") + "-01 00:00:00", weekly: Time.now.strftime('%W').to_i, staff_id: @current_admin.id)
89
91
  @rate = sale_plans.present? ? (sale_plans.sum("finish_rate") / sale_plans.size) : 0
90
92
  @departments_count = sale_plans.joins(:business).count("distinct(department_id)")
@@ -94,13 +96,15 @@ module EducodeSales
94
96
 
95
97
  def new_month
96
98
  @business = Business.find_by(id: params[:business_id])
97
- ids = AssignFollowUp.where(staff_id: @current_admin.id).pluck(:follow_up_id)
98
- ids1 = FollowUp.where(id: ids).pluck(:business_id)
99
- @businesses =Business.where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", ids1, @current_admin.id).pluck(:name, :id)
99
+ business_ids = EducodeSales::AssignFollowUp.joins(:follow_up).where(staff_id: @current_admin.id).pluck :business_id
100
+ @businesses =Business.includes(:department, :last_follow_up).where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", business_ids, @current_admin.id).order(created_at: :desc)
101
+ @businesses = @businesses.map { |b| [b.name + "(" + b.department.school.name + ")" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : '无'), b.id] }
100
102
  render layout: false
101
103
  end
102
104
 
103
105
  def new_monthly
106
+ @area =@current_admin.areas.present? ? @current_admin.areas.pluck(:name).join("、") : ''
107
+ @name = @current_admin.user.real_name
104
108
  sale_plans = SalePlan.where(month: Time.now.strftime("%Y-%m") + "-01 00:00:00", staff_id: @current_admin.id, weekly: nil)
105
109
  @rate = sale_plans.present? ? (sale_plans.sum("finish_rate") / sale_plans.size) : 0
106
110
  @departments_count = sale_plans.joins(:business).count("distinct(department_id)")
@@ -127,12 +131,14 @@ module EducodeSales
127
131
  end
128
132
 
129
133
  def edit_week
130
- @businesses = @current_admin.businesses.pluck(:name, :id)
134
+ business_ids = EducodeSales::AssignFollowUp.joins(:follow_up).where(staff_id: @current_admin.id).pluck :business_id
135
+ @businesses = Business.includes(:department, :last_follow_up).where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", business_ids, @current_admin.id).order(created_at: :desc)
136
+ @businesses = @businesses.map { |b| [b.name + "(" + b.department.school.name + ")" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : '无'), b.id] }
131
137
  @sale_plan = SalePlan.find(params[:id])
132
138
  if @sale_plan.weekly.present?
133
139
  week = Time.now.strftime('%W').to_i
134
140
  if week > 3
135
- @weeks = [week, week - 1, week - 2]
141
+ @weeks = [week+2, week+1, week, week - 1, week - 2]
136
142
  elsif week == 2
137
143
  @weeks = [week, week - 1]
138
144
  else
@@ -140,6 +146,13 @@ module EducodeSales
140
146
  end
141
147
  @weeks << @sale_plan.weekly
142
148
  @weeks = @weeks.uniq.sort
149
+ @weeks = @weeks.map do |d|
150
+ if d == week
151
+ ["#{d} 本周", d]
152
+ else
153
+ [d, d]
154
+ end
155
+ end
143
156
  end
144
157
  @months = [Time.now.strftime("%Y-%m"), Time.now.months_ago(1).strftime("%Y-%m")]
145
158
  @months << @sale_plan.month.strftime("%Y-%m")
@@ -173,7 +186,9 @@ module EducodeSales
173
186
  end
174
187
 
175
188
  def edit_month
176
- @businesses = @current_admin.businesses.pluck(:name, :id)
189
+ business_ids = EducodeSales::AssignFollowUp.joins(:follow_up).where(staff_id: @current_admin.id).pluck :business_id
190
+ @businesses = Business.includes(:department, :last_follow_up).where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", business_ids, @current_admin.id).order(created_at: :desc)
191
+ @businesses = @businesses.map { |b| [b.name + "(" + b.department.school.name + ")" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : '无'), b.id] }
177
192
  @sale_plan = SalePlan.find(params[:id])
178
193
  @finish_rates = []
179
194
  11.times { |d| @finish_rates << ["#{d*10}%", d * 10]}
@@ -9,7 +9,7 @@ module EducodeSales
9
9
  else
10
10
  sale_report = @current_admin.sale_reports.build(month: Date.today.beginning_of_month, weekly: Time.now.strftime('%W').to_i)
11
11
  end
12
-
12
+
13
13
  sale_report.finish_rate = params[:finish_rate]
14
14
  sale_report.client = params[:client]
15
15
  sale_report.content = params[:content]
@@ -23,6 +23,8 @@ module EducodeSales
23
23
 
24
24
  def show
25
25
  @sale_report = SaleReport.find(params[:id])
26
+ @name = @sale_report.staff.user.real_name
27
+ @area = @sale_report.staff.areas.present? ? @sale_report.staff.areas.pluck(:name).join("、") : ''
26
28
  render layout: false
27
29
  end
28
30
 
@@ -51,7 +53,7 @@ module EducodeSales
51
53
  @sale_reports = SaleReport.where(staff_id: @current_admin.id)
52
54
  when '区域'
53
55
  staff_ids = Staff.joins(user: [user_extension: [department: :school]]).where("schools.province in (?)", @current_admin.areas.pluck(:name)).pluck(:id)
54
- @sale_reports = SaleReport.where("staff_id in (?)", staff_ids)
56
+ @sale_reports = SaleReport.where("staff_id in (?) OR educode_sales_sale_reports.staff_id = ?", staff_ids, @current_admin.id)
55
57
  else
56
58
  @sale_reports = SaleReport
57
59
  end
@@ -73,7 +75,7 @@ module EducodeSales
73
75
  if params[:sort].present? && params[:sort][:field]
74
76
  @sale_reports = @sale_reports.order("#{params[:sort][:field]} #{params[:sort][:order]}")
75
77
  else
76
- @sale_reports = @sale_reports.order("updated_at desc")
78
+ @sale_reports = @sale_reports.order("created_at desc")
77
79
  end
78
80
  @sale_reports = @sale_reports.page(params[:page]).per(params[:limit])
79
81
  end
@@ -83,6 +85,8 @@ module EducodeSales
83
85
 
84
86
  def edit
85
87
  @sale_report = SaleReport.find(params[:id])
88
+ @name = @sale_report.staff.user.real_name
89
+ @area = @sale_report.staff.areas.present? ? @sale_report.staff.areas.pluck(:name).join("、") : ''
86
90
  render layout: false
87
91
  end
88
92
 
@@ -118,6 +122,8 @@ module EducodeSales
118
122
 
119
123
  def audit
120
124
  @sale_report = SaleReport.find(params[:id])
125
+ @name = @sale_report.staff.user.real_name
126
+ @area = @sale_report.staff.areas.present? ? @sale_report.staff.areas.pluck(:name).join("、") : ''
121
127
  render layout: false
122
128
  end
123
129
 
@@ -7,20 +7,21 @@ 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 - 2020)).map { |d| 2020 + d }
10
+ @years = (1..(Time.now.year - 2014)).reverse_each.map { |d| 2014 + d }
11
11
  year_time = "#{@year}-01-01 00:00:00"
12
+ year_over_time = "#{@year}-12-31 23:59:59"
12
13
  x = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
13
14
  o = Common.find_by(extras: EducodeSales::Common::OTYPE)&.id
14
15
  @sale_trend = SaleTrend.find_or_create_by(year: @year)
15
- @business_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ? AND educode_sales_follow_ups.clazz_id != ?", x, o).where("educode_sales_follow_ups.created_at >= ?", year_time).sum(:total_amount).round(2)
16
+ @business_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ? AND educode_sales_follow_ups.clazz_id != ?", x, o).sum(:total_amount).round(2)
16
17
  stage_ids = Common.where(clazz: '商机阶段', name: ['已中标','已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
17
- @goal_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.created_at >= ? AND educode_sales_follow_ups.stage_id IN (?)", year_time, stage_ids).sum(:total_amount).round(2)
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)
18
19
  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.created_at >= ? AND educode_sales_follow_ups.stage_id IN (?)", year_time, s_stage_ids).sum(:total_amount).round(2)
20
- @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 >= ?", year_time).sum(:amount).round(2)
21
- a = Common.where(clazz: '商机类型', name: 'A类').pluck(:id)
20
+ @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)
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).where("educode_sales_money_plans.date_at >= ? AND educode_sales_money_plans.date_at <= ? ", year_time, year_over_time).sum(:amount).round(2)
22
+ a = Common.where(clazz: '商机类型', name: Common.find_by(extras: EducodeSales::Common::ATYPE)&.name).pluck(:id)
22
23
  @a_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id IN (?)", a).sum(:total_amount).round(2)
23
- b = Common.where(clazz: '商机类型', name: 'B类').pluck(:id)
24
+ b = Common.where(clazz: '商机类型', name: Common.find_by(extras: EducodeSales::Common::BTYPE)&.name).pluck(:id)
24
25
  @b_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id IN (?)", b).sum(:total_amount).round(2)
25
26
  end
26
27
 
@@ -12,8 +12,8 @@ module EducodeSales
12
12
  end
13
13
  format.json do
14
14
  common = Common.find_by(clazz: 'staff_type', name: '销售')
15
- @a_clazz = Common.find_by(clazz: 'business_type', name: 'A类')
16
- @b_clazz = Common.find_by(clazz: 'business_type', name: 'B类')
15
+ @a_clazz = Common.find_by(clazz: 'business_type', name: Common.find_by(extras: EducodeSales::Common::ATYPE)&.name)
16
+ @b_clazz = Common.find_by(clazz: 'business_type', name: Common.find_by(extras: EducodeSales::Common::BTYPE)&.name)
17
17
  @x = Common.find_by(extras: EducodeSales::Common::XTYPE)
18
18
  @step_ids = Common.where(name: %w(已中标 已签单 已验收 回款中 服务中 已结束), clazz: 'business_step').pluck(:id)
19
19
 
@@ -0,0 +1,99 @@
1
+ require_dependency "educode_sales/application_controller"
2
+
3
+ module EducodeSales
4
+ class UploadFilesController < ApplicationController
5
+
6
+ def index
7
+ respond_to do |format|
8
+ format.html do
9
+ end
10
+ format.json do
11
+ @files = Attachment.where(description: "business", container_id:params[:business_id]).page(params[:page]).per(params[:limit])
12
+ end
13
+ end
14
+ end
15
+
16
+ def create
17
+ upload_file = params["file"]
18
+ raise "未上传文件" unless upload_file
19
+ save_path = File.join("#{Rails.root}/public/images")
20
+ ext = file_ext(upload_file.original_filename)
21
+ local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext)
22
+ content_type = upload_file.content_type.presence || 'application/octet-stream'
23
+ disk_filename = local_path[save_path.size + 1, local_path.size]
24
+ @attachment = Attachment.where(disk_filename: disk_filename,
25
+ author_id: @current_admin.id).first
26
+ if @attachment.blank?
27
+ @attachment = Attachment.new
28
+ @attachment.filename = upload_file.original_filename
29
+ @attachment.description = "business"
30
+ @attachment.disk_filename = local_path[save_path.size + 1, local_path.size]
31
+ @attachment.filesize = upload_file.tempfile.size
32
+ @attachment.content_type = content_type
33
+ @attachment.digest = digest
34
+ @attachment.author_id = @current_admin.id
35
+ @attachment.container_id = params[:business_id]
36
+ @attachment.save!
37
+ else
38
+ logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}"
39
+ end
40
+ render_success
41
+ end
42
+
43
+ def destroy
44
+ file = Attachment.find(params[:id])
45
+ file.destroy
46
+ File.delete("#{Rails.root}/public/images/" + file.disk_filename)
47
+ render_success
48
+ end
49
+
50
+ def download
51
+ file = Attachment.find_by_id(params[:id])
52
+ raise "未找到文件" unless file
53
+ send_file("#{Rails.root}/public/images/" + file.disk_filename, filename: file.title, stream: true, type: file.content_type.presence || 'application/octet-stream')
54
+ end
55
+
56
+
57
+ def file_ext(file_name)
58
+ ext = ''
59
+ exts = file_name.split(".")
60
+ if exts.size > 1
61
+ ext = ".#{exts.last}"
62
+ end
63
+ ext
64
+ end
65
+
66
+ def file_save_to_local(save_path, temp_file, ext)
67
+ unless Dir.exists?(save_path)
68
+ FileUtils.mkdir_p(save_path) ##不成功这里会抛异常
69
+ end
70
+
71
+ digest = md5_file(temp_file)
72
+ digest = "#{digest}_#{(Time.now.to_f * 1000).to_i}"
73
+ local_file_path = File.join(save_path, digest) + ext
74
+ save_temp_file(temp_file, local_file_path)
75
+
76
+ [local_file_path, digest]
77
+ end
78
+
79
+
80
+ def md5_file(temp_file)
81
+ md5 = Digest::MD5.new
82
+ temp_file.rewind
83
+ while (buffer = temp_file.read(8192))
84
+ md5.update(buffer)
85
+ end
86
+ md5.hexdigest
87
+ end
88
+
89
+ def save_temp_file(temp_file, save_file_path)
90
+ File.open(save_file_path, 'wb') do |f|
91
+ temp_file.rewind
92
+ while (buffer = temp_file.read(8192))
93
+ f.write(buffer)
94
+ end
95
+ end
96
+ end
97
+
98
+ end
99
+ end
@@ -4,6 +4,10 @@ module EducodeSales
4
4
 
5
5
  XTYPE = "x_class"
6
6
  OTYPE = 'o_class'
7
+ ATYPE = 'a_class'
8
+ BTYPE = 'b_class'
9
+ CTYPE = 'c_class'
10
+ DTYPE = 'd_class'
7
11
 
8
12
  validates :name, uniqueness: {scope: :clazz, message: '已存在'}
9
13
 
@@ -2,6 +2,7 @@ module EducodeSales
2
2
  class SalePlan < ApplicationRecord
3
3
  belongs_to :business
4
4
  belongs_to :staff
5
+ validates :business_id, presence: true
5
6
 
6
7
  validates :month, presence: true
7
8
  end