educode_sales 0.4.7 → 0.5.1

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 (76) 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 +81 -5
  4. data/app/controllers/educode_sales/follow_ups_controller.rb +2 -2
  5. data/app/controllers/educode_sales/home_controller.rb +1 -1
  6. data/app/controllers/educode_sales/operation_plans_controller.rb +12 -4
  7. data/app/controllers/educode_sales/operations_controller.rb +1 -1
  8. data/app/controllers/educode_sales/plans_controller.rb +26 -18
  9. data/app/controllers/educode_sales/recycles_controller.rb +95 -0
  10. data/app/controllers/educode_sales/sale_reports_controller.rb +1 -1
  11. data/app/controllers/educode_sales/sale_trends_controller.rb +6 -6
  12. data/app/controllers/educode_sales/sales_controller.rb +2 -2
  13. data/app/controllers/educode_sales/staffs_controller.rb +4 -4
  14. data/app/controllers/educode_sales/upload_files_controller.rb +105 -0
  15. data/app/models/concerns/deletable.rb +8 -0
  16. data/app/models/educode_sales/application_record.rb +2 -0
  17. data/app/models/educode_sales/business.rb +15 -2
  18. data/app/models/educode_sales/common.rb +4 -0
  19. data/app/models/educode_sales/follow_up.rb +4 -2
  20. data/app/models/educode_sales/recycle.rb +5 -0
  21. data/app/models/educode_sales/sale_plan.rb +4 -0
  22. data/app/models/educode_sales/sale_report.rb +2 -0
  23. data/app/views/educode_sales/businesses/edit_follow_record.html.erb +15 -0
  24. data/app/views/educode_sales/businesses/edit_plan.html.erb +2 -2
  25. data/app/views/educode_sales/businesses/file.html.erb +154 -0
  26. data/app/views/educode_sales/businesses/index.html.erb +65 -3
  27. data/app/views/educode_sales/businesses/index.json.jbuilder +3 -1
  28. data/app/views/educode_sales/businesses/new_follow_record.html.erb +22 -1
  29. data/app/views/educode_sales/businesses/show_follow.html.erb +54 -12
  30. data/app/views/educode_sales/businesses/show_follow.json.jbuilder +3 -0
  31. data/app/views/educode_sales/businesses/show_follow_record.html.erb +80 -2
  32. data/app/views/educode_sales/businesses/time_line.html.erb +62 -0
  33. data/app/views/educode_sales/businesses/upload_file.html.erb +43 -0
  34. data/app/views/educode_sales/operation_plans/_monthly.html.erb +4 -4
  35. data/app/views/educode_sales/operation_plans/_weekly.html.erb +4 -4
  36. data/app/views/educode_sales/operation_plans/edit_month.html.erb +6 -6
  37. data/app/views/educode_sales/operation_plans/edit_week.html.erb +7 -7
  38. data/app/views/educode_sales/operation_plans/new_month.html.erb +17 -2
  39. data/app/views/educode_sales/operation_plans/new_week.html.erb +21 -6
  40. data/app/views/educode_sales/operation_reports/audit.html.erb +20 -14
  41. data/app/views/educode_sales/operation_reports/edit.html.erb +11 -11
  42. data/app/views/educode_sales/operation_reports/show.html.erb +20 -14
  43. data/app/views/educode_sales/plans/_monthly.html.erb +4 -4
  44. data/app/views/educode_sales/plans/_weekly.html.erb +4 -4
  45. data/app/views/educode_sales/plans/edit_month.html.erb +6 -6
  46. data/app/views/educode_sales/plans/edit_week.html.erb +7 -7
  47. data/app/views/educode_sales/plans/new_month.html.erb +1 -1
  48. data/app/views/educode_sales/plans/new_monthly.html.erb +6 -6
  49. data/app/views/educode_sales/plans/new_week.html.erb +2 -2
  50. data/app/views/educode_sales/plans/new_weekly.html.erb +7 -7
  51. data/app/views/educode_sales/recycles/_business.html.erb +122 -0
  52. data/app/views/educode_sales/recycles/_monthPlan.html.erb +123 -0
  53. data/app/views/educode_sales/recycles/_monthly.html.erb +121 -0
  54. data/app/views/educode_sales/recycles/_weekPlan.html.erb +128 -0
  55. data/app/views/educode_sales/recycles/_weekly.html.erb +122 -0
  56. data/app/views/educode_sales/recycles/business.json.jbuilder +16 -0
  57. data/app/views/educode_sales/recycles/index.html.erb +58 -0
  58. data/app/views/educode_sales/recycles/monthPlan.json.jbuilder +16 -0
  59. data/app/views/educode_sales/recycles/monthly.json.jbuilder +15 -0
  60. data/app/views/educode_sales/recycles/weekPlan.json.jbuilder +16 -0
  61. data/app/views/educode_sales/recycles/weekly.json.jbuilder +15 -0
  62. data/app/views/educode_sales/sale_reports/audit.html.erb +21 -12
  63. data/app/views/educode_sales/sale_reports/edit.html.erb +9 -9
  64. data/app/views/educode_sales/sale_reports/show.html.erb +12 -6
  65. data/app/views/educode_sales/sale_trends/trends.html.erb +6 -6
  66. data/app/views/educode_sales/teachers/add_keys.html.erb +2 -2
  67. data/app/views/educode_sales/teachers/index.html.erb +1 -1
  68. data/app/views/educode_sales/teachers/show_follow.html.erb +9 -3
  69. data/app/views/educode_sales/upload_files/index.json.jbuilder +13 -0
  70. data/app/views/layouts/educode_sales/application.html.erb +3 -0
  71. data/config/routes.rb +27 -0
  72. data/db/migrate/20210902064109_create_educode_sales_role_permissions.rb +6 -0
  73. data/db/migrate/20211102085743_add_bidded_date_educode_sales_follow_ups.rb +6 -0
  74. data/db/migrate/20211109015617_create_educode_sales_recycles.rb +25 -0
  75. data/lib/educode_sales/version.rb +1 -1
  76. metadata +24 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e609ed864a33df3f8398ab53416e7652333965a094df7965414cd93058e0965
