educode_sales 0.4.8 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/educode_sales//345/233/236/346/224/266/347/253/231.png +0 -0
  3. data/app/controllers/educode_sales/businesses_controller.rb +84 -5
  4. data/app/controllers/educode_sales/follow_ups_controller.rb +4 -3
  5. data/app/controllers/educode_sales/home_controller.rb +1 -1
  6. data/app/controllers/educode_sales/operation_plans_controller.rb +34 -6
  7. data/app/controllers/educode_sales/operation_reports_controller.rb +33 -3
  8. data/app/controllers/educode_sales/operations_controller.rb +1 -1
  9. data/app/controllers/educode_sales/plans_controller.rb +43 -15
  10. data/app/controllers/educode_sales/recycles_controller.rb +95 -0
  11. data/app/controllers/educode_sales/roles_controller.rb +5 -0
  12. data/app/controllers/educode_sales/sale_reports_controller.rb +34 -4
  13. data/app/controllers/educode_sales/sale_trends_controller.rb +176 -5
  14. data/app/controllers/educode_sales/sales_controller.rb +6 -2
  15. data/app/controllers/educode_sales/staffs_controller.rb +4 -4
  16. data/app/controllers/educode_sales/upload_files_controller.rb +112 -0
  17. data/app/models/concerns/deletable.rb +8 -0
  18. data/app/models/educode_sales/application_record.rb +2 -0
  19. data/app/models/educode_sales/business.rb +15 -2
  20. data/app/models/educode_sales/common.rb +6 -1
  21. data/app/models/educode_sales/follow_up.rb +4 -2
  22. data/app/models/educode_sales/recycle.rb +5 -0
  23. data/app/models/educode_sales/sale_plan.rb +3 -0
  24. data/app/models/educode_sales/sale_report.rb +2 -0
  25. data/app/views/educode_sales/businesses/edit_follow_record.html.erb +15 -0
  26. data/app/views/educode_sales/businesses/edit_plan.html.erb +2 -2
  27. data/app/views/educode_sales/businesses/file.html.erb +155 -0
  28. data/app/views/educode_sales/businesses/index.html.erb +71 -4
  29. data/app/views/educode_sales/businesses/index.json.jbuilder +3 -1
  30. data/app/views/educode_sales/businesses/new_follow_record.html.erb +22 -1
  31. data/app/views/educode_sales/businesses/show_follow.html.erb +46 -9
  32. data/app/views/educode_sales/businesses/show_follow.json.jbuilder +3 -0
  33. data/app/views/educode_sales/businesses/show_follow_record.html.erb +80 -2
  34. data/app/views/educode_sales/businesses/time_line.html.erb +62 -0
  35. data/app/views/educode_sales/businesses/upload_file.html.erb +43 -0
  36. data/app/views/educode_sales/operation_plans/_monthly.html.erb +4 -4
  37. data/app/views/educode_sales/operation_plans/_weekly.html.erb +4 -4
  38. data/app/views/educode_sales/operation_plans/index.html.erb +6 -1
  39. data/app/views/educode_sales/operation_plans/new_month.html.erb +15 -1
  40. data/app/views/educode_sales/operation_plans/new_week.html.erb +20 -5
  41. data/app/views/educode_sales/operation_reports/audit.html.erb +23 -15
  42. data/app/views/educode_sales/operation_reports/edit.html.erb +9 -9
  43. data/app/views/educode_sales/operation_reports/show.html.erb +22 -19
  44. data/app/views/educode_sales/places/index.html.erb +6 -1
  45. data/app/views/educode_sales/places/index.json.jbuilder +11 -1
  46. data/app/views/educode_sales/plans/_monthly.html.erb +4 -4
  47. data/app/views/educode_sales/plans/_weekly.html.erb +4 -4
  48. data/app/views/educode_sales/plans/index.html.erb +6 -1
  49. data/app/views/educode_sales/plans/new_monthly.html.erb +6 -6
  50. data/app/views/educode_sales/plans/new_week.html.erb +1 -1
  51. data/app/views/educode_sales/plans/new_weekly.html.erb +7 -7
  52. data/app/views/educode_sales/recycles/_business.html.erb +122 -0
  53. data/app/views/educode_sales/recycles/_monthPlan.html.erb +123 -0
  54. data/app/views/educode_sales/recycles/_monthly.html.erb +121 -0
  55. data/app/views/educode_sales/recycles/_weekPlan.html.erb +128 -0
  56. data/app/views/educode_sales/recycles/_weekly.html.erb +122 -0
  57. data/app/views/educode_sales/recycles/business.json.jbuilder +16 -0
  58. data/app/views/educode_sales/recycles/index.html.erb +58 -0
  59. data/app/views/educode_sales/recycles/monthPlan.json.jbuilder +16 -0
  60. data/app/views/educode_sales/recycles/monthly.json.jbuilder +15 -0
  61. data/app/views/educode_sales/recycles/weekPlan.json.jbuilder +16 -0
  62. data/app/views/educode_sales/recycles/weekly.json.jbuilder +15 -0
  63. data/app/views/educode_sales/roles/index.html.erb +19 -1
  64. data/app/views/educode_sales/roles/rename.html.erb +50 -0
  65. data/app/views/educode_sales/sale_reports/audit.html.erb +24 -13
  66. data/app/views/educode_sales/sale_reports/edit.html.erb +7 -7
  67. data/app/views/educode_sales/sale_reports/show.html.erb +13 -10
  68. data/app/views/educode_sales/sale_trends/trends.html.erb +228 -8
  69. data/app/views/educode_sales/sale_trends/trends.json.jbuilder +14 -0
  70. data/app/views/educode_sales/sales/index.html.erb +72 -6
  71. data/app/views/educode_sales/sales/index.json.jbuilder +35 -1
  72. data/app/views/educode_sales/sales/operations.json.jbuilder +11 -1
  73. data/app/views/educode_sales/staffs/index.html.erb +6 -1
  74. data/app/views/educode_sales/staffs/index.json.jbuilder +11 -1
  75. data/app/views/educode_sales/teachers/add_keys.html.erb +3 -3
  76. data/app/views/educode_sales/teachers/index.html.erb +7 -2
  77. data/app/views/educode_sales/teachers/new.html.erb +1 -0
  78. data/app/views/educode_sales/upload_files/index.json.jbuilder +13 -0
  79. data/app/views/layouts/educode_sales/application.html.erb +3 -0
  80. data/config/routes.rb +30 -0
  81. data/db/migrate/20210902064109_create_educode_sales_role_permissions.rb +6 -0
  82. data/db/migrate/20211102085743_add_bidded_date_educode_sales_follow_ups.rb +6 -0
  83. data/db/migrate/20211109015617_create_educode_sales_recycles.rb +25 -0
  84. data/lib/educode_sales/version.rb +1 -1
  85. metadata +26 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09889c1d05306828a3d6dba9b149cdd6600ada4a043c545bfb6914521fdbfe43'
