educode_sales 1.10.48 → 1.10.58

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/stylesheets/educode_sales/modules/easyeditor/easyeditor.css +130 -0
  3. data/app/assets/stylesheets/educode_sales/modules/easyeditor/fangge-style.css +4 -0
  4. data/app/controllers/educode_sales/application_controller.rb +22 -0
  5. data/app/controllers/educode_sales/business_courses_controller.rb +255 -0
  6. data/app/controllers/educode_sales/businesses_controller.rb +43 -7
  7. data/app/controllers/educode_sales/contracts_controller.rb +6 -0
  8. data/app/controllers/educode_sales/home_controller.rb +7 -0
  9. data/app/controllers/educode_sales/money_plan_records_controller.rb +6 -2
  10. data/app/controllers/educode_sales/money_plans_controller.rb +3 -0
  11. data/app/controllers/educode_sales/sale_trends_controller.rb +1 -1
  12. data/app/controllers/educode_sales/shixun_dectects_controller.rb +172 -0
  13. data/app/controllers/educode_sales/shixuns_controller.rb +218 -0
  14. data/app/controllers/educode_sales/subject_trends_controller.rb +144 -0
  15. data/app/controllers/educode_sales/subjects_controller.rb +213 -0
  16. data/app/helpers/educode_sales/application_helper.rb +10 -0
  17. data/app/helpers/educode_sales/business_courses_helper.rb +60 -0
  18. data/app/helpers/educode_sales/sale_trends_helper.rb +52 -52
  19. data/app/helpers/educode_sales/subject_helper.rb +33 -0
  20. data/app/models/educode_sales/business.rb +22 -0
  21. data/app/models/educode_sales/business_deliver_subject.rb +49 -0
  22. data/app/models/educode_sales/business_subject.rb +68 -0
  23. data/app/models/educode_sales/business_subject_shixun.rb +75 -0
  24. data/app/models/educode_sales/business_subject_staff.rb +36 -0
  25. data/app/models/educode_sales/permission.rb +2 -1
  26. data/app/models/educode_sales/shixun_dectect.rb +12 -0
  27. data/app/views/educode_sales/business_courses/edit.html.erb +174 -0
  28. data/app/views/educode_sales/business_courses/index.html.erb +334 -0
  29. data/app/views/educode_sales/business_courses/index.json.jbuilder +16 -0
  30. data/app/views/educode_sales/business_courses/list_shixuns.html.erb +292 -0
  31. data/app/views/educode_sales/business_courses/list_shixuns.json.jbuilder +23 -0
  32. data/app/views/educode_sales/business_courses/list_subjects.html.erb +212 -0
  33. data/app/views/educode_sales/business_courses/list_subjects.json.jbuilder +17 -0
  34. data/app/views/educode_sales/business_courses/new.html.erb +237 -0
  35. data/app/views/educode_sales/businesses/index.html.erb +11 -9
  36. data/app/views/educode_sales/contracts/_list.html.erb +16 -1
  37. data/app/views/educode_sales/contracts/index.html.erb +5 -2
  38. data/app/views/educode_sales/contracts/list.js.erb +4 -1
  39. data/app/views/educode_sales/money_plan_records/_index.html.erb +21 -5
  40. data/app/views/educode_sales/money_plan_records/index.js.erb +4 -1
  41. data/app/views/educode_sales/money_plans/list.html.erb +6 -2
  42. data/app/views/educode_sales/sale_trends/_return_money_forecast.html.erb +1 -1
  43. data/app/views/educode_sales/sale_trends/_user_stat.html.erb +1 -1
  44. data/app/views/educode_sales/sale_trends/_visit_analysis.html.erb +1 -1
  45. data/app/views/educode_sales/sale_trends/return_money_forecast.js.erb +1 -1
  46. data/app/views/educode_sales/sale_trends/trends.html.erb +6 -6
  47. data/app/views/educode_sales/sale_trends/user_stat.js.erb +1 -1
  48. data/app/views/educode_sales/sale_trends/visit_analysis.js.erb +1 -1
  49. data/app/views/educode_sales/shixun_dectects/index.html.erb +516 -0
  50. data/app/views/educode_sales/shixun_dectects/index.json.jbuilder +23 -0
  51. data/app/views/educode_sales/shixun_dectects/markdown.html.erb +60 -0
  52. data/app/views/educode_sales/shixuns/edit.html.erb +208 -0
  53. data/app/views/educode_sales/shixuns/index.html.erb +723 -0
  54. data/app/views/educode_sales/shixuns/index.json.jbuilder +26 -0
  55. data/app/views/educode_sales/shixuns/new.html.erb +261 -0
  56. data/app/views/educode_sales/subject_trends/trends.html.erb +676 -0
  57. data/app/views/educode_sales/subjects/edit.html.erb +86 -0
  58. data/app/views/educode_sales/subjects/index.html.erb +285 -0
  59. data/app/views/educode_sales/subjects/index.json.jbuilder +16 -0
  60. data/app/views/educode_sales/subjects/list_shixuns.html.erb +354 -0
  61. data/app/views/educode_sales/subjects/list_shixuns.json.jbuilder +22 -0
  62. data/app/views/educode_sales/subjects/new.html.erb +254 -0
  63. data/app/views/layouts/educode_sales/application.html.erb +38 -0
  64. data/config/routes.rb +37 -0
  65. data/lib/educode_sales/version.rb +1 -1
  66. metadata +42 -7
  67. data/app/assets/images/educode_sales/indexlogo.png +0 -0