4
- data.tar.gz: b506ac92b247f3bbdebb03ffa7e5d7e4c5bd48d0ac4e68a01919d81137cf175d
3
+ metadata.gz: 249bcf8612e073c689b8c6f696cc3590aeffb4271b6eef3ed7b95ecc2033aba5
4
+ data.tar.gz: 1efd466f3e9630b9908c94d7fe6184979ab775c75946b77987a8f07e67618b64
5
5
  SHA512:
6
- metadata.gz: 5ef7c7f3635c83459308d71cc80e89a6f1e45b38e0fec1c65d53fe469f4fb4d75a5b1c2982cd04c7cf4fc66299742275b8fe1f655f6f656f525fb40abceac5b0
7
- data.tar.gz: 943c29ffb564e3cc318c3bc55ce6daf4dd08e5986039f463abac740d6626d6e6b062300280e0b015cc4ce31114ffe913350e0ec95540cdf70add0ee000ac0bc2
6
+ metadata.gz: f189282b2df2c5bbae317f6ed513862721dc280885791fe5dfda7b2245894d511d0d303a2d5caaab304adb855de8f9d8e65f2c014f4212b34b347e3126854fd0
7
+ data.tar.gz: 6848e0f74872c5b7e53e05104a224abd58a6a4b8b374393e918ad09c20a34d83b7aa78789bc9e6c2d1091d5f06f6d057400ed0eeeaa9605637bd0abe592ffdd8
@@ -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,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
 
@@ -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
@@ -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
@@ -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
@@ -135,7 +136,7 @@ module EducodeSales
135
136
  if @sale_plan.weekly.present?
136
137
  week = Time.now.strftime('%W').to_i
137
138
  if week > 3
138
- @weeks = [week, week - 1, week - 2]
139
+ @weeks = [week+2, week+1, week, week - 1, week - 2]
139
140
  elsif week == 2
140
141
  @weeks = [week, week - 1]
141
142
  else
@@ -143,6 +144,13 @@ module EducodeSales
143
144
  end
144
145
  @weeks << @sale_plan.weekly
145
146
  @weeks = @weeks.uniq.sort
147
+ @weeks = @weeks.map do |d|
148
+ if d == week
149
+ ["#{d} 本周", d]
150
+ else
151
+ [d, d]
152
+ end
153
+ end
146
154
  end
147
155
  @months = [Time.now.strftime("%Y-%m"), Time.now.months_ago(1).strftime("%Y-%m")]
148
156
  @months << @sale_plan.month.strftime("%Y-%m")
@@ -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
@@ -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
@@ -70,18 +70,18 @@ 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
- ids = AssignFollowUp.where(staff_id: @current_admin.id).pluck(:follow_up_id)
82
- ids1 = FollowUp.where(id: ids).pluck(:business_id)
83
- @businesses =Business.includes(:department, :last_follow_up).where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", ids1, @current_admin.id)
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.id] }
82
+ business_ids = EducodeSales::AssignFollowUp.joins(:follow_up).where(staff_id: @current_admin.id).pluck :business_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] }
85
85
  render layout: false
86
86
  end
87
87
 
@@ -97,10 +97,9 @@ module EducodeSales
97
97
 
98
98
  def new_month