4
- data.tar.gz: 9ee3dfb7975c1270ea5adfd43b3cc0bee417a0cb7c544628486465037afd4166
3
+ metadata.gz: 1ae794ee6831f1fab6465eb9290de9f3155b4a32e13acafe865500e42decaff6
4
+ data.tar.gz: cb2e8ea7a97b6cd04942343417a7d427f18657dec46ddc2805d11a876a8672f1
5
5
  SHA512:
6
- metadata.gz: 6acf74a3a544e7cc6fc44809976f549fe4f0ca55cc9e96e91044daf2a0b0acddf4807deda3967cb00310c8403fab92930f5f01fb7d17125ca904746a93b30e3d
7
- data.tar.gz: 480ec2fc713a76af3cf6207805ee11c805cdeeaa50daefae6b148c70b976140b0ab01ba29aa4bc263b8b6fe9a6ef077c5dae8035acbbc219c5a32c2449cee336
6
+ metadata.gz: 72e214c3bca3382997cc389f36eb92747a96323ef141f255154aff068b20c9e5488fe24de4a028bbcb67a6d4c8d457713d078c6c5a70d8be08c311e3402363f4
7
+ data.tar.gz: f570a34ca2014691e28f95c758a204a82f3953118deccc89b22650476fc32ca7f5cf7a003758023796f2deccb980fbb609cfd0f99a141cafd027c06f8293ef18
@@ -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
+ 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
  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,45 @@ module EducodeSales
40
66
  end
41
67
  end
42
68
 
