educode_sales 0.7.9 → 0.8.3

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 (25) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/educode_sales/application_controller.rb +14 -0
  3. data/app/controllers/educode_sales/assessments_controller.rb +58 -55
  4. data/app/controllers/educode_sales/businesses_controller.rb +16 -1
  5. data/app/controllers/educode_sales/follow_ups_controller.rb +1 -1
  6. data/app/controllers/educode_sales/money_plans_controller.rb +0 -2
  7. data/app/models/educode_sales/filter.rb +12 -0
  8. data/app/models/educode_sales/follow_up.rb +7 -0
  9. data/app/views/educode_sales/assessments/_setup.html.erb +183 -132
  10. data/app/views/educode_sales/assessments/new.html.erb +1 -1
  11. data/app/views/educode_sales/businesses/edit_follow_record.html.erb +9 -0
  12. data/app/views/educode_sales/businesses/index.html.erb +220 -161
  13. data/app/views/educode_sales/businesses/index.json.jbuilder +8 -0
  14. data/app/views/educode_sales/businesses/new_follow_record.html.erb +13 -3
  15. data/app/views/educode_sales/businesses/show_follow.html.erb +6 -3
  16. data/app/views/educode_sales/businesses/show_follow.json.jbuilder +7 -0
  17. data/app/views/educode_sales/businesses/show_follow_record.html.erb +15 -5
  18. data/app/views/educode_sales/money_plans/index.json.jbuilder +1 -1
  19. data/config/routes.rb +1 -0
  20. data/db/migrate/20220507020149_create_filter.rb +10 -0
  21. data/db/migrate/20220507091959_change_educode_sales_filter_column_length.rb +5 -0
  22. data/db/migrate/20220509073936_update_educode_sales_filters_filter_data.rb +9 -0
  23. data/db/migrate/20220512031715_add_column_o_business_deployment_to_follow_ups.rb +5 -0
  24. data/lib/educode_sales/version.rb +1 -1
  25. metadata +7 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9403e25df2848c96f744c79481e62ea3ebe44c6da7d265bd1e107885c13b108
4
- data.tar.gz: 994b9567c3b88d6a804b43484447932725dcfe5d3c0f1e6113233c309a1f1f62
3
+ metadata.gz: c2693da2ea5d023a9703a21550dceaf68b5795f052201e6ccce8b16d506e0079
4
+ data.tar.gz: da956ba153a3b5d72841e40d578766b389b1d296ac0d81efbdb279adaba1e131
5
5
  SHA512:
6
- metadata.gz: 202b2c2d096f7b8d949658605ed1eb1d9b288a2764ee8144e83efb60b7c718720471f3acec0f5a818302798550eef40c53b1642421465bb3370dec1160272fee
7
- data.tar.gz: d5cd014d540019070da9da22c4b7439c4a71b242d6841d34494fdff9af0b049e9d14e22200af16b8c5a32f06bdd6ba9c18bb7b1c21a8c8a78c94f7ec446f7d7f
6
+ metadata.gz: a20abc2ed0a9a0dd161d33e3ae9d41507721a5940c5db87bba4570ad1ec573bd602fdd654398b870140ca8f432b7b3391b8b2ca234d7379de6397026f4761d6b
7
+ data.tar.gz: 5254ba05ec825566dbcedef4d4d5208c137b1aba10bb7505355cb815ff4c1f926bfa5e54e3f13406def8bdf90a525d032f2cc52f8c7651906c99d1b41244079e
@@ -27,6 +27,20 @@ module EducodeSales
27
27
  end
28
28
  end
29
29
 
30
+ def filter
31
+ params[:check] = params[:check] == "true" ? 0:1
32
+ begin
33
+ filter = Filter.find_or_create_by!(staff_id: @current_admin.id, clazz: params[:type])
34
+ filter.extras["#{params[:name]}"] = params[:check]
35
+ filter.save!
36
+ render json: {success: true ,hidden: params[:check]}
37
+ rescue => e
38
+ render_failure("操作失败")
39
+ end
40
+ end
41
+
42
+
43
+
30
44
  rescue_from CanCan::AccessDenied do |exception|
31
45
  redirect_to no_permission_path
32
46
  end
@@ -15,11 +15,19 @@ module EducodeSales
15
15
  gon.export_menus << { title: '导出到Csv文件', event: 'export_csv' }
16
16
  gon.export_menus << { title: '导出到Excel文件', event: 'export_excel' }
17
17
  # index页面new弹出层下使用