@@ -0,0 +1,213 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EducodeSales
4
+ include SubjectHelper
5
+
6
+ # 实践课程管理
7
+ class SubjectsController < ApplicationController
8
+ before_action :subject_members, :subject_url
9
+
10
+ def index
11
+ authorize! :subject, BusinessDeliverSubject
12
+ respond_to do |format|
13
+ format.html do
14
+ end
15
+ format.json do
16
+
17
+ if is_commissioner_above?
18
+ business_subject = BusinessSubject
19
+ else
20
+ deliver_staffs = BusinessSubject.joins(business_deliver_subject: [manages: :staff])
21
+ business_subject_ids = deliver_staffs.where("educode_sales_staffs.id = #{@current_admin.id} ").ids
22
+ subject_staffs = BusinessSubject.where(id: BusinessSubject.ids - deliver_staffs.ids).joins(manages: :staff).where("educode_sales_staffs.id = #{@current_admin.id} ")
23
+ business_subject = BusinessSubject.where(id: business_subject_ids + subject_staffs.ids )
24
+ end
25
+
26
+
27
+ business_subject = business_subject.joins(:subject).left_joins(business_deliver_subject: [:manages, business: [:last_follow_up]])
28
+ if params[:q] && params[:q][:business_name].present?
29
+ business_subject = business_subject.joins(:business).where("educode_sales_businesses.name like '%#{params[:q][:business_name]}%' ")
30
+ end
31
+ # 查询条件 实践课程名称
32
+ if params[:q] && params[:q][:subjects_name].present?
33
+ business_subject = business_subject.where("subjects.name like '%#{params[:q][:subjects_name]}%'")
34
+ end
35
+ # 查询条件 时间
36
+ if params[:q] && params[:q][:time].present?
37
+ start_time = params[:q][:time].split(" - ")[0]
38
+ end_time = params[:q][:time].split(" - ")[-1]
39
+ business_subject = business_subject.where("educode_sales_business_subjects.deliver_date BETWEEN '#{start_time}' AND '#{end_time}' OR
40
+ educode_sales_follow_ups.reception_at BETWEEN'#{start_time}' AND '#{end_time}'")
41
+ end
42
+ business_subject_schools = {}
43
+ business_subject_manges = {}
44
+ business_subject_staffs = {}
45
+ BusinessSubject.includes(:school, :manages, :subject, :staffs, business_deliver_subject: [:manages, business: [:school, last_follow_up: :assign_follow_ups] ]).find_each do |d|
46
+ b_d_s = d.business_deliver_subject
47
+
48
+ b_d_s.present? ? business_subject_schools.merge!({ "#{d.id}": d.business.school.name }) : business_subject_schools.merge!({"#{d.id}": d.school_name })
49
+ b_d_s.present? ? business_subject_manges.merge!({ "#{d.id}": b_d_s.subject_manages}) : business_subject_manges.merge!({"#{d.id}": d.manges_name })
50
+ b_d_s.present? ? business_subject_staffs.merge!({ "#{d.id}": d.business.staff_name }) : business_subject_staffs.merge!({"#{d.id}": d.staffs_name })
51
+
52
+ end
53
+ @business_subject_schools = business_subject_schools.stringify_keys
54
+ @business_subject_staffs = business_subject_staffs.stringify_keys
55
+ @business_subject_manges = business_subject_manges.stringify_keys
56
+ business_subject = business_subject.select("subjects.name s_name,
57
+ subjects.identifier s_identifier,
58
+ subjects.status status,
59
+ subjects.public public,
60
+ educode_sales_business_subjects.id,
61
+ IFNULL(educode_sales_follow_ups.reception_at, educode_sales_business_subjects.deliver_date) deliver_date,
62
+ IFNULL(educode_sales_businesses.name, '--' ) b_name
63
+ ")
64
+ @count = business_subject.count("educode_sales_business_subjects.id")
65
+ @business_subject = business_subject.page(params[:page]).per(params[:limit])
66
+
67
+ end
68
+ end
69
+ end
70
+
71
+ def new
72
+ authorize! :subject, BusinessDeliverSubject
73
+ # staffs = Staff.where.not(role_id: 11).includes(:user)
74
+ gon.staffs = @manages
75
+ render layout: false
76
+ end
77
+
78
+ def edit
79
+ authorize! :subject, BusinessDeliverSubject
80
+ if params[:id]
81
+ business_subject = BusinessSubject.find(params[:id])
82
+ @item = business_subject.subject
83
+ @select = @item.shixuns.map { |item| { value: item.id, name: item.name } }
84
+ @id = business_subject.id
85
+ @school_id = business_subject.school_id
86
+ @default_select = BusinessSubjectShixun.where("business_subject_id = #{params[:id]}")
87
+ .select(:shixun_id)
88
+ .map { |item| item.shixun_id }
89
+ render layout: false
90
+ end
91
+ end
92
+
93
+ def create
94
+ authorize! :subject, BusinessDeliverSubject
95
+ # 开启事务
96
+ ActiveRecord::Base.transaction do
97
+ subject = Subject.where.not(id: BusinessSubject.pluck(:subject_id) ).find_by(id: params[:subject_id])
98
+ if subject.present?
99
+ attr = {
100
+ deliver_date: params[:deliver_date],
101
+ school_id: params[:school_id],
102
+ subject_id: subject.id
103
+ }
104
+ new_object = BusinessSubject.create(attr)
105
+
106
+ new_object.add_subject_shixuns(params[:shixun_ids].split(',').map(&:to_i))
107
+
108
+
109
+ BusinessSubjectStaff.bulk_insert(:staff_id, :container_id, :container_type, :created_at, :updated_at, :category) do |d|
110
+ params[:manage_id].split(",").each do |m|
111
+ d.add [m.to_i, new_object.id, BusinessSubjectStaff::CONTAINER_TYPES::SUBJECT, Time.now, Time.now, BusinessSubjectStaff::CATEGORY_TYPES::SUBJECT_MANAGE ]
112
+ end
113
+ params[:sale_id].split(",").each do |s|
114
+ d.add [s.to_i, new_object.id, BusinessSubjectStaff::CONTAINER_TYPES::SUBJECT, Time.now, Time.now, BusinessSubjectStaff::CATEGORY_TYPES::SUBJECT_STAFF ]
115
+ end
116
+ end
117
+
118
+ render_success
119
+ else
120
+ render_failure("操作失败")
121
+ end
122
+ end
123
+ end
124
+
125
+ def update
126
+ authorize! :subject, BusinessDeliverSubject
127
+ # 开启事务
128
+ ActiveRecord::Base.transaction do
129
+ business_subject = BusinessSubject.find_by(id: params[:id])
130
+
131
+ if business_subject
132
+ new_shixun_ids = params[:shixun_ids].split(',').map(&:to_i)
133
+ old_shixun_ids = business_subject.business_subject_shixuns.pluck(:shixun_id)
134
+
135
+ # 需要删除的科目id
136
+ change_shixuns = old_shixun_ids - new_shixun_ids
137
+ add_shixuns = new_shixun_ids - old_shixun_ids
138
+
139
+ # 取消关联
140
+ business_subject.business_subject_shixuns.where(shixun_id: change_shixuns).update_all(business_subject_id: nil)
141
+
142
+ # 创建关联
143
+ business_subject.add_subject_shixuns(add_shixuns)
144
+
145
+ render_success
146
+ else
147
+ render_failure("操作失败")
148
+ end
149
+
150
+ end
151
+ end
152
+
153
+ def shixun_list
154
+ respond_to do |format|
155
+ format.json do
156
+ @list = Shixun.where(hidden: 0).where.not(id: BusinessSubjectShixun.joins(:business_subject).pluck(:shixun_id) ) # 1先创建实践项目下,通过实践课程无法选该
157
+ if params[:q].present?
158
+ @list = @list.where("name like '%#{params[:q]}%'").page(params[:page]).per(10)
159
+ end
160
+ if params[:subject_id].present?
161
+ @list = @list.joins(:stage_shixuns).where("subject_id = #{params[:subject_id]}")
162
+ end
163
+ render json: {
164
+ data: @list.map { |item| { value: item[:id], name: item[:name] } },
165
+ code: 0
166
+ }
167
+ end
168
+ end
169
+ end
170
+
171
+ def search_subjects
172
+ respond_to do |format|
173
+ format.json do
174
+ @subjects = Subject.unhidden.where.not(id: BusinessSubject.pluck(:subject_id)).where("name like '%#{params[:q]}%' ").page(params[:page]).per(10)
175
+ render json: {
176
+ data: @subjects.map { |item| { value: item[:id], name: item[:name] } },
177
+ code: 0,
178
+ count: @subjects.total_count / 10
179
+ }
180
+ end
181
+ end
182
+ end
183
+
184
+ def list_shixuns
185
+ @shixuns = BusinessSubjectShixun.left_joins(:last_dectect)
186
+ .left_joins(:shixun)
187
+ .where("business_subject_id = #{params[:id]}")
188
+
189
+ if params[:q].present? && params[:q][:shixun_name].present?
190
+ @shixuns = @shixuns.where("shixuns.name like '%#{params[:q][:shixun_name]}%'")
191
+ end
192
+ if params[:q].present? && params[:q][:level].present? && params[:q][:level].to_i != 0
193
+ @shixuns = @shixuns.where(level: params[:q][:level])
194
+ end
195
+ # 项目状态 0 全部
196
+ if params[:q].present? && params[:q][:status].present? && params[:q][:status].to_i != 0
197
+ @shixuns = @shixuns.where(shixun_status: params[:q][:status])
198
+ end
199
+ if params[:q].present? && params[:q][:category].present? && params[:q][:category].to_i != 0
200
+ @shixuns = @shixuns.where(category: params[:q][:category])
201
+ end
202
+ @shixuns = @shixuns.select("educode_sales_business_subject_shixuns.*,
203
+ shixuns.name as shixun_name,
204
+ shixuns.identifier,
205
+ educode_sales_shixun_dectects.created_at as shixun_dectects_time,
206
+ educode_sales_shixun_dectects.content as dectects_content")
207
+ .page(params[:page])
208
+ .per(params[:limit])
209
+ render layout: false
210
+ end
211
+
212
+ end
213
+ end
@@ -9,6 +9,16 @@ module EducodeSales
9
9
  end
10
10
  end
11
11
 
12
+ def handled_data(item)
13
+ item.blank? ? "--" : item
14
+ end
15
+
16
+ def handled_time_data(item)
17
+ item.blank? ? "--" : item.strftime("%Y-%m-%d")
18
+ end
19
+ def handled_time_data_accurate(item)
20
+ item.blank? ? "--" : item.strftime("%Y-%m-%d %H:%M:%S")
21
+ end
12
22
  def url_to_avatar(source)
13
23
  return "" if source.blank?
14
24
  if File.exist?(disk_filename(source&.class, source&.id)) && File.file?(disk_filename(source&.class, source&.id))
@@ -0,0 +1,60 @@
1
+ module EducodeSales
2
+ module BusinessCoursesHelper
3
+
4
+ def real_shixun_category(categor)
5
+ case categor.to_i
6
+ when 1
7
+ "管培"
8
+ when 2
9
+ "全职"
10
+ when 3
11
+ "专职"
12
+ else
13
+ "管培"
14
+ end
15
+ end
16
+
17
+ def real_shixun_level(level)
18
+ case level.to_i
19
+ when 1
20
+ "不明确"
21
+ when 2
22
+ "重要紧急"
23
+ when 3
24
+ "重要不紧急"
25
+ when 4
26
+ "不重要紧急"
27
+ when 5
28
+ "不重要不紧急"
29
+ else
30
+ "不明确"
31
+ end
32
+ end
33
+ # 项目状态: 待建设(constructed) 已签协议(signed) 建设中(construction) 审核中(review),返修中(repair) 已内部公开(public), 已公开发布(published) 已经付费(paid)
34
+ def real_shixun_status(status)
35
+ case status.to_i
36
+ when 1
37
+ "待建设"
38
+ when 2
39
+ "已签协议"
40
+ when 3
41
+ "建设中"
42
+ when 4
43
+ "审核中"
44
+ when 5
45
+ "返修中"
46
+ when 6
47
+ "已内部发布"
48
+ when 7
49
+ "已公开发布"
50
+ when 8
51
+ "已付费用"
52
+ when 9
53
+ "审核通过"
54
+ end
55
+
56
+ end
57
+
58
+
59
+ end
60
+ end
@@ -1,7 +1,7 @@
1
1
  module EducodeSales
2
2
  module SaleTrendsHelper
3
3
  NAMES = %w[计划投标额 计划投标额累计 实际中标额 实际中标额累计]
4
- RETURN_NAMES = %w[实际回款额 计划回款额 实际回款 计划回款额-全部 计划回款额-o类]
4
+ RETURN_NAMES = %w[计划回款额 计划回款额-全部 实际回款额 实际回款额-累计 计划回款额-O类]
5
5
 
6
6
  def goal_forecast_quarter(labels, selects, staff_id = nil, property)
7
7
  plan_get = plan_get(staff_id, labels, "quarter", property)
@@ -349,7 +349,7 @@ module EducodeSales
349
349
  week = d.split("-").last
350
350
  year = d.split("-").first
351
351
  yearweek = "#{year}#{week}".to_i
352
- actual_return[yearweek].to_f.round(3)
352
+ plan_return[yearweek].to_f.round(3)
353
353
  end
354
354
  elsif select == RETURN_NAMES[1]
355
355
  arr = labels.map do |d|
@@ -367,12 +367,13 @@ module EducodeSales
367
367
  actual_return[yearweek].to_f.round(3)
368
368
  end
369
369
  elsif select == RETURN_NAMES[3]
370
- labels.map do |d|
370
+ arr = labels.map do |d|
371
371
  week = d.split("-").last
372
372
  year = d.split("-").first
373
373
  yearweek = "#{year}#{week}".to_i
374
- plan_return[yearweek].to_f.round(3)
374
+ actual_return[yearweek].to_f.round(3)
375
375
  end
376
+ arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) }
376
377
  elsif select == RETURN_NAMES[4]
377
378
  arr = labels.map do |d|
378
379
  week = d.split("-").last
@@ -382,16 +383,15 @@ module EducodeSales
382
383
  end
383
384
  arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) }
