educode_sales 1.10.23 → 1.10.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/educode_sales/businesses_controller.rb +13 -0
  3. data/app/controllers/educode_sales/contracts_controller.rb +55 -0
  4. data/app/controllers/educode_sales/follow_ups_controller.rb +34 -0
  5. data/app/controllers/educode_sales/idea_follows_controller.rb +146 -0
  6. data/app/controllers/educode_sales/ideas_controller.rb +37 -0
  7. data/app/controllers/educode_sales/money_plan_records_controller.rb +14 -10
  8. data/app/controllers/educode_sales/money_plans_controller.rb +5 -3
  9. data/app/controllers/educode_sales/plans_controller.rb +28 -5
  10. data/app/helpers/educode_sales/sale_trends_helper.rb +11 -1
  11. data/app/models/educode_sales/common.rb +3 -1
  12. data/app/models/educode_sales/money_plan_claim.rb +1 -1
  13. data/app/models/educode_sales/permission.rb +2 -1
  14. data/app/models/educode_sales/sale_plan.rb +2 -0
  15. data/app/views/educode_sales/businesses/index.html.erb +123 -80
  16. data/app/views/educode_sales/ideas/_follows.html.erb +3 -2
  17. data/app/views/educode_sales/ideas/_index.html.erb +37 -7
  18. data/app/views/educode_sales/ideas/edit_follow_record.html.erb +67 -49
  19. data/app/views/educode_sales/ideas/follow_list.html.erb +252 -0
  20. data/app/views/educode_sales/ideas/follow_list.json.jbuilder +16 -0
  21. data/app/views/educode_sales/ideas/follow_ups.json.jbuilder +2 -1
  22. data/app/views/educode_sales/ideas/index.json.jbuilder +1 -0
  23. data/app/views/educode_sales/ideas/new_follow_up.html.erb +2 -0
  24. data/app/views/educode_sales/ideas/show_follow.html.erb +72 -491
  25. data/app/views/educode_sales/money_plans/index.json.jbuilder +4 -4
  26. data/app/views/educode_sales/plans/_monthPlan.html.erb +5 -0
  27. data/app/views/educode_sales/plans/_weekPlan.html.erb +5 -0
  28. data/app/views/educode_sales/plans/_yearPlan.html.erb +4 -4
  29. data/app/views/educode_sales/plans/edit_month.html.erb +6 -0
  30. data/app/views/educode_sales/plans/edit_week.html.erb +6 -0
  31. data/app/views/educode_sales/plans/index.json.jbuilder +1 -0
  32. data/app/views/educode_sales/plans/new_month.html.erb +14 -0
  33. data/app/views/educode_sales/plans/new_week.html.erb +14 -0
  34. data/config/routes.rb +4 -0
  35. data/db/migrate/20230629130033_add_clazz_to_money_plans.rb +6 -0
  36. data/lib/educode_sales/version.rb +1 -1
  37. metadata +6 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ac157bfbdbc5c1aceeef3b0d0af4b81e74b6835ddda09a5beae4188f23720391
4
- data.tar.gz: a4f7c4077fc9af0f5374fc3efec8bf42e5c3a57a27dc78090a5727cabe2f5510
3
+ metadata.gz: 96a6775767542fb19b07af8d6e33230a59840d0de8cebe92fce6d415a6709b98
4
+ data.tar.gz: b67442d07ea5b753f6f617553b43685916ab979e30d6a6b5574aadd7ed3dfdcd
5
5
  SHA512:
6
- metadata.gz: 804531ab845025fe61054b79b248a5f1f83e4194d0c23cad2f0fb4c49978db71eb695815723d50e7255fa35a4aa0b0154babb156fdd5cd953808bb2a1b56a9e9
7
- data.tar.gz: 13484d3b014be703413f41b03938881aeb56bd1b7cf97f721f055f9a0aa869dfedc6b948ddbd57bb7b3174c2e3aa171dc7efa5823821f3e2b903e1e1ec9b2591
6
+ metadata.gz: 91d38ed9783a320d29546f6143ffc1e9db8583a05730b698993456b0d4038c59530d26d77b9d64519a85078166aec0fb49d29145d5c7fa60c129de4dcb40e9f1
7
+ data.tar.gz: 229ad3617584f13d20d2bdf058855519858dd856afeff9fda580bf0abb3d3041bb57613896ebd6d28ef8f7c3ccd8dbdc3d51000981ae201f2c461cf7a1aab54a
@@ -15,6 +15,7 @@ module EducodeSales
15
15
  # @more = can?(:create, EducodeSales::SalePlan) || can?(:update, EducodeSales::Business) || can?(:destroy, EducodeSales::Business) || can?(:show_file, EducodeSales::Business)
16
16
  @more = true
17
17
  gon.menus = []