18
- gon.demo = Staff.joins(:user).where(job_type: common.id).map do |d|
18
+ gon.staff_ids = Staff.joins(:user).where(job_type: common.id).map do |d|
19
19
  {value: d.id, name: d.user.real_name }
20
20
  end
21
+ filter = Filter.find_or_create_by(staff_id: @current_admin.id, clazz: "assessments_setup")
22
+ if filter.extras.present?
23
+ gon.filter = filter.extras
24
+ else
25
+ gon.filter = {}
26
+ end
21
27
  end
22
28
  format.json do
29
+ @year2 = params[:q]&[:assessment_year] || '2022'
30
+ p @year2
23
31
  @year = params[:q].present? && params[:q][:assessment_year].present? ? params[:q][:assessment_year]:'2022'
24
32
  @assessments_id = params[:q].present? && params[:q][:assessment_id].present? ? params[:q][:assessment_id]: '1'
25
33
  @assessments = AssessmentsSetting.where("assessment_year >= ? and assessment_year <= ?", "#{@year}-01-01 00:00:00".to_date, "#{@year}-12-31 23:59:00".to_date)
@@ -34,14 +42,16 @@ module EducodeSales
34
42
  # 新增
35
43
  def create
36
44
  begin
37
- demo = AssessmentsSetting.new(params_create)
38
- demo.user_id = current_user.user_id
39
- demo.assessment_year = "#{params[:assessment_year]}-01-01"
45
+ assessment = AssessmentsSetting.new(params_create)
46
+ assessment.user_id = current_user.user_id
47
+ assessment.assessment_year = "#{params[:assessment_year]}-01-01"
48
+ AssessmentsSetting.transaction do
40
49
  params[:staffs_ids].split(",").each do |d|
41
- staff = demo.dup
50
+ staff = assessment.dup
42
51
  staff.staff_id = d.to_i
43
52
  staff.save
44
53
  end
54
+ end
45
55
  render_success
46
56
  rescue => e
47
57
  render_failure '增加数据错误'
@@ -83,8 +93,8 @@ module EducodeSales
83
93
  assessment = AssessmentsSetting.find(params[:id])
84
94
  assessment.destroy
85
95
  render_success
86
- rescue ActiveRecord::DeleteRestrictionError => e
87
- render_failure '渠道下已有关联数据产生,暂不能删除'
96
+ rescue => e
97
+ render_failure '暂不能删除'
88
98
  end
89
99
  end
90
100
 
@@ -109,14 +119,13 @@ module EducodeSales
109
119
  # common = Common.find_by(clazz: 'staff_type', name: '销售')
110
120
  # @staff_ids = Staff.joins(:user).where(job_type: common.id).pluck(:id)
111
121
  @assessment_id = params[:q].present? && params[:q][:assessment_id].present? ? params[:q][:assessment_id]:'1'
112
- @assessment_year = params[:q].present? && params[:q][:assessment_year].present? ? params[:q][:assessment_year] : '2022'
122
+ @assessment_year = params[:q].present? && params[:q][:assessment_year].present? ? params[:q][:assessment_year] : Time.now.year
113
123
  @assessments =AssessmentsSetting.where(assessment: @assessment_id)
114
124
  .where("assessment_year >= ? and assessment_year <= ?", "#{@assessment_year}-01-01 00:00:00".to_date, "#{@assessment_year}-12-31 23:59:00".to_date)
115
125
  .order("created_at desc")
116
126
  if @assessments.present?
117
127
  # 小优化
118
- @staff_ids = params[:q].present? && params[:q][:staff_id].present? ? [params[:q][:staff_id].to_i]:@assessments.pluck(:staff_id).uniq
119
- p @staff_ids
128
+ @staff_ids = params[:q].present? && params[:q][:staff_id].present? ? [params[:q][:staff_id].to_i]:@assessments.distinct.pluck(:staff_id)
120
129
  progress_main
121
130
  # 注意一下
122
131
  @assessments = @assessments.where(staff_id: @staff_ids)
@@ -158,14 +167,13 @@ module EducodeSales
158
167
  @staff_ids.each do |d|
159
168
  # 注意
160
169
  businesses = @businesses.where(staff_id: d)