69
+ if params[:q].present? && params[:q][:name].present?
70
+ @year = params[:q][:name].split("-")[1].present? ? params[:q][:name].split("-")[1] : ''
71
+ end
72
+
73
+ if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-现有商机)"
74
+ a_id = Common.find_by(extras: EducodeSales::Common::ATYPE)&.id
75
+ b_id = Common.find_by(extras: EducodeSales::Common::BTYPE)&.id
76
+ c_id = Common.find_by(extras: EducodeSales::Common::CTYPE)&.id
77
+ d_id = Common.find_by(extras: EducodeSales::Common::DTYPE)&.id
78
+ ids = [a_id ,b_id ,c_id ,d_id]
79
+ @businesses = @businesses.joins("
80
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
81
+ ").where("educode_sales_follow_ups.clazz_id in (?)",ids)
82
+ end
83
+
84
+ if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-" + @year + "-已中标商机)"
85
+ stage_ids = Common.where(clazz: '商机阶段', name: ['已中标','已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
86
+ @businesses = @businesses.joins("
87
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
88
+ ").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)
89
+ end
90
+
91
+ if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-" + @year + "-已签单商机)"
92
+ s_stage_ids = Common.where(clazz: '商机阶段', name: ['已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
93
+ @businesses = @businesses.joins("
94
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
95
+ ").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)
96
+ end
97
+
98
+ if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-" + @year + "-已回款商机)"
99
+ x_id = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
100
+ # @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("
101
+ # JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
102
+ # ").where.not("educode_sales_follow_ups.clazz_id = ?",x_id)
103
+ year_time = "#{@year}-01-01 00:00:00"
104
+ year_over_time = "#{@year}-12-31 23:59:59"
105
+ @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
106
+ end
107
+
43
108
  if params[:q].present? && params[:q][:all].present?
44
109
  @businesses = @businesses
45
110
  end
@@ -51,7 +116,7 @@ module EducodeSales
51
116
  end
52
117
 
53
118
  @businesses = @businesses
54
- if params[:q].present? && params[:q][:name].present?
119
+ if params[:q].present? && params[:q][:name].present? && params[:q][:name] != "(销售态势-" + @year + "-已中标商机)" && params[:q][:name] != "(销售态势-" + @year + "-已签单商机)" && params[:q][:name] != "(销售态势-" + @year + "-已回款商机)" && params[:q][:name] != "(销售态势-现有商机)"
55
120
  @businesses = @businesses.where("educode_sales_businesses.name like ?", "%#{params[:q][:name]}%")
56
121
  end
57
122
  if params[:q].present? && params[:q][:department].present?
@@ -59,10 +124,10 @@ module EducodeSales
59
124
  @businesses = @businesses.joins(:department).where("departments.id in (?)", departments_ids)
60
125
  end
61
126
  if params[:q].present? && params[:q][:staff_id].present?
62
- part_a_ids = @businesses.where("educode_sales_businesses.last_follow_up_id is null AND staff_id = ?",params[:q][:staff_id]).ids
127
+ part_a_ids = @businesses.where("educode_sales_businesses.last_follow_up_id is null AND educode_sales_businesses.staff_id = ?",params[:q][:staff_id]).ids
63
128
  part_b_ids = @businesses.where("educode_sales_businesses.last_follow_up_id is not null").joins("
64
129
  JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
65
- ").where("educode_sales_follow_ups.staff_id = ?", params[:q][:staff_id]).pluck(:business_id)
130
+ ").where("educode_sales_follow_ups.staff_id = ?", params[:q][:staff_id]).ids
66
131
  business_ids = part_a_ids + part_b_ids
67
132
  @businesses = EducodeSales::Business.where(id:business_ids)
68
133
  end
@@ -109,6 +174,8 @@ module EducodeSales
109
174
  educode_sales_businesses.*,
110
175
  last_follow.invitation_at,
111
176
  last_follow.reception_at,
177
+ last_follow.bidded_date,
178
+ last_follow.signed_date,
112
179
  last_follow.total_amount").joins("
113
180
  LEFT JOIN educode_sales_follow_ups AS last_follow ON educode_sales_businesses.last_follow_up_id = last_follow.id
114
181
  ").page(params[:page]).per(params[:limit])
@@ -158,7 +225,7 @@ module EducodeSales
158
225
 
159
226
  def destroy
160
227
  business = Business.find(params[:id])
161
- business.destroy
228
+ business.soft_destroy(@current_admin.id)
162
229
  render_success
163
230
  rescue ActiveRecord::DeleteRestrictionError => e
164
231
  render_failure '该商机已其它关联数据产生,暂不能删除'
@@ -213,7 +280,16 @@ module EducodeSales
213
280
  end
214
281
 
215
282
  def show_follow_record
216
- @follow_up = FollowUp.find(params[:follow_up_id])
283
+ follow_up_id = params[:follow_up_id]
284
+ @follow_up = FollowUp.find(follow_up_id)
285
+ id = @follow_up.id
286
+ @follow_ups = Business.find(@follow_up.business_id).follow_ups
287
+ ids = @follow_ups.ids
288
+ size = ids.size
289
+ ids = ids.reverse
290
+ index = ids.index(id)
291
+ @next_id = (index != size - 1 && size > 1) ? ids[index + 1] : 0
292
+ @pre_id = (index != 0 && size > 1) ? ids[index - 1] : 0
217
293
  render layout: false
218
294
  end
219
295
 
@@ -243,5 +319,8 @@ module EducodeSales
243
319
  params.permit(:clazz_id, :stage_id, :invitation_at, :reception_at, :total_amount, :actual_amount, :divide_amount, :description, :advise, :place_id)
244
320
  end
245
321
 
322
+ def edu_setting name
323
+ EduSetting.get(name)
324
+ end
246
325
  end
247
326
  end
@@ -36,7 +36,7 @@ module EducodeSales
36
36
  def destroy
37
37
  follow_up = FollowUp.find(params[:id])
38
38
  business = follow_up.business
39
- if follow_up.destroy
39
+ if follow_up.soft_destroy(@current_admin.id)
40
40
  if follow_up.id == business.last_follow_up_id
41
41
  business.update(last_follow_up: business.follow_ups.last, return_money: MoneyPlan.where(clazz: '已完成', follow_up_id: business.follow_ups.last&.id).sum(:amount))
42
42
  end
@@ -132,7 +132,8 @@ module EducodeSales
132
132
  )
133
133
  teacher.save
134
134
  key_peprson = KeyPerson.new(teacher_params)
135
- key_peprson.teacher = teacher
135
+ teacher_id = EducodeSales::Teacher.find_by(name: user.real_name, department_id: user.department_id).id
136
+ key_peprson.teacher_id = teacher_id
136
137
  end
137
138
 
138
139
  follow_up.key_person << key_peprson
@@ -156,7 +157,7 @@ module EducodeSales
156
157
  end
157
158
 
158
159
  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)
160
+ 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
161
  end
161
162
 
162
163
  def teacher_params
@@ -34,7 +34,7 @@ module EducodeSales
34
34
  end
35
35
 
36
36
  def search_operation_teacher
37
- @data = Teacher.where("name like ? and is_key = false", "%#{params[:q]}%").limit(20)
37
+ @data = @current_admin.teachers.where("name like ? and is_key = false", "%#{params[:q]}%").limit(20)
38
38
  end
39
39
 
40
40
  def search_edu_teacher
@@ -52,13 +52,14 @@ module EducodeSales
52
52
  end
53
53
  def new_week
54
54
  @teacher = Teacher.find_by(id: params[:teacher_id])
55
+ @week = Time.now.strftime('%W').to_i
55
56
  week = Time.now.strftime('%W').to_i
56
57
  if week > 3
57
- @weeks = [week, week - 1, week - 2]
58
+ @weeks = [[week+2,week+2], [week+1,week+1], [week.to_s + ' 本周',week], [week - 1,week - 1], [week - 2,week - 2]]
58
59
  elsif week == 2
59
- @weeks = [week, week - 1]
60
+ @weeks = [[week.to_s + ' 本周',week], [week - 1,week - 1]]
60
61
  else
61
- @weeks = [week]
62
+ @weeks = [[week.to_s + ' 本周',week]]
62
63
  end
63
64
  @teachers = @current_admin.teachers.where(is_key: 0).pluck(:name, :id)
64
65
  render layout: false
@@ -77,7 +78,17 @@ module EducodeSales
77
78
  end
78
79
 
79
80
  def new_weekly
80
- @area =@current_admin.areas.present? ? @current_admin.areas.pluck(:name).join("、") : ''
81
+ d = @current_admin
82
+ area_ids = EducodeSales::Common.where(clazz: 'area').ids.sort.to_s
83
+ if d.areas.present?
84
+ if d.areas.ids.sort.to_s == area_ids
85
+ @area = '全国'
86
+ else
87
+ @area = d.areas.pluck(:name).join("、")
88
+ end
89
+ else
90
+ @area = ''
91
+ end
81
92
  @name = @current_admin.user.real_name
82
93
  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)
83
94
  @rate = sale_plans.present? ? (sale_plans.sum("finish_rate") / sale_plans.size) : 0
@@ -94,7 +105,17 @@ module EducodeSales
94
105
  end
95
106
 
96
107
  def new_monthly
97
- @area =@current_admin.areas.present? ? @current_admin.areas.pluck(:name).join("、") : ''
108
+ d = @current_admin
109
+ area_ids = EducodeSales::Common.where(clazz: 'area').ids.sort.to_s
110
+ if d.areas.present?
111
+ if d.areas.ids.sort.to_s == area_ids
112
+ @area = '全国'
113
+ else
114
+ @area = d.areas.pluck(:name).join("、")
115
+ end
116
+ else
117
+ @area = ''
118
+ end
98
119
  @name = @current_admin.user.real_name
99
120
  sale_plans = OperationPlan.where(month: Time.now.strftime("%Y-%m") + "-01 00:00:00", staff_id: @current_admin.id, weekly: nil)
100
121
  @rate = sale_plans.present? ? (sale_plans.sum("finish_rate") / sale_plans.size) : 0
@@ -135,7 +156,7 @@ module EducodeSales
135
156
  if @sale_plan.weekly.present?
136
157
  week = Time.now.strftime('%W').to_i
137
158
  if week > 3
138
- @weeks = [week, week - 1, week - 2]
159
+ @weeks = [week+2, week+1, week, week - 1, week - 2]
139
160
  elsif week == 2
140
161
  @weeks = [week, week - 1]
141
162
  else
@@ -143,6 +164,13 @@ module EducodeSales
143
164
  end
144
165
  @weeks << @sale_plan.weekly
145
166
  @weeks = @weeks.uniq.sort
167
+ @weeks = @weeks.map do |d|
168
+ if d == week
169
+ ["#{d} 本周", d]
170
+ else
171
+ [d, d]
172
+ end
173
+ end
146
174
  end
147
175
  @months = [Time.now.strftime("%Y-%m"), Time.now.months_ago(1).strftime("%Y-%m")]
148
176
  @months << @sale_plan.month.strftime("%Y-%m")
@@ -68,7 +68,17 @@ module EducodeSales
68
68
  def show
69
69
  @sale_report = OperationReport.find(params[:id])
70
70
  @name = @sale_report.staff.user.real_name
71
- @area = @sale_report.staff.areas.present? ? @sale_report.staff.areas.pluck(:name).join("、") : ''
71
+ d = @sale_report.staff
72
+ area_ids = EducodeSales::Common.where(clazz: 'area').ids.sort.to_s
73
+ if d.areas.present?
74
+ if d.areas.ids.sort.to_s == area_ids
75
+ @area = '全国'
76
+ else
77
+ @area = d.areas.pluck(:name).join("、")
78
+ end
79
+ else
80
+ @area = ''
81
+ end
72
82
  render layout: false
73
83
  end
74
84
 
@@ -81,7 +91,17 @@ module EducodeSales
81
91
  def edit
82
92
  @sale_report = OperationReport.find(params[:id])
83
93
  @name = @sale_report.staff.user.real_name
84
- @area = @sale_report.staff.areas.present? ? @sale_report.staff.areas.pluck(:name).join("、") : ''
94
+ d = @sale_report.staff
95
+ area_ids = EducodeSales::Common.where(clazz: 'area').ids.sort.to_s
96
+ if d.areas.present?
97
+ if d.areas.ids.sort.to_s == area_ids
98
+ @area = '全国'
99
+ else
100
+ @area = d.areas.pluck(:name).join("、")
101
+ end
102
+ else
103
+ @area = ''
104
+ end
85
105
  render layout: false
86
106
  end
87
107
 
@@ -118,7 +138,17 @@ module EducodeSales
118
138
  def audit
119
139
  @sale_report = OperationReport.find(params[:id])
120
140
  @name = @sale_report.staff.user.real_name
121
- @area = @sale_report.staff.areas.present? ? @sale_report.staff.areas.pluck(:name).join("、") : ''
141
+ d = @sale_report.staff
142
+ area_ids = EducodeSales::Common.where(clazz: 'area').ids.sort.to_s
143
+ if d.areas.present?
144
+ if d.areas.ids.sort.to_s == area_ids
145
+ @area = '全国'
146
+ else
147
+ @area = d.areas.pluck(:name).join("、")
148
+ end
149
+ else
150
+ @area = ''
151
+ end
122
152
  render layout: false
123
153
  end
124
154
 
@@ -4,7 +4,7 @@ module EducodeSales
4
4
  class OperationsController < ApplicationController
5
5
 
6
6
  def trends
7
- @years = (1..(Time.now.year - 2014)).map { |d| 2014 + 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
@@ -70,22 +70,33 @@ module EducodeSales
70
70
 
71
71
  def new_week
72
72
  @business = Business.find_by(id: params[:business_id])
73
+ @week = Time.now.strftime('%W').to_i
73
74
  week = Time.now.strftime('%W').to_i
74
75
  if week > 3
75
- @weeks = [week, week - 1, week - 2]
76
+ @weeks = [[week+2,week+2], [week+1,week+1], [week.to_s + ' 本周',week], [week - 1,week - 1], [week - 2,week - 2]]
76
77
  elsif week == 2
77
- @weeks = [week, week - 1]
78
+ @weeks = [[week.to_s + ' 本周',week], [week - 1,week - 1]]
78
79
  else
79
- @weeks = [week]
80
+ @weeks = [[week.to_s + ' 本周',week]]
80
81
  end
81
82
  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)
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] }
83
+ @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)
84
+ @businesses = @businesses.map { |b| [b.name + "(" + b.department.school.name + ")" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : b.created_at.to_s), b.id] }
84
85
  render layout: false