18
+ gon.assign_menus = []
18
19
  gon.export_menus = []
19
20
  gon.place = params[:place_id].present? ? [{ value: params[:place_id], name: EducodeSales::Place.find(params[:place_id]).name }] : []
20
21
 
@@ -70,18 +71,30 @@ module EducodeSales
70
71
  gon.menus << { title: '添加年计划', event: 'year' }
71
72
  end
72
73
 
74
+ if can?(:assign, EducodeSales::SalePlan)
75
+ gon.assign_menus << { title: '指派周计划', event: 'week' }
76
+ gon.assign_menus << { title: '指派月计划', event: 'month' }
77
+ gon.assign_menus << { title: '指派年计划', event: 'year' }
78
+ end
79
+
73
80
  gon.menus << { title: '添加回款计划', event: 'money_plan' }
81
+ gon.assign_menus << { title: '添加回款计划', event: 'money_plan' }
74
82
 
75
83
  gon.menus << { title: '关注', event: 'following' }
76
84
  gon.menus << { title: '跟进时间线', event: 'time_line' }
85
+
86
+ gon.assign_menus << { title: '关注', event: 'following' }
87
+ gon.assign_menus << { title: '跟进时间线', event: 'time_line' }
77
88
  if can?(:show_file, EducodeSales::Business)
78
89
  gon.menus << { title: '附件管理', event: 'file' }
90
+ gon.assign_menus << { title: '附件管理', event: 'file' }
79
91
  end
80
92
  if can?(:update, EducodeSales::Business)
81
93
  # gon.menus << { title: '编辑', event: 'edit' }
82
94
  end
83
95
  if can?(:destroy, EducodeSales::Business)
84
96
  gon.menus << { title: '删除', event: 'delete' }
97
+ gon.assign_menus << { title: '删除', event: 'delete' }
85
98
  end
86
99
  if can?(:export_business, EducodeSales::Business)
87
100
  gon.export_menus << { title: '导出到Csv文件', event: 'export_csv' }
@@ -328,6 +328,17 @@ module EducodeSales
328
328
  def add_follow_ups
329
329
  @business = Business.find(params[:business_id])
330
330
  last_follow_up = @business.last_follow_up
331
+
332
+ # 计划交货时间
333
+ current_1_plan = nil
334
+ # 计划验收时间
335
+ current_2_plan = nil
336
+ # 实际交货时间
337
+ current_1_actual = nil
338
+ # 实际验收时间
339
+ current_2_actual = nil
340
+
341
+
331
342
 
332
343
  data = []
333
344
  6.times do |i|
@@ -340,9 +351,20 @@ module EducodeSales
340
351
  end
341
352
  params["#{i+1}_plan_date"].each do |d, v|
342
353
  data[i][d.to_i] << v
354
+ if i == 0 && v.present?
355
+ current_1_plan = v.to_date
356
+ elsif i == 1 && v.present?
357
+ current_2_plan = v
358
+ end
343
359
  end
344
360
  params["#{i+1}_actual_date"].each do |d, v|
345
361
  data[i][d.to_i] << v
362
+ if i == 0 && v.present?
363
+ current_1_actual = v.to_date
364
+ elsif i == 1 && v.present?
365
+ current_2_actual = v
366
+ end
367
+
346
368
  if i == 1 && last_follow_up
347
369
  # 验收时间
348
370
  last_follow_up.reception_at = v
@@ -357,6 +379,39 @@ module EducodeSales
357
379
  # data.each do |d|
358
380
  # d.select! { |d| d.delete_if{|f| f == ''}.present? }
359
381
  # end