384
385
  end
385
- type = if select == RETURN_NAMES[0] || select == RETURN_NAMES[1]
386
+ type = if select == RETURN_NAMES[0] || select == RETURN_NAMES[2]
386
387
  'bar'
387
388
  else
388
389
  "line"
389
390
  end
390
- backgroundColor = if select == RETURN_NAMES[0] || select == RETURN_NAMES[1]
391
- 'rgba(54, 162, 235, 1)'
392
- else
391
+ backgroundColor = if select == RETURN_NAMES[0] || select == RETURN_NAMES[2]
393
392
  SaleTrend::COLORS[i]
394
- 'rgba(54, 162, 235, 0)'
393
+ else
394
+ 'rgba(54, 162, 235, 0.2)'
395
395
  end
396
396
  {
397
397
  type: type,
@@ -405,11 +405,11 @@ module EducodeSales
405
405
 
406
406
  hash_a = {
407
407
  labels: labels,
408
- datasets: [datasets[0], datasets[1]]
408
+ datasets: [datasets[0], datasets[2]]
409
409
  }
410
410
  hash_b = {
411
411
  labels: labels,
412
- datasets: [datasets[2], datasets[3], datasets[4]]
412
+ datasets: [datasets[1], datasets[4], datasets[3]]
413
413
  }
414
414
  [hash_a, hash_b]
415
415
  end
@@ -423,7 +423,7 @@ module EducodeSales
423
423
  labels.map do |d|
424
424
  quarter = d.split("-").last.to_i
425
425
  year = d.split("-").first.to_i
426
- actual_return[[year, quarter]]&.pluck(:amount)&.reject(&:blank?)&.sum.to_f.round(3)
426
+ plan_return[[year, quarter]]&.pluck(:plan_return_money)&.reject(&:blank?)&.sum.to_f.round(3)
427
427
  end
428
428
  elsif select == RETURN_NAMES[1]
429
429
  arr = labels.map do |d|
@@ -439,11 +439,12 @@ module EducodeSales
439
439
  actual_return[[year, quarter]]&.pluck(:amount)&.reject(&:blank?)&.sum.to_f.round(3)
440
440
  end
441
441
  elsif select == RETURN_NAMES[3]
442
- labels.map do |d|
442
+ arr = labels.map do |d|
443
443
  quarter = d.split("-").last.to_i
444
444
  year = d.split("-").first.to_i
445
- plan_return[[year, quarter]]&.pluck(:plan_return_money)&.reject(&:blank?)&.sum.to_f.round(3)
445
+ actual_return[[year, quarter]]&.pluck(:amount)&.reject(&:blank?)&.sum.to_f.round(3)
446
446
  end
447
+ arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) }
447
448
  elsif select == RETURN_NAMES[4]