85
86
  end
86
87
 
87
88
  def new_weekly
88
- @area =@current_admin.areas.present? ? @current_admin.areas.pluck(:name).join("、") : ''
89
+ d = @current_admin
90
+ area_ids = EducodeSales::Common.where(clazz: 'area').ids.sort.to_s
91
+ if d.areas.present?
92
+ if d.areas.ids.sort.to_s == area_ids
93
+ @area = '全国'
94
+ else
95
+ @area = d.areas.pluck(:name).join("、")
96
+ end
97
+ else
98
+ @area = ''
99
+ end
89
100
  @name = @current_admin.user.real_name
90
101
  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)
91
102
  @rate = sale_plans.present? ? (sale_plans.sum("finish_rate") / sale_plans.size) : 0
@@ -97,13 +108,23 @@ module EducodeSales
97
108
  def new_month
98
109
  @business = Business.find_by(id: params[:business_id])
99
110
  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)
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] }
111
+ @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)
112
+ @businesses = @businesses.map { |b| [b.name + "(" + b.department.school.name + ")" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : b.created_at.to_s), b.id] }
102
113
  render layout: false
103
114
  end
104
115
 
105
116
  def new_monthly
106
- @area =@current_admin.areas.present? ? @current_admin.areas.pluck(:name).join("、") : ''
117
+ d = @current_admin
118
+ area_ids = EducodeSales::Common.where(clazz: 'area').ids.sort.to_s
119
+ if d.areas.present?
120
+ if d.areas.ids.sort.to_s == area_ids
121
+ @area = '全国'
122
+ else
123
+ @area = d.areas.pluck(:name).join("、")
124
+ end
125
+ else
126
+ @area = ''
127
+ end
107
128
  @name = @current_admin.user.real_name