382
+ current_week = Time.now.strftime('%W')
383
+ staff_manage_ids = @business&.last_follow_up&.assign_follow_ups.present? ? @business.last_follow_up.assign_follow_ups.pluck(:staff_id) : [@business.staff_id]
384
+ if current_1_plan && current_1_plan.to_date.strftime('%W') == current_week
385
+ unless EducodeSales::SalePlan.where(weekly: current_week, content: "提醒:请补充交付计划内容!", business: @business, staff_id: staff_manage_ids, finish_rate: 0).exists?
386
+ common_id = EducodeSales::Common.find_by(clazz: '计划类型', name: '交付计划')&.id
387
+ staff_manage_ids.each do |staff_id|
388
+ EducodeSales::SalePlan.create(month: Time.now.beginning_of_month, weekly: current_week, content: "提醒:请补充交付计划内容!", business: @business, staff_id: staff_id, finish_rate: '0', common_id: common_id )
389
+ EducodeSales::SalePlan.create(month: Time.now.beginning_of_month, content: "提醒:请补充交付计划内容!", business: @business, staff_id: staff_id, finish_rate: '0', common_id: common_id )
390
+ end
391
+ end
392
+ end
393
+
394
+ if current_2_plan && current_2_plan.to_date.strftime('%W') == current_week
395
+ unless EducodeSales::SalePlan.where(weekly: current_week, content: "提醒:请补充验收计划内容!", business: @business, staff_id: staff_manage_ids, finish_rate: 0).exists?
396
+ common_id = EducodeSales::Common.find_by(clazz: '计划类型', name: '验收计划')&.id
397
+ staff_manage_ids.each do |staff_id|
398
+ EducodeSales::SalePlan.create(month: Time.now.beginning_of_month, weekly: current_week, content: "提醒:请补充验收计划内容!", business: @business, staff_id: staff_id, finish_rate: '0', common_id: common_id )
399
+ EducodeSales::SalePlan.create(month: Time.now.beginning_of_month, content: "提醒:请补充验收计划内容!", business: @business, staff_id: staff_id, finish_rate: '0', common_id: common_id )
400
+ end
401
+ end
402
+ end
403
+
404
+ # 更新对应的计划完成度
405
+ if current_2_plan.present? && current_2_plan.to_date.strftime('%W') == current_week
406
+ common_id = EducodeSales::Common.find_by(clazz: '计划类型', name: '交付计划')&.id
407
+ EducodeSales::SalePlan.where(month: Time.now.beginning_of_month, business: @business, staff_id: staff_manage_ids, finish_rate: 0, common_id: common_id).update_all(finish_rate: 100)
408
+ end
409
+
410
+ if current_2_actual.present? && current_2_actual.to_date.strftime('%W') == current_week
411
+ common_id = EducodeSales::Common.find_by(clazz: '计划类型', name: '验收计划')&.id
412
+ EducodeSales::SalePlan.where(month: Time.now.beginning_of_month, business: @business, staff_id: staff_manage_ids, finish_rate: 0, common_id: common_id).update_all(finish_rate: 100)
413
+ end
414
+
360
415
 
361
416
  follow_up = last_follow_up.dup
362
417
 
@@ -119,6 +119,17 @@ module EducodeSales
119
119
  business_clazz_change.save unless business_clazz_change.persisted?
120
120
  end
121
121
  end
122
+
123
+ # 计划投标时间有变化且是当前周的话,添加当周/当月的销售计划
124
+ current_week = Time.now.strftime('%W').to_i
125
+ if follow_up.invitation_at&.strftime('%W').to_i == current_week
126
+ if last_follow_up && last_follow_up.invitation_at&.strftime('%W').to_i == current_week
127
+ current_week = nil
128
+ end
129
+ else
130
+ current_week = nil
131
+ end
132
+
122
133
  if follow_up.save
123
134
  if last_follow_up.present?
124
135
  last_follow_up.key_person.each do |d|
@@ -136,6 +147,29 @@ module EducodeSales
136
147
  last_follow_up.contract_date_lists.update_all(follow_up_id: follow_up.id)
137
148
  end
138
149
  @business.update(last_follow_up_id: follow_up.id, clazz_id: follow_up.clazz_id, p_deploy_time: params[:deploy_time])
150
+
151
+ if current_week.present?
152
+ staff_manage_ids = @business&.last_follow_up&.assign_follow_ups.present? ? @business.last_follow_up.assign_follow_ups.pluck(:staff_id) : [@business.staff_id]
153
+ common_id = EducodeSales::Common.find_by(clazz: '计划类型', name: '中标计划')&.id
154
+ staff_manage_ids.each do |staff_id|
155
+ EducodeSales::SalePlan.create(month: Time.now.beginning_of_month, weekly: current_week, content: "提醒:请补充中标计划内容!", business: @business, staff_id: staff_id, finish_rate: '0', common_id: common_id )
156
+ EducodeSales::SalePlan.create(month: Time.now.beginning_of_month, content: "提醒:请补充中标计划内容!", business: @business, staff_id: staff_id, finish_rate: '0', common_id: common_id )
157
+ end
158
+ end
159
+
160
+ # 更新对应的计划完成度
161
+ if follow_up.bidded_date.present?
162
+ staff_manage_ids = @business&.last_follow_up&.assign_follow_ups.present? ? @business.last_follow_up.assign_follow_ups.pluck(:staff_id) : [@business.staff_id]
163
+ common_id = EducodeSales::Common.find_by(clazz: '计划类型', name: '中标计划')&.id
164
+ if follow_up.bidded_date.strftime('%W') == Time.now.strftime('%W')
165
+ EducodeSales::SalePlan.where(month: Time.now.beginning_of_month, weekly: Time.now.strftime('%W').to_i, business: @business, staff_id: staff_manage_ids, finish_rate: 0, common_id: common_id).update_all(finish_rate: 100)
166
+ end
167
+ if follow_up.bidded_date.strftime('%Y-%m') == Time.now.strftime('%Y-%m')
168
+ EducodeSales::SalePlan.where(month: Time.now.beginning_of_month, weekly: nil, business: @business, staff_id: staff_manage_ids, finish_rate: 0, common_id: common_id).update_all(finish_rate: 100)
169
+ end
170
+ end
171
+
172
+
139
173
  # 增加o商机编号