448
449
  arr = labels.map do |d|
449
450
  quarter = d.split("-").last.to_i
@@ -452,16 +453,15 @@ module EducodeSales
452
453
  end
453
454
  arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) }
454
455
  end
455
- type = if select == RETURN_NAMES[0] || select == RETURN_NAMES[1]
456
+ type = if select == RETURN_NAMES[0] || select == RETURN_NAMES[2]
456
457
  'bar'
457
458
  else
458
459
  "line"
459
460
  end
460
- backgroundColor = if select == RETURN_NAMES[0] || select == RETURN_NAMES[1]
461
- 'rgba(54, 162, 235, 1)'
462
- else
461
+ backgroundColor = if select == RETURN_NAMES[0] || select == RETURN_NAMES[2]
463
462
  SaleTrend::COLORS[i]
464
- 'rgba(54, 162, 235, 0)'
463
+ else
464
+ 'rgba(54, 162, 235, 0.2)'
465
465
  end
466
466
  {
467
467
  type: type,
@@ -475,11 +475,11 @@ module EducodeSales
475
475
 
476
476
  hash_a = {
477
477
  labels: labels,
478
- datasets: [datasets[0], datasets[1]]
478
+ datasets: [datasets[0], datasets[2]]
479
479
  }
480
480
  hash_b = {
481
481
  labels: labels,
482
- datasets: [datasets[2], datasets[3], datasets[4]]
482
+ datasets: [datasets[1], datasets[4], datasets[3]]
483
483
  }
484
484
  [hash_a, hash_b]
485
485
  end
@@ -492,47 +492,47 @@ module EducodeSales
492
492
  datasets = selects.map.with_index do |select, i|
493
493
  data = if select == RETURN_NAMES[0]
494
494
  labels.map do |d|
495
- quarter = d.split("-").last.to_i
495
+ month = d.split("-").last.to_i
496
496
  year = d.split("-").first.to_i
497
- actual_return[[year, quarter]]&.pluck(:amount)&.reject(&:blank?)&.sum.to_f.round(3)
497
+ plan_return[[year, month]]&.pluck(:plan_return_money)&.reject(&:blank?)&.sum.to_f.round(3)
498
498
  end
499
499
  elsif select == RETURN_NAMES[1]
500
500
  arr = labels.map do |d|
501
- quarter = d.split("-").last.to_i
501
+ month = d.split("-").last.to_i
502
502
  year = d.split("-").first.to_i
503
- plan_return[[year, quarter]]&.pluck(:plan_return_money)&.reject(&:blank?)&.sum.to_f.round(3)
503
+ plan_return[[year, month]]&.pluck(:plan_return_money)&.reject(&:blank?)&.sum.to_f.round(3)
504
504
  end
505
505
  arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) }