161
- b = []
162
- a=[]
163
- FollowUp.joins("JOIN educode_sales_businesses ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id").where("educode_sales_businesses.id in (?)",businesses.pluck(:id)).each do |m|
164
- b << {value: m.actual_amount.to_i, date:m.signed_date.to_s[5..6].to_i}
170
+ data_count=[]
171
+ data_list = FollowUp.joins("JOIN educode_sales_businesses ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id")
172
+ .where("educode_sales_businesses.id in (?)",businesses.pluck(:id)).map do |m|
173
+ {value: m.actual_amount.to_i, date:m.signed_date.to_s[5..6].to_i}
165
174
  end
166
-
167
- count_data(b,a) # 统计数据
168
- update_assessments_progress(a,d) # 批量更新assessment数据 事物 出现一个commit
175
+ count_data(data_list,data_count) # 统计数据
176
+ update_assessments_progress(data_count,d) # 批量更新assessment数据 事物 一个commit
169
177
  end
170
178
  end
171
179
 
@@ -186,20 +194,19 @@ module EducodeSales
186
194
  b_ids = Business.where(school_id: school_ids).pluck(:last_follow_up_id)
187
195
  ids = a_ids + b_ids
188
196
  @money_plans = MoneyPlan.joins(:follow_up).where(follow_up_id: ids)
189
- else
197
+ else
190
198
  @money_plans = MoneyPlan.joins(:follow_up).where(follow_up_id: follow_up_ids)
191
199
  end
192
200
  end
193
- # todo 1 :实际回款 0:计划回款 where(clazz: 1 OR 实际回款 ) 先把staff写死
201
+ # todo 1 :实际回款 0:计划回款 where(clazz: 1 OR 实际回款 )
194
202
  @money_plans = @money_plans.where(clazz: 1).where.not(date_at: nil)
195
203
  @staff_ids.each do |d|
196
- b = []
197
- a = []
198
- @money_plans.where(staff_id: d).each do |m|
199
- b << {date:m.date_at.to_s[5..6].to_i, value:m.amount.to_i}
204
+ data_count = []
205
+ data_list = @money_plans.where(staff_id: d).map do |m|
206
+ {date:m.date_at.to_s[5..6].to_i, value:m.amount.to_i}
200
207
  end
201
- count_data(b,a)
202
- update_assessments_progress(a, d)
208
+ count_data(data_list,data_count)
209
+ update_assessments_progress(data_count, d)
203
210
  end
204
211
  end
205
212
 
@@ -235,20 +242,20 @@ module EducodeSales
235
242
  def customer_and_busniness_visits
236
243
  @staff_ids.each do |m|
237
244
  customers = @customers.where(id: EducodeSales::CustomerExtension.where(customer_staff_id: m).pluck(:school_id))
238
- b = []
239
- a = []
245
+ data_list = []
246
+ data_count = []
240
247
  CustomerFollow.joins(:school).where(school_id: customers.pluck(:id))
241
248
  .where("Educode_Sales_customer_follows.created_at >= ? and Educode_Sales_customer_follows.created_at <= ?","#{@assessment_year}-01-01 ","#{@assessment_year}-12-31 23:59:59" )
242
249
  .each do |d|
243
- b << {value: 1, date: d.created_at.to_s[5..6].to_i}
250
+ data_list << {value: 1, date: d.created_at.to_s[5..6].to_i}
244
251
  end
245
252
  FollowUp.joins(:business).where("Educode_Sales_businesses.id in (?)",EducodeSales::Business.where(school_id: customers.pluck(:id)).pluck(:id))
246
253
  .where("Educode_Sales_follow_ups.created_at >= ? and Educode_Sales_follow_ups.created_at <= ?","#{@assessment_year}-01-01 00:00:00", "#{@assessment_year}-12-31 23:59:59").each do |d|
247
- b << {date: d.created_at.to_s[5..6].to_i, value: 1}
254
+ data_list << {date: d.created_at.to_s[5..6].to_i, value: 1}
248
255
  end
249
- count_data(b,a)
256
+ count_data(data_list,data_count)
250
257
  assessment = @assessments.where(staff_id: m)
251
- update_assessments_progress(a, assessment)
258
+ update_assessments_progress(data_count, assessment)
252
259
  end
253
260
  end
254
261
 
@@ -262,13 +269,12 @@ module EducodeSales
262
269
  @businesses = @businesses.joins("JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id").where("educode_sales_follow_ups.clazz_id in (?) ",ids)
263
270
  @staff_ids.each do |d|
264
271
  businesses = @businesses.where(staff_id: d)