140
174
  add_business_number
141
175
  update_department
@@ -0,0 +1,146 @@
1
+ require_dependency "educode_sales/application_controller"
2
+
3
+ module EducodeSales
4
+ class IdeaFollowsController < ApplicationController
5
+ def create
6
+ load_teacher
7
+ follow_up = @teacher.teacher_follows.build(follow_up_params)
8
+ follow_up.staff = @current_admin
9
+ if @teacher.user_id.present?
10
+ course_ids = CourseMember.joins(:course).where(user_id: @teacher.user_id, courses: { is_delete: 0 }).where.not(role: 4).pluck(:course_id)
11
+ follow_up.course_shixuns_count = CourseMember.joins(course: :practice_homework_shixuns).where(course_id: course_ids).pluck(:shixun_id).uniq.count
12
+ follow_up.shixuns_count = ShixunMember.where(user_id: @teacher.user_id).count
13
+ follow_up.students_count = CourseMember.where(course_id: course_ids, role: 4).count
14
+ follow_up.evaluates_count = Course.where(id: course_ids).inject(0) { |i, d| i += d.evaluate_count }
15
+ follow_up.courses_count = course_ids.size
16
+ end
17
+ if follow_up.save
18
+ @teacher.update(follow_up_id: follow_up.id, followup_at: Time.now)
19
+ render_success
20
+ else
21
+ render_failure follow_up
22
+ end
23
+ end
24
+
25
+ def destroy
26
+ follow_up = IdeaFollow.find(params[:id])
27
+ if follow_up.destroy
28
+ render_success
29
+ else
30
+ render_failure follow_up
31
+ end
32
+ end
33
+
34
+ def update
35
+ # follow_up = IdeaFollow.new(idea_id: idea.id, staff_id: @current_admin.id, money: params[:money], content: params[:content], status: params[:status], advise: params[:advise], sale_staff_id: params[:sale_staff_id], idea_staff_id: params[:idea_staff_id])
36
+
37
+ follow_up = IdeaFollow.find(params[:id])
38
+ follow_up.money = params[:money]
39
+ follow_up.content = params[:content]
40
+ follow_up.status = params[:status]
41
+ follow_up.advise = params[:advise]
42
+ follow_up.sale_staff_id = params[:sale_staff_id]
43
+ follow_up.idea_staff_id = params[:idea_staff_id]
44
+ if follow_up.save
45
+ render_success
46
+ else
47
+ render_failure follow_up
48
+ end
49
+ end
50
+
51
+ def index
52
+ @staff_manages = {}
53
+ role = EducodeSales::Role.find_by(name: '生态经理')
54
+ EducodeSales::Common.joins(market_areas: :staff).includes(market_areas: :staff).where(clazz: '区域').where("educode_sales_staffs.role_id = #{role.id}").each do |d|
55
+ @staff_manages[d.name] = d.market_areas.map { |d| d.staff&.name }.uniq.compact
56
+ end if role
57
+
58
+ if @current_admin.is_admin?
59
+ @follow_ups = TeacherFollow.all
60
+ else
61
+ level = @current_admin.role.role_areas.find_by(clazz: '教师运营').level
62
+ case level
63
+ when '自己'
64
+ @follow_ups = TeacherFollow.where(staff_id: @current_admin.id)
65
+ when '区域'
66
+ school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id)
67
+ teacher_ids = EducodeSales::Teacher.joins("JOIN departments ON educode_sales_teachers.department_id = departments.id").where("departments.school_id in (?) OR educode_sales_teachers.staff_id = #{@current_admin.id}", school_ids).pluck(:id)
68
+ @follow_ups = TeacherFollow.where(teacher_id: teacher_ids)
69
+ else
70
+ @follow_ups = TeacherFollow.all
71
+ end
72
+ end
73
+ if params[:q].present? && params[:q][:name].present?
74
+ @follow_ups = @follow_ups.joins(:teacher).where("educode_sales_teachers.name LIKE ?", "%#{params[:q][:name]}%")
75
+ end
76
+
77
+ if params[:q].present? && params[:q][:staff_id].present?
78
+ staff = Staff.find(params[:q][:staff_id])
79
+ school_ids = School.where(province: staff.areas.pluck(:name)).pluck(:id)
80
+ teacher_ids = EducodeSales::Teacher.joins("JOIN departments ON educode_sales_teachers.department_id = departments.id").where("departments.school_id in (?)", school_ids).pluck(:id)
81
+ @follow_ups = @follow_ups.where(teacher_id: teacher_ids)
82
+ end
83
+
84
+ if params[:q].present? && params[:q][:department].present?
85
+ departments_ids = Department.joins(:school).where("schools.name like ?", "%#{params[:q][:department]}%").pluck(:id)
86
+ @follow_ups = @follow_ups.joins(:teacher).where("department_id in (?)", departments_ids)
87
+ end
88
+
89
+ if params[:q].present? && params[:q][:area].present?
90
+ p = EducodeSales::Common.find(params[:q][:area]).name
91
+ # if @current_admin.is_admin?
92
+ @follow_ups = @follow_ups.joins(:teacher).joins("
93
+ JOIN departments ON educode_sales_teachers.department_id = departments.id
94
+ JOIN schools ON departments.school_id = schools.id
95
+ ").where("province = ?", p)
96
+ # else
97
+ # level = @current_admin.role.role_areas.find_by(clazz: '教师运营').level
98
+ # if level == "区域"
99
+ # school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id)
100
+ # @follow_ups = @follow_ups.joins(:teacher).joins("
101
+ # JOIN departments ON educode_sales_teachers.department_id = departments.id
102
+ # JOIN schools ON departments.school_id = schools.id
103
+ # ").where("province = ? AND departments.school_id in (?)", p, school_ids)
104
+ # else
105
+ # @follow_ups = @follow_ups.joins(:teacher).joins("
106
+ # JOIN departments ON educode_sales_teachers.department_id = departments.id
107
+ # JOIN schools ON departments.school_id = schools.id
108
+ # ").where("province = ?", p)
109
+ # end
110
+ # end
111
+ end
112
+
113
+ if params[:q].present? && params[:q][:attitude_id].present?
114
+ @follow_ups = @follow_ups.where("educode_sales_teacher_follows.attitude_id = ?", "#{params[:q][:attitude_id]}")
115
+ end
116
+
117
+ if params[:q].present? && params[:q][:description].present?
118
+ @follow_ups = @follow_ups.where("educode_sales_teacher_follows.description LIKE ?", "%#{params[:q][:description]}%")
119
+ end
120
+
121
+ if params[:q].present? && params[:q][:follows_date].present?
122
+ date = params[:q][:follows_date].split(" - ")
123
+ @follow_ups = @follow_ups.where("educode_sales_teacher_follows.created_at > ? AND educode_sales_teacher_follows.created_at < ?", date[0], date[1] + ' 23:59:59')
124
+ end
125
+
126
+ @follow_ups = @follow_ups.includes(:teacher, :attitude, :staff)
127
+ if params[:sort].present? && params[:sort][:field]
128
+ @follow_ups = @follow_ups.order("#{params[:sort][:field]} #{params[:sort][:order]}")
129
+ else
130
+ @follow_ups = @follow_ups.order("educode_sales_teacher_follows.created_at desc")
131
+ end
132
+ @follow_ups = @follow_ups.page(params[:page]).per(params[:limit])
133
+ end
134
+
135
+ private
136
+
137
+ def load_teacher
138
+ @teacher = Teacher.find(params[:teacher_id])
139
+ end
140
+
141
+ def follow_up_params
142
+ params.permit(:attitude_id, :follow_id, :course_plan_id, :course_build_id, :description, :advise, :is_contact)
143
+ end
144
+
145
+ end
146
+ end
@@ -221,6 +221,43 @@ module EducodeSales
221
221
  render layout: false
222
222
  end
223
223
 
224
+ def show_follow
225
+ @idea_follow = IdeaFollow.find(params[:id])
226
+ staffs = Staff.where.not(role_id: 11).includes(:user)
227
+ gon.sale_staffs = staffs.map { |d| { name: d.user.real_name, value: d.id, selected: d.id == @idea_follow.sale_staff_id } }
228
+ gon.idea_staffs = staffs.map { |d| { name: d.user.real_name, value: d.id, selected: d.id == @idea_follow.idea_staff_id } }
229
+ respond_to do |format|
230
+ format.html do
231
+ render layout: false
232
+ end
233
+ format.json do
234
+ end
235
+ end
236
+ end
237
+
238
+ def follow_list
239
+ @idea = Idea.find(params[:id])
240
+ respond_to do |format|
241
+ format.html do
242
+ render layout: false
243
+ end
244
+ format.json do
245
+ @follow_ups = @idea.idea_follows.includes(:staff, :sale_staff, :idea_staff).order(id: :desc)
246
+ @latest = @follow_ups.order(id: :desc).first
247
+ @follow_ups = @follow_ups.page(params[:page]).per(params[:limit])
248
+ end
249
+ end
250
+ end
251
+
252
+ def edit_follow_record
253
+ @idea_follow = IdeaFollow.find(params[:id])
254
+ @idea = @idea_follow.idea
255
+ staffs = Staff.where.not(role_id: 11).includes(:user)
256
+ gon.sale_staffs = staffs.map { |d| { name: d.user.real_name, value: d.id, selected: d.id == @idea_follow.sale_staff_id } }
257
+ gon.idea_staffs = staffs.map { |d| { name: d.user.real_name, value: d.id, selected: d.id == @idea_follow.idea_staff_id } }
258
+ render layout: false
259
+ end
260
+
224
261
  def follow_up
225
262
  idea = Idea.find(params[:id])
226
263
  follow_up = IdeaFollow.new(idea_id: idea.id, staff_id: @current_admin.id, money: params[:money], content: params[:content], status: params[:status], advise: params[:advise], sale_staff_id: params[:sale_staff_id], idea_staff_id: params[:idea_staff_id])
@@ -6,7 +6,7 @@ module EducodeSales
6
6
  def index
7
7
  respond_to do |format|
8
8
  format.html do
9
-
9
+
10
10
  end
11
11
  format.js do
12
12
  gon.edit_record = can?(:update_record, EducodeSales::MoneyPlan)
@@ -50,7 +50,7 @@ module EducodeSales
50
50
  elsif params[:q][:state] == '无对应合同'
51
51
  @money_plan_records = @money_plan_records.having("claim_num = 0 AND business_id IS NULL")
52
52
  end
53
-
53
+
54
54
  end
55
55
 
56
56
  if params[:q].present? && params[:q][:staff_manages].present?
@@ -60,7 +60,7 @@ module EducodeSales
60
60
  LEFT JOIN educode_sales_assign_follow_ups ON educode_sales_assign_follow_ups.follow_up_id = last_follow_up.id").
61
61
  where("(educode_sales_assign_follow_ups.id IS NOT NULL AND educode_sales_assign_follow_ups.staff_id = ?) OR (educode_sales_assign_follow_ups.id IS NULL AND educode_sales_businesses.staff_id = ?)", params[:q][:staff_manages], params[:q][:staff_manages])
62
62
  end
63
-
63
+
64
64
  if params[:q].present? && params[:q][:amount].present?
65
65
  @money_plan_records = @money_plan_records.where(amount: params[:q][:amount])
66
66
  end
@@ -119,7 +119,7 @@ module EducodeSales
119
119
  business_id = Business.find_by(number: ods.row(r+2)[3].to_s.strip)&.id
120
120
  EducodeSales::MoneyPlanRecord.create(payer_name: ods.row(r+2)[0].to_s.strip, amount: ods.row(r+2)[1].to_s.strip, date_at: ods.row(r+2)[2].to_s.strip, business_id: business_id, staff_id: @current_admin.id) if business_id
121
121
  end
122
-
122
+
123
123
  render json: { succcess: true}
124
124
  end
125
125
 
@@ -163,15 +163,15 @@ module EducodeSales
163
163
  # last_follow_up = business.last_follow_up
164
164
  # if last_follow_up.present?
165
165
  # follow_up = last_follow_up.dup
166
-
166
+
167
167
  # follow_up.description = "认领了回款记录"
168
-
168
+
169
169
  # follow_up.staff = @current_admin
170
-
170
+
171
171
  # last_follow_up.assign_follow_ups.each do |d|
172
172
  # follow_up.assign_follow_ups.build(staff_id: d.staff_id)
173
173
  # end
174
-
174
+
175
175
  # if follow_up.save!
176
176
  # last_follow_up.key_person.each do |d|
177
177
  # key_person = d.dup
@@ -187,9 +187,13 @@ module EducodeSales
187
187
  # end
188
188
  end
189
189
  end
190
-
191
190
  businesses.uniq.each do |d|
192
- d.update(return_money: d.money_plans.joins(:money_plan_claims).sum("educode_sales_money_plan_claims.amount") )
191
+ d.update(return_money: d.money_plans.joins(:money_plan_claims).sum("educode_sales_money_plan_claims.amount").round(6) )
192
+
193
+ # 更新对应的计划完成度
194
+ staff_manage_ids = d&.last_follow_up&.assign_follow_ups.present? ? d.last_follow_up.assign_follow_ups.pluck(:staff_id) : [d.staff_id]
195
+ common_id = EducodeSales::Common.find_by(clazz: '计划类型', name: '回款计划')&.id
196
+ EducodeSales::SalePlan.where(month: Time.now.beginning_of_month, business: d, staff_id: staff_manage_ids, common_id: common_id).update_all(finish_rate: 100)
193
197
  end
194
198
  render_success
195
199
  end
@@ -92,16 +92,18 @@ module EducodeSales
92
92
  data = []
93
93
  week = Time.now.strftime('%W').to_i
94
94
  current_week = ""
95
- staff_manage_ids = business&.last_follow_up&.assign_follow_ups.present? ? business.last_follow_up.assign_follow_ups.pluck(:staff_id) : [business.staff_id]
95
+
96
96
  (params[:num].to_i+1).times do |i|
97
97
  _week = params["date_at[#{i}]"].to_date.strftime('%W').to_i
98
98
  current_week = _week if _week == week
99
99
  business.money_plans.create(category: params["category[#{i}]"], amount: params["amount[#{i}]"], payment_clause: params["payment_clause[#{i}]"], date_at: params["date_at[#{i}]"], follow_up_id: business.last_follow_up_id, staff_id: @current_admin.id )
100
100
  end
101
101
  if current_week.present?
102
+ staff_manage_ids = business&.last_follow_up&.assign_follow_ups.present? ? business.last_follow_up.assign_follow_ups.pluck(:staff_id) : [business.staff_id]
103
+ common_id = EducodeSales::Common.find_by(clazz: '计划类型', name: '回款计划')&.id
102
104
  staff_manage_ids.each do |staff_id|
103
- EducodeSales::SalePlan.create(month: Time.now.beginning_of_month, weekly: week, content: "提醒:请补充回款计划内容!", business: business, staff_id: staff_id, finish_rate: '0' )
104
- EducodeSales::SalePlan.create(month: Time.now.beginning_of_month, content: "提醒:请补充回款计划内容!", business: business, staff_id: staff_id, finish_rate: '0' )
105
+ EducodeSales::SalePlan.create(month: Time.now.beginning_of_month, weekly: week, content: "提醒:请补充回款计划内容!", business: business, staff_id: staff_id, finish_rate: '0', common_id: common_id )
106
+ EducodeSales::SalePlan.create(month: Time.now.beginning_of_month, content: "提醒:请补充回款计划内容!", business: business, staff_id: staff_id, finish_rate: '0', common_id: common_id )
105
107
  end
106
108
  end
107
109
  render_success
@@ -61,7 +61,11 @@ module EducodeSales
61
61
  def create
62
62
  if params["year"].present?
63
63
  business = Business.find_by(id: params[:business_id])
64
- plan = @current_admin.sale_plans.build(year: params[:year], business_id: business.id, clazz: params[:clazz])
64
+ plan = @current_admin.sale_plans.build(year: params[:year], business_id: business.id, clazz: params[:clazz], common_id: params[:common_id] )
65
+ if params[:assign_id].present?
66
+ plan.staff_id = params[:assign_id]
67
+ plan.assign_id = @current_admin.id
68
+ end
65
69
  if plan.save
66
70
  render_success
67
71
  else
@@ -71,6 +75,11 @@ module EducodeSales
71
75
  plan = @current_admin.sale_plans.build(plan_params)
72
76
  plan.month = params["month"] + "-1"
73
77
  plan.business = Business.find_by(id: params[:business_id])
78
+
79
+ if params[:assign_id].present?
80
+ plan.staff_id = params[:assign_id]
81
+ plan.assign_id = @current_admin.id
82
+ end
74
83
  if plan.save
75
84
  render_success
76
85
  else
@@ -93,6 +102,10 @@ module EducodeSales
93
102
 
94
103
  def new_week
95
104
  @business = Business.find_by(id: params[:business_id])
105
+ common = Common.find_by(clazz: 'staff_type', name: '销售')
106
+ @staffs = Staff.includes(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id] }
107
+
108
+
96
109
  @week = Time.now.strftime('%W').to_i