506
506
  elsif select == RETURN_NAMES[2]
507
507
  labels.map do |d|
508
- quarter = d.split("-").last.to_i
508
+ month = d.split("-").last.to_i
509
509
  year = d.split("-").first.to_i
510
- actual_return[[year, quarter]]&.pluck(:amount)&.reject(&:blank?)&.sum.to_f.round(3)
510
+ actual_return[[year, month]]&.pluck(:amount)&.reject(&:blank?)&.sum.to_f.round(3)
511
511
  end
512
512
  elsif select == RETURN_NAMES[3]
513
- labels.map do |d|
514
- quarter = d.split("-").last.to_i
513
+ arr = labels.map do |d|
514
+ month = d.split("-").last.to_i
515
515
  year = d.split("-").first.to_i
516
- plan_return[[year, quarter]]&.pluck(:plan_return_money)&.reject(&:blank?)&.sum.to_f.round(3)
516
+ actual_return[[year, month]]&.pluck(:amount)&.reject(&:blank?)&.sum.to_f.round(3)
517
517
  end
518
+ arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) }
518
519
  elsif select == RETURN_NAMES[4]
519
520
  arr = labels.map do |d|
520
- quarter = d.split("-").last.to_i
521
+ month = d.split("-").last.to_i
521
522
  year = d.split("-").first.to_i