265
- b = []
266
- a = []
267
- businesses.each do |m|
268
- b << {date: m.created_at.to_s[5..6].to_i, value: 1}
272
+ data_count = []
273
+ data_list = businesses.map do |m|
274
+ {date: m.created_at.to_s[5..6].to_i, value: 1}
269
275
  end
270
- count_data(b,a)
271
- update_assessments_progress(a, d)
276
+ count_data(data_list,data_count) # 统计数据
277
+ update_assessments_progress(data_count, d) # 批量更新assessment数据 事物 一个commit
272
278
  end
273
279
  end
274
280
 
@@ -297,30 +303,27 @@ module EducodeSales
297
303
 
298
304
 
299
305
  # 更新assessments_settings表中数据
300
- def update_assessments_progress(a,staff_id)
301
- a[12] = a[0].to_i + a[1].to_i + a[2].to_i
302
- a[13] = a[3].to_i + a[4].to_i + a[5].to_i
303
- a[14] = a[6].to_i + a[7].to_i + a[8].to_i
304
- a[15] = a[9].to_i + a[10].to_i + a[11].to_i
305
- a[16] = a[12].to_i + a[13].to_i + a[14].to_i + a[15].to_i
306
+ def update_assessments_progress(data_count,staff_id)
307
+ data_count[12] = data_count[0].to_i + data_count[1].to_i + data_count[2].to_i
308
+ data_count[13] = data_count[3].to_i + data_count[4].to_i + data_count[5].to_i
309
+ data_count[14] = data_count[6].to_i + data_count[7].to_i + data_count[8].to_i
310
+ data_count[15] = data_count[9].to_i + data_count[10].to_i + data_count[11].to_i
311
+ data_count[16] = data_count[12].to_i + data_count[13].to_i + data_count[14].to_i + data_count[15].to_i
306
312
  # 开启事物 处理 批量修改数据
307
- ActiveRecord::Base.transaction do
308
- assessments = @assessments.where(staff_id: staff_id)
309
- assessments.update(annual_progress: a[16], first_quarter_progress: a[12], second_quarter_progress: a[13], third_quarter_progress: a[14], fourth_quarter_progress: a[15],
310
- january_progress: a[0], february_progress: a[1], march_progress: a[2], april_progress: a[3], may_progress: a[4], june_progress: a[5],
311
- july_progress: a[6], august_progress: a[7], september_progress: a[8], october_progress: a[9], november_progress: a[10], december_progress: a[11])
312
-
313
- end
313
+ assessments = @assessments.where(staff_id: staff_id)
314
+ assessments.update(annual_progress: data_count[16], first_quarter_progress: data_count[12], second_quarter_progress: data_count[13], third_quarter_progress: data_count[14], fourth_quarter_progress: data_count[15],
315
+ january_progress: data_count[0], february_progress: data_count[1], march_progress: data_count[2], april_progress: data_count[3], may_progress: data_count[4], june_progress: data_count[5],
316
+ july_progress: data_count[6], august_progress: data_count[7], september_progress: data_count[8], october_progress: data_count[9], november_progress: data_count[10], december_progress: data_count[11])
314
317
 
315
318
  end
316
319
 
317
320
  # 将统计到的数据转入a中
318
- def count_data(arry,a)
319
- arry.each do |d|
320
- if a[d[:date]-1].present?
321
- a[d[:date]-1] = a[d[:date]-1] + d[:value]
321
+ def count_data(data_list,data_count)
322
+ data_list.each do |d|
323
+ if data_count[d[:date]-1].present?
324
+ data_count[d[:date]-1] = data_count[d[:date]-1] + d[:value]
322
325
  else
323
- a[d[:date]-1] = d[:value]
326
+ data_count[d[:date]-1] = d[:value]
324
327
  end
325
328
  end
326
329
  end
@@ -21,9 +21,10 @@ module EducodeSales
21
21
  end
22
22
 
23
23
  gon.type = params[:clazz_id].present? ? [{ value: params[:clazz_id], name: Common.find(params[:clazz_id]).name }] : []
24
- gon.business_step = Common.where(clazz: 'business_step').map do |d|
24
+ gon.business_step = Common.where(clazz: 'business_step').order("position").map do |d|
25
25
  {value: d.id, name: d.name}
26
26
  end
27
+
27
28
  if can?(:create, EducodeSales::SalePlan)
28
29
  gon.menus << { title: '添加周计划', event: 'week' }
29
30
  gon.menus << { title: '添加月计划', event: 'month' }
@@ -45,6 +46,12 @@ module EducodeSales
45
46
  gon.export_menus << { title: '导出到Excel文件', event: 'export_excel' }