97
110
  week = Time.now.strftime('%W').to_i
98
111
  if week > 3
@@ -102,6 +115,7 @@ module EducodeSales
102
115
  else
103
116
  @weeks = [[week.to_s + ' 本周',week]]
104
117
  end
118
+ @commons = Common.where(clazz: '计划类型').pluck(:name, :id)
105
119
  business_ids = EducodeSales::AssignFollowUp.joins(:follow_up).where(staff_id: @current_admin.id).pluck :business_id
106
120
  @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)
107
121
  @businesses = @businesses.map { |b| [b.name + "(#{b.department&.school&.name} #{b.department&.name})" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : b.created_at.to_s), b.id] }
@@ -129,6 +143,10 @@ module EducodeSales
129
143
  end
130
144
 
131
145
  def new_month
146
+ @commons = Common.where(clazz: '计划类型').pluck(:name, :id)
147
+ common = Common.find_by(clazz: 'staff_type', name: '销售')
148
+ @staffs = Staff.includes(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id] }
149
+
132
150
  @business = Business.find_by(id: params[:business_id])
133
151
  business_ids = EducodeSales::AssignFollowUp.joins(:follow_up).where(staff_id: @current_admin.id).pluck :business_id
134
152
  @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)
@@ -201,10 +219,14 @@ module EducodeSales
201
219
  end