522
- plan_return_by_o[[year, quarter]]&.pluck(:plan_return_money)&.reject(&:blank?)&.sum.to_f.round(3)
523
+ plan_return_by_o[[year, month]]&.pluck(:plan_return_money)&.reject(&:blank?)&.sum.to_f.round(3)
523
524
  end
524
525
  arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) }
525
526
  end
526
- type = if select == RETURN_NAMES[0] || select == RETURN_NAMES[1]
527
+ type = if select == RETURN_NAMES[0] || select == RETURN_NAMES[2]
527
528
  'bar'
528
529
  else
529
530
  "line"
530
531
  end
531
- backgroundColor = if select == RETURN_NAMES[0] || select == RETURN_NAMES[1]
532
- 'rgba(54, 162, 235, 1)'
533
- else
532
+ backgroundColor = if select == RETURN_NAMES[0] || select == RETURN_NAMES[2]
534
533
  SaleTrend::COLORS[i]
535
- 'rgba(54, 162, 235, 0)'
534
+ else
535
+ 'rgba(54, 162, 235, 0.2)'
536
536
  end
537
537
  {
538
538
  type: type,
@@ -546,11 +546,11 @@ module EducodeSales
546
546
 
547
547
  hash_a = {
548
548
  labels: labels,
549
- datasets: [datasets[0], datasets[1]]
549
+ datasets: [datasets[0], datasets[2]]
550
550
  }
551
551
  hash_b = {
552
552
  labels: labels,
553
- datasets: [datasets[2], datasets[3], datasets[4]]
553
+ datasets: [datasets[1], datasets[4], datasets[3]]
554
554
  }
555
555
  [hash_a, hash_b]
556
556
  end
@@ -561,29 +561,29 @@ module EducodeSales
561
561
  plan_return_by_o = plan_return_by_o(staff_id, labels, "year", property)
562
562
  datasets = selects.map.with_index do |select, i|
563
563
  data = if select == RETURN_NAMES[0]
564
- labels.map { |d| actual_return[d.to_i] || 0 }
564
+ labels.map { |d| plan_return[d.to_i] || 0 }
565
565
  elsif select == RETURN_NAMES[1]
566
566
  arr = labels.map { |d| plan_return[d.to_i] || 0 }
567
567
  arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) }