99
99
  @business = Business.find_by(id: params[:business_id])
100
- ids = AssignFollowUp.where(staff_id: @current_admin.id).pluck(:follow_up_id)
101
- ids1 = FollowUp.where(id: ids).pluck(:business_id)
102
- @businesses =Business.includes(:department, :last_follow_up).where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", ids1, @current_admin.id)
103
- @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
+ business_ids = EducodeSales::AssignFollowUp.joins(:follow_up).where(staff_id: @current_admin.id).pluck :business_id
101
+ @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)
102
+ @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] }
104
103
  render layout: false
105
104
  end
106
105
 
@@ -133,13 +132,14 @@ module EducodeSales
133
132
  end
134
133
 
135
134
  def edit_week
136
- @businesses = @current_admin.businesses
137
- @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] }
135
+ business_ids = EducodeSales::AssignFollowUp.joins(:follow_up).where(staff_id: @current_admin.id).pluck :business_id
136
+ @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)
137
+ @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] }
138
138
  @sale_plan = SalePlan.find(params[:id])
139
139
  if @sale_plan.weekly.present?
140
140
  week = Time.now.strftime('%W').to_i
141
141
  if week > 3
142
- @weeks = [week, week - 1, week - 2]
142
+ @weeks = [week+2, week+1, week, week - 1, week - 2]
143
143
  elsif week == 2
144
144
  @weeks = [week, week - 1]
145
145
  else
@@ -147,6 +147,13 @@ module EducodeSales
147
147
  end
148
148
  @weeks << @sale_plan.weekly
149
149
  @weeks = @weeks.uniq.sort
150
+ @weeks = @weeks.map do |d|
151
+ if d == week
152
+ ["#{d} 本周", d]
153
+ else
154
+ [d, d]
155
+ end
156
+ end
150
157
  end
151
158
  @months = [Time.now.strftime("%Y-%m"), Time.now.months_ago(1).strftime("%Y-%m")]
152
159
  @months << @sale_plan.month.strftime("%Y-%m")
@@ -168,7 +175,7 @@ module EducodeSales
168
175
 
169
176
  def destroy
170
177
  sale_plan = SalePlan.find(params[:id])
171
- if sale_plan.destroy
178
+ if sale_plan.soft_destroy(@current_admin.id)
172
179
  render_success
173
180
  else
174
181
  render_failure sale_plan
@@ -180,8 +187,9 @@ module EducodeSales
180
187
  end
181
188
 
182
189
  def edit_month
183
- @businesses = @current_admin.businesses
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] }
190
+ business_ids = EducodeSales::AssignFollowUp.joins(:follow_up).where(staff_id: @current_admin.id).pluck :business_id
191
+ @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)
192
+ @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
193
  @sale_plan = SalePlan.find(params[:id])
186
194
  @finish_rates = []
187
195
  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
@@ -30,7 +30,7 @@ module EducodeSales
30
30
 
31
31
  def destroy
32
32
  sale_report = SaleReport.find(params[:id])
33
- if sale_report.destroy
33
+ if sale_report.soft_destroy(@current_admin.id)
34
34
  render_success
35
35
  else
36
36
  render_failure sale_report
@@ -7,7 +7,7 @@ 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)).map { |d| 2014 + 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
12
  year_over_time = "#{@year}-12-31 23:59:59"
13
13
  x = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
@@ -15,13 +15,13 @@ module EducodeSales
15
15
  @sale_trend = SaleTrend.find_or_create_by(year: @year)
16
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)
17
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.created_at >= ? AND educode_sales_follow_ups.created_at <= ? AND educode_sales_follow_ups.stage_id IN (?)", year_time, year_over_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)
19
19
  s_stage_ids = Common.where(clazz: '商机阶段', name: ['已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
20
- @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.created_at <= ? AND educode_sales_follow_ups.stage_id IN (?)", year_time, year_over_time, 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_follow_ups.created_at <= ? ", year_time, year_over_time).sum(:amount).round(2)
22
- 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)
23
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: 'B类').pluck(:id)
24
+ b = Common.where(clazz: '商机类型', name: Common.find_by(extras: EducodeSales::Common::BTYPE)&.name).pluck(:id)
25
25
  @b_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id IN (?)", b).sum(:total_amount).round(2)
26
26
  end
27
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
 
@@ -8,7 +8,7 @@ module EducodeSales
8
8
  format.html do
9
9
  end
10
10
  format.json do
11
- @staffs = Staff.where(is_admin: false).page(params[:page]).per(params[:limit])
11
+ @staffs = Staff.where(is_admin: false, deleted_at: nil).page(params[:page]).per(params[:limit])
12
12
  end
13
13
  end
14
14
  end