202
220
 
203
221
  def edit_week
222
+ @commons = Common.where(clazz: '计划类型').pluck(:name, :id)
204
223
  business_ids = EducodeSales::AssignFollowUp.joins(:follow_up).where(staff_id: @current_admin.id).pluck :business_id
205
- @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)
206
- @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] }
207
224
  @sale_plan = SalePlan.find(params[:id])
225
+ # 加入指派的商机id
226
+ business_ids << @sale_plan.business_id
227
+ @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)
228
+ @businesses = @businesses.map { |b| [b.name + "(" + b.department&.school&.name.to_s + ")" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : b.created_at.to_s), b.id] }
229
+
208
230
  if @sale_plan.weekly.present?
209
231
  week = Time.now.strftime('%W').to_i
210
232
  if week > 3
@@ -267,9 +289,10 @@ module EducodeSales
267
289
  end
268
290
 
269
291
  def edit_month
292
+ @commons = Common.where(clazz: '计划类型').pluck(:name, :id)
270
293
  business_ids = EducodeSales::AssignFollowUp.joins(:follow_up).where(staff_id: @current_admin.id).pluck :business_id
271
294
  @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)
272
- @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] }
295
+ @businesses = @businesses.map { |b| [b.name + "(" + b.department&.school&.name.to_s + ")" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : b.created_at.to_s), b.id] }
273
296
  @sale_plan = SalePlan.find(params[:id])