568
568
  elsif select == RETURN_NAMES[2]
569
569
  labels.map { |d| actual_return[d.to_i] || 0 }
570
570
  elsif select == RETURN_NAMES[3]
571
- labels.map { |d| plan_return[d.to_i] || 0 }
571
+ arr = labels.map { |d| actual_return[d.to_i] || 0 }
572
+ arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) }
572
573
  elsif select == RETURN_NAMES[4]
573
574
  arr = labels.map { |d| plan_return_by_o[d.to_i] || 0 }
574
575
  arr.map.with_index(1) { |num, i| arr.first(i).inject(:+) }
575
576
  end
576
577
 
577
- type = if select == RETURN_NAMES[0] || select == RETURN_NAMES[1]
578
+ type = if select == RETURN_NAMES[0] || select == RETURN_NAMES[2]
578
579
  'bar'
579
580
  else
580
581
  "line"
581
582
  end
582
- backgroundColor = if RETURN_NAMES[0] || select == RETURN_NAMES[1]
583
- 'rgba(54, 162, 235, 1)'
584
- else
583
+ backgroundColor = if select == RETURN_NAMES[0] || select == RETURN_NAMES[2]
585
584
  SaleTrend::COLORS[i]
586
- 'rgba(54, 162, 235, 0)'
585
+ else
586
+ 'rgba(54, 162, 235, 0.2)'
587
587
  end