108
129
  sale_plans = SalePlan.where(month: Time.now.strftime("%Y-%m") + "-01 00:00:00", staff_id: @current_admin.id, weekly: nil)
109
130
  @rate = sale_plans.present? ? (sale_plans.sum("finish_rate") / sale_plans.size) : 0
@@ -132,13 +153,13 @@ module EducodeSales
132
153
 
133
154
  def edit_week
134
155
  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)
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] }
156
+ @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)
157
+ @businesses = @businesses.map { |b| [b.name + "(" + b.department.school.name + ")" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : b.created_at.to_s), b.id] }
137
158
  @sale_plan = SalePlan.find(params[:id])
138
159
  if @sale_plan.weekly.present?
139
160
  week = Time.now.strftime('%W').to_i
140
161
  if week > 3
141
- @weeks = [week, week - 1, week - 2]
162
+ @weeks = [week+2, week+1, week, week - 1, week - 2]
142
163
  elsif week == 2
143
164
  @weeks = [week, week - 1]
144
165
  else
@@ -146,6 +167,13 @@ module EducodeSales
146
167
  end
147
168
  @weeks << @sale_plan.weekly
148
169
  @weeks = @weeks.uniq.sort
170
+ @weeks = @weeks.map do |d|
171
+ if d == week
172
+ ["#{d} 本周", d]
173
+ else
174
+ [d, d]
175
+ end
176
+ end
149
177
  end