@@ -37,10 +37,10 @@ module EducodeSales
37
37
 
38
38
  def destroy
39
39
  staff = Staff.find(params[:id])
40
- staff.destroy
40
+ staff.update(deleted_at: Time.now, expired_at: Time.now.days_ago(1))
41
41
  render_success
42
- rescue ActiveRecord::DeleteRestrictionError => e
43
- render_failure '该用户已有数据产生,暂不能删除'
42
+ # rescue ActiveRecord::DeleteRestrictionError => e
43
+ # render_failure '该用户已有数据产生,暂不能删除'
44
44
  end
45
45
 
46
46
  def disable
@@ -0,0 +1,105 @@
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])
12
+ if params[:sort].present? && params[:sort][:field]
13
+ @files = @files.order("#{params[:sort][:field]} #{params[:sort][:order]}")
14
+ else
15
+ @files = @files.order("created_on desc")
16
+ end
17
+ @files = @files.page(params[:page]).per(params[:limit])
18
+ end
19
+ end
20
+ end
21
+
22
+ def create
23
+ upload_file = params["file"]
24
+ raise "未上传文件" unless upload_file
25
+ save_path = File.join("#{Rails.root}/public/images")
26
+ ext = file_ext(upload_file.original_filename)
27
+ local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext)
28
+ content_type = upload_file.content_type.presence || 'application/octet-stream'
29
+ disk_filename = local_path[save_path.size + 1, local_path.size]
30
+ @attachment = Attachment.where(disk_filename: disk_filename,
31
+ author_id: @current_admin.id).first
32
+ if @attachment.blank?
33
+ @attachment = Attachment.new
34
+ @attachment.filename = upload_file.original_filename
35
+ @attachment.description = "business"
36
+ @attachment.disk_filename = local_path[save_path.size + 1, local_path.size]
37
+ @attachment.filesize = upload_file.tempfile.size
38
+ @attachment.content_type = content_type
39
+ @attachment.digest = digest
40
+ @attachment.author_id = @current_admin.id
41
+ @attachment.container_id = params[:business_id]
42
+ @attachment.save!
43
+ else
44
+ logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}"
45
+ end
46
+ render_success
47
+ end
48
+
49
+ def destroy
50
+ file = Attachment.find(params[:id])
51
+ file.destroy
52
+ File.delete("#{Rails.root}/public/images/" + file.disk_filename)
53
+ render_success
54
+ end
55
+
56
+ def download
57
+ file = Attachment.find_by_id(params[:id])
58
+ raise "未找到文件" unless file
59
+ send_file("#{Rails.root}/public/images/" + file.disk_filename, filename: file.title, stream: true, type: file.content_type.presence || 'application/octet-stream')
60
+ end
61
+
62
+
63
+ def file_ext(file_name)
64
+ ext = ''
65
+ exts = file_name.split(".")
66
+ if exts.size > 1
67
+ ext = ".#{exts.last}"
68
+ end
69
+ ext
70
+ end
71
+
72
+ def file_save_to_local(save_path, temp_file, ext)
73
+ unless Dir.exists?(save_path)
74
+ FileUtils.mkdir_p(save_path) ##不成功这里会抛异常
75
+ end
76
+
77
+ digest = md5_file(temp_file)
78
+ digest = "#{digest}_#{(Time.now.to_f * 1000).to_i}"
79
+ local_file_path = File.join(save_path, digest) + ext
80
+ save_temp_file(temp_file, local_file_path)
81
+
82
+ [local_file_path, digest]
83
+ end
84
+
85
+
86
+ def md5_file(temp_file)
87
+ md5 = Digest::MD5.new
88
+ temp_file.rewind
89
+ while (buffer = temp_file.read(8192))
90
+ md5.update(buffer)
91
+ end
92
+ md5.hexdigest
93
+ end
94
+
95
+ def save_temp_file(temp_file, save_file_path)
96
+ File.open(save_file_path, 'wb') do |f|
97
+ temp_file.rewind
98
+ while (buffer = temp_file.read(8192))
99
+ f.write(buffer)
100
+ end
101
+ end
102
+ end
103
+
104
+ end
105
+ end
@@ -0,0 +1,8 @@
1
+ module Deletable
2
+ extend ActiveSupport::Concern
3
+
4
+ def soft_destroy(user_id)
5
+ self.update(deleted_at: Time.now)
6
+ EducodeSales::Recycle.create(source: self, deleter_id: user_id)
7
+ end
8
+ end
@@ -1,5 +1,7 @@
1
1
  module EducodeSales
2
2
  class ApplicationRecord < ActiveRecord::Base
3
3
  self.abstract_class = true
4
+
5
+
4
6
  end
5
7
  end