46
47
  end
47
48
  gon.export_menus << { title: '导出记录', event: 'export_records' }
49
+ filter = Filter.find_or_create_by(staff_id: @current_admin.id, clazz: "businesses_list")
50
+ if filter.extras.present?
51
+ gon.filter = filter.extras
52
+ else
53
+ gon.filter = {}
54
+ end
48
55
  end
49
56
  format.json do
50
57
  if @current_admin.is_admin?
@@ -316,6 +323,7 @@ module EducodeSales
316
323
  @o_name = EducodeSales::Common.find_by(extras: EducodeSales::Common::OTYPE)&.name
317
324
  @clazz = Common.where(clazz: 'business_type').order("position").pluck(:name, :id)
318
325
  @stages = Common.where(clazz: 'business_step').order("position").pluck(:name, :id)
326
+ @deployment_type = EducodeSales::FollowUp::BUSINESS_DEPLOYMENT
319
327
  @places = Place.order("created_at desc").pluck(:name, :id)
320
328
  @last_follow_up = @business.last_follow_up
321
329
  if @last_follow_up
@@ -342,6 +350,12 @@ module EducodeSales
342
350
  size = ids.size
343
351
  ids = ids.reverse
344
352
  index = ids.index(id)
353
+ EducodeSales::FollowUp::BUSINESS_DEPLOYMENT.each do |m|
354
+ if @follow_up.o_business_deployment == m[1]
355
+ @show_follow_recored_deployment = m[0]
356
+ break
357
+ end
358
+ end
345
359
  @next_id = (index != size - 1 && size > 1) ? ids[index + 1] : 0
346
360
  @pre_id = (index != 0 && size > 1) ? ids[index - 1] : 0
347
361
  render layout: false
@@ -350,6 +364,7 @@ module EducodeSales
350
364
  def edit_follow_record
351
365
  @years = (2015..Time.now.year).to_a.reverse
352
366
  @o_name = EducodeSales::Common.find_by(extras: EducodeSales::Common::OTYPE)&.name
367
+ @deployment_type = EducodeSales::FollowUp::BUSINESS_DEPLOYMENT
353
368
  @follow_up = FollowUp.find(params[:follow_up_id])
354
369
  @clazz = Common.where(clazz: 'business_type').order("position").pluck(:name, :id)
355
370
  @stages = Common.where(clazz: 'business_step').order("position").pluck(:name, :id)
@@ -226,7 +226,7 @@ module EducodeSales
226
226
  end
227
227
 
228
228
  def follow_up_params
229
- params.permit(:clazz_id, :stage_id, :invitation_at, :reception_at, :total_amount, :actual_amount, :divide_amount, :description, :advise, :place_id, :bidded_date, :signed_date, :year)
229
+ params.permit(:clazz_id, :stage_id, :invitation_at, :reception_at, :total_amount, :actual_amount, :divide_amount, :description, :advise, :place_id, :bidded_date, :signed_date, :year, :o_business_deployment)
230
230
  end
231
231
 
232
232
  def teacher_params
@@ -13,8 +13,6 @@ module EducodeSales
13
13
  end
14
14
  format.json do
15
15
  x_id = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
16
- p "================================================================================"
17
- p x_id
18
16
  if @current_admin.is_admin?
19
17
  @money_plans = MoneyPlan.joins(:follow_up).where("educode_sales_follow_ups.clazz_id != ?", x_id).where(follow_up_id: follow_up_ids)
20
18
  else
@@ -0,0 +1,12 @@
1
+
2
+
3
+ module EducodeSales
4
+ class Filter< ApplicationRecord
5
+ # belongs_to :educode_sales_staff, :class_name => 'EducodeSales::Staff'
6
+ belongs_to :staff
7
+
8
+ serialize :extras, Hash
9
+
10
+ end
11
+ end
12
+
@@ -1,5 +1,12 @@
1
1
  module EducodeSales
2
2
  class FollowUp < ApplicationRecord
3
+ # todo O类商机特有字段-部署类型(因此不写入common表中)
4
+ BUSINESS_DEPLOYMENT =[
5
+ ["公有云", 1],
6
+ ["私有云", 2],
7
+ ["混合云", 3]
8
+ ]
9
+
3
10
  include ::Deletable
4
11
  belongs_to :business, counter_cache: true # counter_cache(自动计算 business对应follow_up表中对应的个数)
5
12
  belongs_to :place, optional: true