150
178
  @months = [Time.now.strftime("%Y-%m"), Time.now.months_ago(1).strftime("%Y-%m")]
151
179
  @months << @sale_plan.month.strftime("%Y-%m")
@@ -167,7 +195,7 @@ module EducodeSales
167
195
 
168
196
  def destroy
169
197
  sale_plan = SalePlan.find(params[:id])
170
- if sale_plan.destroy
198
+ if sale_plan.soft_destroy(@current_admin.id)
171
199
  render_success
172
200
  else
173
201
  render_failure sale_plan
@@ -180,8 +208,8 @@ module EducodeSales
180
208
 
181
209
  def edit_month
182
210
  business_ids = EducodeSales::AssignFollowUp.joins(:follow_up).where(staff_id: @current_admin.id).pluck :business_id
183
- @businesses = Business.includes(:department, :last_follow_up).where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", business_ids, @current_admin.id)
184
- @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] }
211
+ @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)
212
+ @businesses = @businesses.map { |b| [b.name + "(" + b.department.school.name + ")" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : b.created_at.to_s), b.id] }
185
213
  @sale_plan = SalePlan.find(params[:id])
186
214
  @finish_rates = []
187
215
  11.times { |d| @finish_rates << ["#{d*10}%", d * 10]}
@@ -0,0 +1,95 @@
1
+ require_dependency "educode_sales/application_controller"
2
+
3
+ module EducodeSales
4
+ class RecyclesController < ApplicationController
5
+
6
+ def destroy
7
+ @recycle = Recycle.find(params[:id])
8
+ @recycle.destroy
9
+ render_success
10
+ end
11
+
12
+
13
+
14
+ def restore_reports
15
+ @recycle = Recycle.find(params[:id])
16
+ report_id = @recycle.source_id
17
+ EducodeSales::SaleReport.unscoped.find(report_id).update(deleted_at: nil)
18
+ @recycle.destroy
19
+ render_success
20
+ end
21
+
22
+ def restore_plans
23
+ @recycle = Recycle.find(params[:id])
24
+ plan = EducodeSales::SalePlan.unscoped.find(@recycle.source_id)
25
+ business = EducodeSales::Business.unscoped.find(plan.business_id)
26
+ Recycle.find_by(source_id: business.id).destroy if Recycle.find_by(source_id: business.id).present?
27
+ business.update(deleted_at: nil)
28
+ follow_ups = EducodeSales::FollowUp.unscoped.where(business_id: business.id)
29
+ follow_ups.update_all(deleted_at: nil)
30
+ plan.update(deleted_at: nil)
31
+ @recycle.destroy
32
+ render_success
33
+ end
34
+
35
+ def restore_businesses
36
+ @recycle = Recycle.find(params[:id])
37
+ business_id = @recycle.source_id
38
+ EducodeSales::Business.unscoped.find(business_id).update(deleted_at: nil)
39
+ follow_ups = EducodeSales::FollowUp.unscoped.where(business_id: business_id)
40
+ follow_ups.update_all(deleted_at: nil)
41
+ @recycle.destroy
42
+ render_success
43
+ end
44
+
45
+ def business
46
+ @businesses = Recycle.where(source_type:"EducodeSales::Business")
47
+ if params[:sort].present? && params[:sort][:field]
48
+ @businesses = @businesses.order("created_at #{params[:sort][:order]}")
49
+ else
50
+ @businesses = @businesses.order("educode_sales_recycles.created_at desc")
51
+ end
52
+ @businesses = @businesses.page(params[:page]).per(params[:limit])
53
+ end
54
+
55
+ def weekly
56
+ @weekly = Recycle.where(source_type:"EducodeSales::SaleReport").order(created_at: :desc).page(params[:page]).per(params[:limit])
57
+ if params[:sort].present? && params[:sort][:field]
58
+ @weekly = @weekly.order("created_at #{params[:sort][:order]}")
59
+ else
60
+ @weekly = @weekly.order("educode_sales_recycles.created_at desc")
61
+ end
62
+ @weekly = @weekly.page(params[:page]).per(params[:limit])
63
+ end
64
+
65
+ def monthly
66
+ @monthly = Recycle.where(source_type:"EducodeSales::SaleReport")
67
+ if params[:sort].present? && params[:sort][:field]
68
+ @monthly = @monthly.order("created_at #{params[:sort][:order]}")
69
+ else
70
+ @monthly = @monthly.order("educode_sales_recycles.created_at desc")
71
+ end
72
+ @monthly = @monthly.page(params[:page]).per(params[:limit])
73
+ end
74
+
75
+ def weekPlan
76
+ @weekPlans = Recycle.where(source_type:"EducodeSales::SalePlan")
77
+ if params[:sort].present? && params[:sort][:field]
78
+ @weekPlans = @weekPlans.order("created_at #{params[:sort][:order]}")
79
+ else
80
+ @weekPlans = @weekPlans.order("educode_sales_recycles.created_at desc")
81
+ end
82
+ @weekPlans = @weekPlans.page(params[:page]).per(params[:limit])
83
+ end
84
+
85
+ def monthPlan
86
+ @monthPlans = Recycle.where(source_type:"EducodeSales::SalePlan")
87
+ if params[:sort].present? && params[:sort][:field]
88
+ @monthPlans = @monthPlans.order("created_at #{params[:sort][:order]}")
89
+ else
90
+ @monthPlans = @monthPlans.order("educode_sales_recycles.created_at desc")
91
+ end
92
+ @monthPlans = @monthPlans.page(params[:page]).per(params[:limit])
93
+ end
94
+ end
95
+ end
@@ -35,6 +35,11 @@ module EducodeSales
35
35
  render layout: false