274
297
  @finish_rates = []
275
298
  11.times { |d| @finish_rates << ["#{d*10}%", d * 10]}
@@ -448,7 +471,7 @@ module EducodeSales
448
471
  private
449
472
 
450
473
  def plan_params
451
- params.permit(:month, :weekly, :content, :finish_rate, :business_id)
474
+ params.permit(:month, :weekly, :content, :finish_rate, :business_id, :common_id, :assign_id)
452
475
  end
453
476
 
454
477
  def business_info_params
@@ -248,7 +248,17 @@ module EducodeSales
248
248
  end
249
249
 
250
250
  def visit_analysis_charts(visit_count_year, visit_count_season, visit_count_month, visit_count_week, visit_type, title_names)
251
- names = visit_count_year.map{|d| d[0]}
251
+ if visit_type.present? && visit_type.include?("1")
252
+ names = visit_count_year.map{|d| d[0]}
253
+ elsif visit_type.present? && visit_type.include?("2")
254
+ names = visit_count_season.map{|d| d[0]}
255
+ elsif visit_type.present? && visit_type.include?("3")
256
+ names = visit_count_month.map{|d| d[0]}
257
+ elsif visit_type.present? && visit_type.include?("4")
258
+ names = visit_count_week.map{|d| d[0]}
259
+ else
260
+ names = visit_count_year.map{|d| d[0]}
261
+ end
252
262
 