588
588
  {
589
589
  type: type,
@@ -597,11 +597,11 @@ module EducodeSales
597
597
 
598
598
  hash_a = {
599
599
  labels: labels,
600
- datasets: [datasets[0], datasets[1]]
600
+ datasets: [datasets[0], datasets[2]]
601
601
  }
602
602
  hash_b = {
603
603
  labels: labels,
604
- datasets: [datasets[2], datasets[3], datasets[4]]
604
+ datasets: [datasets[1], datasets[4], datasets[3]]
605
605
  }
606
606
  [hash_a, hash_b]
607
607
  end
@@ -725,7 +725,7 @@ module EducodeSales
725
725
  time_range.last.split("-").first + "-12-31"
726
726
  end
727
727
  staff_id = staff_id.present? ? Array(staff_id) : nil
728
- data = Business.joins(:last_follow_up)
728
+ data = Business.joins(:last_follow_up).where("educode_sales_businesses.deleted_at is null")
729
729
  .where("educode_sales_follow_ups.plan_return_date >= ? and educode_sales_follow_ups.plan_return_date <= ?", start_time, end_time)
730
730
  if staff_id.present?
731
731
  data = data.joins("LEFT JOIN educode_sales_follow_ups AS last_follow_up ON educode_sales_businesses.last_follow_up_id = last_follow_up.id AND last_follow_up.deleted_at IS NULL
@@ -773,14 +773,14 @@ module EducodeSales
773
773
  time_range.last.split("-").first + "-12-31"
774
774
  end
775
775
  staff_id = staff_id.present? ? Array(staff_id) : nil
776
- data = MoneyPlanRecord.joins(business: [department: [school: :school_tags]]).where("educode_sales_money_plan_records.date_at >= ? and educode_sales_money_plan_records.date_at <= ?", start_time, end_time)
776
+ data = MoneyPlanRecord.where("educode_sales_money_plan_records.date_at >= ? and educode_sales_money_plan_records.date_at <= ?", start_time, end_time)
777
777
  if staff_id.present?
778
778
  data = data.joins("LEFT JOIN educode_sales_follow_ups AS last_follow_up ON educode_sales_businesses.last_follow_up_id = last_follow_up.id AND last_follow_up.deleted_at IS NULL
779
779
  LEFT JOIN educode_sales_assign_follow_ups ON educode_sales_assign_follow_ups.follow_up_id = last_follow_up.id").
780
780
  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 = ?)", staff_id, staff_id)
781
781
  end
782
782
  if property.present?
783
- data = data.where("school_tags.id = ?", property)
783
+ data = data.joins(business: [department: [school: :school_tags]]).where("school_tags.id = ?", property)
784
784
  end
785
785
  case type
786
786
  when "week"
@@ -820,7 +820,7 @@ module EducodeSales
820
820
  time_range.last.split("-").first + "-12-31"
821
821
  end
822
822
  staff_id = staff_id.present? ? Array(staff_id) : nil
823
- data = Business.joins(:last_follow_up).where("educode_sales_businesses.clazz_id = ?", clazz_id)
823
+ data = Business.joins(:last_follow_up).where("educode_sales_businesses.deleted_at is null").where("educode_sales_businesses.clazz_id = ?", clazz_id)
824
824
  .where("educode_sales_follow_ups.plan_return_date >= ? and educode_sales_follow_ups.plan_return_date <= ?", start_time, end_time)
825
825
  if staff_id.present?
826
826
  data = data.joins("LEFT JOIN educode_sales_follow_ups AS last_follow_up ON educode_sales_businesses.last_follow_up_id = last_follow_up.id AND last_follow_up.deleted_at IS NULL
@@ -0,0 +1,33 @@
1
+ module EducodeSales
2
+ module SubjectHelper
3
+
4
+
5
+ def status(d)
6
+ d.public == 2 ? "已公开" : d.public == 1 ? "待审核" : d.status == 2 ? "已发布" : "编辑中"
7
+ end
8
+
9
+ def school_name(item)
10
+ item.business ? item.business.school.name : item.school_name
11
+ end
12
+
13
+ # def deliver_date(item)
14
+ # item.business ? item.business.p_course_time : item.deliver_date.strft审核中ime("%Y-%m-%d")
15
+ # end
16
+
17
+
18
+ # def b_name(item)
19
+ # item.business ? item.business.name : ''
20
+ # end
21
+
22
+ def staffs(item)
23
+ item.business ? item.business.staff.name : item.staffs_name
24
+ end
25
+
26
+ def manges(item)
27
+ item.business ? item.business.business_deliver_subjects.take.subject_manages : item.manges_name
28
+ end
29
+
30
+
31
+
32
+ end
33
+ end
@@ -18,6 +18,7 @@ module EducodeSales
18
18
  has_many :business_levels, dependent: :destroy
19
19
  has_many :business_watches, dependent: :destroy
20
20
  has_many :business_histories, dependent: :destroy
21
+ has_many :business_deliver_subjects, dependent: :destroy # 商机交付课程
21
22
  has_many :money_plans
22
23
 
23
24
  has_one :invoice_apply
@@ -35,6 +36,7 @@ module EducodeSales
35
36
  # 关联关注
36
37
  has_many :users, :class_name => 'EducodeSales::BusinessRelationShip', foreign_key: 'business_id', :dependent => :destroy
37
38
 
39
+ after_update :change_diliver
38
40
  # 每次查询时 默认的查询条件
39
41
  default_scope -> { where(deleted_at: nil) }
40
42
 
@@ -75,6 +77,26 @@ module EducodeSales
75
77
  '应收款' => ['已中标','已签单','已验收','回款中', '服务中','已结束']
76
78
  }[type]
77
79
  end
80
+
81
+
82
+ # 创建商机交付课程数据
83
+ def change_diliver
84
+
85
+ # if previous_changes["last_follow_up_id"].present?
86
+ # last_clazz_id = previous_changes["last_follow_up_id"][-1]
87
+ # common_type = FollowUp.find_by(id: last_clazz_id)&.stage&.name == "已中标"
88
+ # BusinessDeliverSubject.find_or_create_by(business_id: self.id) if common_type
89
+ # end
90
+ end
91
+
92
+ def school_name
93
+ department&.school&.name || "--"
94
+ end
95
+
96
+ def staff_name
97
+ last_follow_up&.assign_follow_ups.present? ? (last_follow_up.assign_follow_ups.map{ |d| d.staff.user.real_name}.join("、")) : staff&.user&.real_name
98
+ end
99
+
78
100
  end
79
101
 
80
102
  end