36
36
  end
37
37
 
38
+ def rename
39
+ @name = Role.find(params[:id]).name
40
+ render layout: false
41
+ end
42
+
38
43
  def update_role
39
44
  role = Role.find(params[:id])
40
45
  if role.update(name: params[:name])
@@ -24,13 +24,23 @@ module EducodeSales
24
24
  def show
25
25
  @sale_report = SaleReport.find(params[:id])
26
26
  @name = @sale_report.staff.user.real_name
27
- @area = @sale_report.staff.areas.present? ? @sale_report.staff.areas.pluck(:name).join("、") : ''
27
+ d = @sale_report.staff
28
+ area_ids = EducodeSales::Common.where(clazz: 'area').ids.sort.to_s
29
+ if d.areas.present?
30
+ if d.areas.ids.sort.to_s == area_ids
31
+ @area = '全国'
32
+ else
33
+ @area = d.areas.pluck(:name).join("、")
34
+ end
35
+ else
36
+ @area = ''
37
+ end
28
38
  render layout: false
29
39
  end
30
40
 
31
41
  def destroy
32
42
  sale_report = SaleReport.find(params[:id])
33
- if sale_report.destroy
43
+ if sale_report.soft_destroy(@current_admin.id)
34
44
  render_success
35
45
  else
36
46
  render_failure sale_report