253
263
  visit_count_season_data = []
254
264
  names.each do |name|
@@ -3,6 +3,7 @@ module EducodeSales
3
3
  acts_as_list scope: [:clazz]
4
4
 
5
5
  has_many :market_areas, class_name: 'MarketArea', foreign_key: 'area_id'
6
+ has_many :sale_plans, dependent: :nullify
6
7
 
7
8
  XTYPE = "x_class"
8
9
  OTYPE = 'o_class'
@@ -24,7 +25,8 @@ module EducodeSales
24
25
  '跟进手段': 'contact',
25
26
  '人员类型': 'staff_type',
26
27
  '开课计划': 'course_plan',
27
- '区域': 'area'
28
+ '区域': 'area',
29
+ '计划类型': 'plan_type'
28
30
  }
29
31
 
30
32
  def self.job_type_name
@@ -11,7 +11,7 @@ module EducodeSales
11
11
 
12
12
  def update_return_money
13
13
  amount = self.money_plan.business.money_plans.joins(:money_plan_claims).sum("educode_sales_money_plan_claims.amount")
14
- self.money_plan.business.update(return_money: amount)
14
+ self.money_plan.business.update(return_money: amount.round(6))
15
15
  end
16
16
  end
17
17
  end
@@ -16,7 +16,8 @@ module EducodeSales
16
16
  '绩效考核': 'assessments_setting',
17
17
  '方案管理': 'idea',
18
18
  '项目管理': 'project',
19
- '合同管理': 'contract'
19
+ '合同管理': 'contract',
20
+ '产品目录': 'product_category'
20
21
  }
21
22
  end
22
23
  end
@@ -3,6 +3,8 @@ module EducodeSales
3
3
  include ::Deletable
4
4
  belongs_to :business
5
5
  belongs_to :staff
6
+ belongs_to :common, optional: true
7
+ belongs_to :assign, class_name: "Staff", optional: true
6
8
  validates :business_id, presence: true
7
9
 
8
10
  has_many :business_infos