@@ -86,7 +96,17 @@ module EducodeSales
86
96
  def edit
87
97
  @sale_report = SaleReport.find(params[:id])
88
98
  @name = @sale_report.staff.user.real_name
89
- @area = @sale_report.staff.areas.present? ? @sale_report.staff.areas.pluck(:name).join("、") : ''
99
+ d = @sale_report.staff
100
+ area_ids = EducodeSales::Common.where(clazz: 'area').ids.sort.to_s
101
+ if d.areas.present?
102
+ if d.areas.ids.sort.to_s == area_ids
103
+ @area = '全国'
104
+ else
105
+ @area = d.areas.pluck(:name).join("、")
106
+ end
107
+ else
108
+ @area = ''
109
+ end
90
110
  render layout: false
91
111
  end
92
112
 
@@ -123,7 +143,17 @@ module EducodeSales
123
143
  def audit
124
144
  @sale_report = SaleReport.find(params[:id])
125
145
  @name = @sale_report.staff.user.real_name
126
- @area = @sale_report.staff.areas.present? ? @sale_report.staff.areas.pluck(:name).join("、") : ''
146
+ d = @sale_report.staff
147
+ area_ids = EducodeSales::Common.where(clazz: 'area').ids.sort.to_s
148
+ if d.areas.present?
149
+ if d.areas.ids.sort.to_s == area_ids
150
+ @area = '全国'
151
+ else
152
+ @area = d.areas.pluck(:name).join("、")
153
+ end
154
+ else
155
+ @area = ''
156
+ end
127
157
  render layout: false
128
158
  end
129
159