educode_sales 0.6.7 → 0.7.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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/educode_sales/businesses_controller.rb +185 -6
  3. data/app/controllers/educode_sales/customers_controller.rb +48 -15
  4. data/app/controllers/educode_sales/follow_ups_controller.rb +1 -1
  5. data/app/controllers/educode_sales/home_controller.rb +6 -0
  6. data/app/controllers/educode_sales/money_plans_controller.rb +3 -3
  7. data/app/controllers/educode_sales/operation_plans_controller.rb +4 -1
  8. data/app/controllers/educode_sales/plans_controller.rb +2 -1
  9. data/app/controllers/educode_sales/sale_trends_controller.rb +4 -2
  10. data/app/controllers/educode_sales/staffs_controller.rb +31 -0
  11. data/app/controllers/educode_sales/teachers_controller.rb +1 -1
  12. data/app/models/educode_sales/customer_add.rb +4 -0
  13. data/app/models/educode_sales/staff.rb +1 -0
  14. data/app/models/educode_sales/staff_school.rb +6 -0
  15. data/app/views/educode_sales/businesses/get_export_data.json.jbuilder +30 -0
  16. data/app/views/educode_sales/businesses/index.html.erb +103 -10
  17. data/app/views/educode_sales/businesses/index.json.jbuilder +9 -35
  18. data/app/views/educode_sales/businesses/show_follow.html.erb +44 -4
  19. data/app/views/educode_sales/businesses/show_follow.json.jbuilder +2 -0
  20. data/app/views/educode_sales/customers/index.html.erb +30 -1
  21. data/app/views/educode_sales/customers/index.json.jbuilder +12 -0
  22. data/app/views/educode_sales/customers/new.html.erb +106 -53
  23. data/app/views/educode_sales/home/staff_schools.json.jbuilder +9 -0
  24. data/app/views/educode_sales/roles/edit.html.erb +17 -11
  25. data/app/views/educode_sales/sale_trends/trends.html.erb +1 -1
  26. data/app/views/educode_sales/sales/index.json.jbuilder +1 -1
  27. data/app/views/educode_sales/staffs/edit.html.erb +46 -5
  28. data/app/views/educode_sales/staffs/index.html.erb +74 -2
  29. data/app/views/educode_sales/staffs/index.json.jbuilder +1 -0
  30. data/config/routes.rb +2 -0
  31. data/db/migrate/20210902064109_create_educode_sales_role_permissions.rb +5 -0
  32. data/db/migrate/20220121060006_create_educode_sales_business_export_records.rb +10 -0
  33. data/db/migrate/20220125013811_create_educode_sales_staff_schools.rb +10 -0
  34. data/db/migrate/20220125033552_create_educode_sales_customer_adds.rb +9 -0
  35. data/lib/educode_sales/version.rb +1 -1
  36. metadata +9 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6dbbb6a86049648541dc1d2fb1ec36eec9e24562bd17693725b1e3b498be3c0
4
- data.tar.gz: 7d4dffa34c61c38e66664d685244f4485d1cf7021c7115fb52903155efd3aac8
3
+ metadata.gz: fd1dede8ec609b98a19dcd71c21bac7b6024098a7cdb8bad5c600784bd9a649e
4
+ data.tar.gz: 34bdddc9c368c11588d2d9dc0a3307f8cfbc4568489f539e344b13f32bf41702
5
5
  SHA512:
6
- metadata.gz: dc84606ad701fb65520d5be1d79f59c83bad909b93fb3d6b4b61b7bc22e037c7b58a94bd9f13f9d8f9bfc6a37d891a168e04c23453fb5590fb4e479878025ed2
7
- data.tar.gz: fefca5856e9a3c84876b2dcff7fd9c7415ca1d935f141a367b4dcc3c6b549965febef90454afcfe6462b93fd716a38b21b1899947fe0292353c5dc9f7dfaaaf3
6
+ metadata.gz: 372e451790e777e0c9df20e7bdd9bc133e4d15351c6ae5b541c53a9761b14c2cbd5645c7517d0ae20ea4301872592fd43de82013ae90166546b5ae647b59db32
7
+ data.tar.gz: f9a5c5518474de3e1aa03e2fe1fae7bbede839df9649227e1c0c0ddba1f4aaaf62e3e903c813c3115dd7d792d56e48e9c6659226cf0ed4b29169ac1198dda8a4
@@ -31,7 +31,7 @@ module EducodeSales
31
31
  gon.menus << { title: '附件管理', event: 'file' }
32
32
  end
33
33
  if can?(:update, EducodeSales::Business)
34
- gon.menus << { title: '编辑', event: 'edit' }
34
+ # gon.menus << { title: '编辑', event: 'edit' }
35
35
  end
36
36
  if can?(:destroy, EducodeSales::Business)
37
37
  gon.menus << { title: '删除', event: 'delete' }
@@ -52,7 +52,7 @@ module EducodeSales
52
52
  business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
53
53
  @businesses = Business.where("educode_sales_businesses.staff_id = ? OR educode_sales_businesses.id in (?)", @current_admin.id, business_ids)
54
54
  when '区域'
55
- school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id)
55
+ school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id) + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
56
56
  business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
57
57
  @businesses = Business.joins("JOIN departments ON educode_sales_businesses.department_id = departments.id").where("departments.school_id in (?) OR educode_sales_businesses.staff_id = #{@current_admin.id} OR educode_sales_businesses.id in (?)", school_ids, business_ids)
58
58
  else
@@ -200,20 +200,20 @@ module EducodeSales
200
200
 
201
201
  @business_count = @businesses.count
202
202
 
203
- @businesses_exports = @businesses.select("
203
+ @businesses = @businesses.select("
204
204
  educode_sales_businesses.*,
205
205
  last_follow.invitation_at,
206
206
  last_follow.reception_at,
207
207
  last_follow.bidded_date,
208
208
  last_follow.signed_date,
209
+ last_follow.year,
209
210
  last_follow.created_at as latest_time,
210
211
  last_follow.actual_amount,
211
212
  (last_follow.actual_amount - educode_sales_businesses.return_money) as wait_return_money,
212
213
  last_follow.total_amount").joins("
213
214
  LEFT JOIN educode_sales_follow_ups AS last_follow ON educode_sales_businesses.last_follow_up_id = last_follow.id
214
- ")
215
+ ").page(params[:page]).per(params[:limit])
215
216
 
216
- @businesses = @businesses_exports.page(params[:page]).per(params[:limit])
217
217
  end
218
218
  end
219
219
  end
@@ -371,7 +371,7 @@ module EducodeSales
371
371
  render layout: false
372
372
  end
373
373
  format.json do
374
- @records = BusinessExportRecord.all.page(params[:page]).per(params[:limit])
374
+ @records = BusinessExportRecord.all.order(id: :desc).page(params[:page]).per(params[:limit])
375
375
  end
376
376
  end
377
377
  end
@@ -388,6 +388,185 @@ module EducodeSales
388
388
  end
389
389
  end
390
390
 
391
+ def get_export_data
392
+ respond_to do |format|
393
+ format.html do
394
+ end
395
+ format.json do
396
+ if @current_admin.is_admin?
397
+ @businesses = Business
398
+ else
399
+ level = @current_admin.role.role_areas.find_by(clazz: '商机管理').level
400
+ case level
401
+ when '自己'
402
+ business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
403
+ @businesses = Business.where("educode_sales_businesses.staff_id = ? OR educode_sales_businesses.id in (?)", @current_admin.id, business_ids)
404
+ when '区域'
405
+ school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id)
406
+ business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
407
+ @businesses = Business.joins("JOIN departments ON educode_sales_businesses.department_id = departments.id").where("departments.school_id in (?) OR educode_sales_businesses.staff_id = #{@current_admin.id} OR educode_sales_businesses.id in (?)", school_ids, business_ids)
408
+ else
409
+ @businesses = Business
410
+ end
411
+ end
412
+
413
+ if params[:name].present?
414
+ @year = params[:name].split("-")[1].present? ? params[:name].split("-")[1] : ''
415
+ end
416
+
417
+ if params[:name].present? && params[:name] == "(销售态势-" + @year + "-现有商机)"
418
+ ids = Common.where(extras: %w[a_class b_class c_class d_class e_class o_class]).pluck(:id)
419
+ if @year == '全部'
420
+ @businesses = @businesses.joins("
421
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
422
+ ").where("educode_sales_follow_ups.clazz_id in (?)",ids)
423
+ else
424
+ @businesses = @businesses.joins("
425
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
426
+ ").where("educode_sales_follow_ups.clazz_id in (?)",ids).where("educode_sales_follow_ups.year = ?",@year)
427
+ end
428
+
429
+ end
430
+
431
+ if params[:name].present? && params[:name] == "(销售态势-" + @year + "-已中标商机)"
432
+ stage_ids = Common.where(clazz: '商机阶段', name: ['已中标','已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
433
+ if @year == '全部'
434
+ @businesses = @businesses.joins("
435
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
436
+ ").where("educode_sales_follow_ups.stage_id IN (?)",stage_ids)
437
+ else
438
+ @businesses = @businesses.joins("
439
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
440
+ ").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)
441
+ end
442
+
443
+ end
444
+
445
+ if params[:name].present? && params[:name] == "(销售态势-" + @year + "-已签单商机)"
446
+ s_stage_ids = Common.where(clazz: '商机阶段', name: ['已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
447
+ if @year == '全部'
448
+ @businesses = @businesses.joins("
449
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
450
+ ").where("educode_sales_follow_ups.stage_id IN (?)",s_stage_ids)
451
+ else
452
+ @businesses = @businesses.joins("
453
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
454
+ ").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)
455
+ end
456
+ end
457
+
458
+ if params[:name].present? && params[:name] == "(销售态势-" + @year + "-已回款商机)"
459
+ x_id = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
460
+ year_time = "#{@year}-01-01 00:00:00"
461
+ year_over_time = "#{@year}-12-31 23:59:59"
462
+ if @year == '全部'
463
+ @businesses = @businesses.joins(follow_ups: :money_plans).where("educode_sales_follow_ups.clazz_id != ?", x_id).where.not("educode_sales_money_plans.clazz!= ?", 1).distinct
464
+ else
465
+ @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
466
+ end
467
+ end
468
+
469
+ if params[:all].present?
470
+ @businesses = @businesses
471
+ end
472
+
473
+ if params[:mine].present?
474
+ ids = AssignFollowUp.where(staff_id: @current_admin.id).pluck(:follow_up_id)
475
+ ids1 = FollowUp.where(id: ids).pluck(:business_id)
476
+ @businesses =@businesses.where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", ids1, @current_admin.id)
477
+ end
478
+
479
+ @businesses = @businesses
480
+ if params[:name].present? && params[:name] != "(销售态势-" + @year + "-已中标商机)" && params[:name] != "(销售态势-" + @year + "-已签单商机)" && params[:name] != "(销售态势-" + @year + "-已回款商机)" && params[:name] != "(销售态势-" + @year + "-现有商机)"
481
+ @businesses = @businesses.where("educode_sales_businesses.name like ?", "%#{params[:name]}%")
482
+ end
483
+ if params[:department].present?
484
+ departments_ids = Department.joins(:school).where("schools.name like ?", "%#{params[:department]}%").pluck(:id)
485
+ @businesses = @businesses.joins(:department).where("departments.id in (?)", departments_ids)
486
+ end
487
+ if params[:staff_id].present?
488
+ part_a_ids = @businesses.where("educode_sales_businesses.last_follow_up_id is null AND educode_sales_businesses.staff_id = ?",params[:staff_id]).ids
489
+ part_b_ids = @businesses.where("educode_sales_businesses.last_follow_up_id is not null").joins("
490
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
491
+ ").where("educode_sales_follow_ups.staff_id = ?", params[:staff_id]).ids
492
+ business_ids = part_a_ids + part_b_ids
493
+ @businesses = EducodeSales::Business.where(id:business_ids)
494
+ end
495
+ if params[:business_type].present?
496
+ @businesses = @businesses.joins("
497
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
498
+ ").where("educode_sales_follow_ups.clazz_id in (?)", params[:business_type].split(",").map(&:to_i))
499
+ end
500
+ if params[:business_step].present?
501
+ @businesses = @businesses.joins("
502
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
503
+ ").where("educode_sales_follow_ups.stage_id in (?)", params[:business_step].split(",").map(&:to_i))
504
+ end
505
+ if params[:place_id].present?
506
+ @businesses = @businesses.joins("
507
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
508
+ ").where("educode_sales_follow_ups.place_id = ?", params[:place_id])
509
+ end
510
+
511
+ if params[:area].present?
512
+ p = EducodeSales::Common.find(params[:area]).name
513
+ if @current_admin.is_admin?
514
+ @businesses = @businesses.joins("
515
+ JOIN departments ON educode_sales_businesses.department_id = departments.id
516
+ JOIN schools ON departments.school_id = schools.id
517
+ ").where("province = ?", p)
518
+ else
519
+ level = @current_admin.role.role_areas.find_by(clazz: '商机管理').level
520
+ if level == "区域"
521
+ @businesses = @businesses.joins("
522
+ JOIN schools ON departments.school_id = schools.id
523
+ ").where("province = ?", p)
524
+ else
525
+ @businesses = @businesses.joins("
526
+ JOIN departments ON educode_sales_businesses.department_id = departments.id
527
+ JOIN schools ON departments.school_id = schools.id
528
+ ").where("province = ?", p)
529
+ end
530
+ end
531
+ end
532
+
533
+ if params[:date].present?
534
+ date = params[:date].split(" - ")
535
+ @businesses = @businesses.where("educode_sales_businesses.created_at > ? AND educode_sales_businesses.created_at < ?", date[0], date[1] + '23:59:59')
536
+ end
537
+
538
+ if params[:invitation_at].present?
539
+ date = params[:invitation_at].split(" - ")
540
+ @businesses = @businesses.joins("
541
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
542
+ ").where("educode_sales_follow_ups.invitation_at > ? AND educode_sales_follow_ups.invitation_at < ?", date[0] + '00:00:00', date[1] + '23:59:59')
543
+ end
544
+
545
+ if params[:sort].present? && params[:sort][:field]
546
+ @businesses = @businesses.order("#{params[:sort][:field]} #{params[:sort][:order]}")
547
+ else
548
+ @businesses = @businesses.order("educode_sales_businesses.created_at desc")
549
+ end
550
+
551
+ @business_count = @businesses.count
552
+
553
+ @businesses = @businesses.select("
554
+ educode_sales_businesses.*,
555
+ last_follow.invitation_at,
556
+ last_follow.reception_at,
557
+ last_follow.bidded_date,
558
+ last_follow.signed_date,
559
+ last_follow.created_at as latest_time,
560
+ last_follow.actual_amount,
561
+ (last_follow.actual_amount - educode_sales_businesses.return_money) as wait_return_money,
562
+ last_follow.total_amount").joins("
563
+ LEFT JOIN educode_sales_follow_ups AS last_follow ON educode_sales_businesses.last_follow_up_id = last_follow.id
564
+ ")
565
+
566
+ end
567
+ end
568
+ end
569
+
391
570
  private
392
571
 
393
572
  def load_business
@@ -51,13 +51,16 @@ module EducodeSales
51
51
  when '区域'
52
52
  a_school_ids = School.where(province: @current_admin.areas.pluck(:name)).ids
53
53
  b_school_ids = CustomerExtension.where(customer_staff_id: @current_admin.id).pluck(:school_id)
54
- school_ids = a_school_ids + b_school_ids
54
+ school_ids = a_school_ids + b_school_ids + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
55
55
  @customers = School.where(id: school_ids)
56
56
  else
57
57
  @customers = School.all
58
58
  end
59
59
  end
60
-
60
+ part_a_ids = CustomerFollow.all.pluck(:school_id)
61
+ part_b_ids = Business.where(id: EducodeSales::FollowUp.pluck(:business_id)).pluck(:school_id)
62
+ ids = part_a_ids + part_b_ids + CustomerAdd.all.pluck(:school_id)
63
+ @customers = @customers.where(id: ids)
61
64
  if params[:q].present? && params[:q][:name].present?
62
65
  @customers = @customers.where("schools.name like ?", "%#{params[:q][:name]}%")
63
66
  end
@@ -68,6 +71,30 @@ module EducodeSales
68
71
  school_ids = EducodeSales::CustomerExtension.where(customer_staff_id: params[:q][:staff_id]).pluck(:school_id)
69
72
  @customers = @customers.where(id: school_ids)
70
73
  end
74
+ if params[:q].present? && params[:q][:property].present?
75
+ school_property_ids = []
76
+ property = params[:q][:property].split(",").map(&:to_i)
77
+ property.each do |p|
78
+ case p
79
+ when 0
80
+ school_property_ids += SchoolProperty.where( project_985: true ).ids
81
+ when 1
82
+ school_property_ids += SchoolProperty.where( project_211: true ).ids
83
+ when 2
84
+ school_property_ids += SchoolProperty.where( regular_college: true ).ids
85
+ when 3
86
+ school_property_ids += SchoolProperty.where( junior_college: true ).ids
87
+ when 4
88
+ school_property_ids += SchoolProperty.where( secondary_school: true ).ids
89
+ when 5
90
+ school_property_ids += SchoolProperty.where( military_school: true ).ids
91
+ when 6
92
+ school_property_ids += SchoolProperty.where( enterprise: true ).ids
93
+ else
94
+ end
95
+ end
96
+ @customers = @customers.where(school_property_id: school_property_ids)
97
+ end
71
98
 
72
99
  if params[:q].present? && params[:q][:date].present?
73
100
  ids = EducodeSales::CustomerFollow.all.pluck(:school_id)
@@ -149,20 +176,26 @@ module EducodeSales
149
176
  render layout: false
150
177
  end
151
178
 
179
+ # def create
180
+ # ActiveRecord::Base.transaction do
181
+ # property = SchoolProperty.find_or_create_by!(project_985: params[:project_985].present? ? 1 : 0,
182
+ # project_211: params[:project_211].present? ? 1 : 0,
183
+ # regular_college: params[:regular_college].present? ? 1 : 0,
184
+ # junior_college: params[:junior_college].present? ? 1 : 0,
185
+ # secondary_school: params[:secondary_school].present? ? 1 : 0,
186
+ # military_school: params[:military_school].present? ? 1 : 0,
187
+ # enterprise: params[:enterprise].present? ? 1 : 0)
188
+ # @school = School.new
189
+ # @school.attributes = school_params
190
+ # @school.school_property = property
191
+ # @school.save!
192
+ # EducodeSales::CustomerExtension.create(customer_staff_id: @current_admin.id, school_id: @school.id)
193
+ # end
194
+ # render_success
195
+ # end
152
196
  def create
153
- ActiveRecord::Base.transaction do
154
- property = SchoolProperty.find_or_create_by!(project_985: params[:project_985].present? ? 1 : 0,
155
- project_211: params[:project_211].present? ? 1 : 0,
156
- regular_college: params[:regular_college].present? ? 1 : 0,
157
- junior_college: params[:junior_college].present? ? 1 : 0,
158
- secondary_school: params[:secondary_school].present? ? 1 : 0,
159
- military_school: params[:military_school].present? ? 1 : 0,
160
- enterprise: params[:enterprise].present? ? 1 : 0)
161
- @school = School.new
162
- @school.attributes = school_params
163
- @school.school_property = property
164
- @school.save!
165
- EducodeSales::CustomerExtension.create(customer_staff_id: @current_admin.id, school_id: @school.id)
197
+ params[:school_ids].each do |d|
198
+ CustomerAdd.create(school_id: d)
166
199
  end
167
200
  render_success
168
201
  end
@@ -20,7 +20,7 @@ module EducodeSales
20
20
  business_ids = @businesses.pluck(:id)
21
21
  @follow_ups = FollowUp.where(business_id: business_ids)
22
22
  when '区域'
23
- school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id)
23
+ school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id) + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
24
24
  business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
25
25
  @businesses = Business.joins("JOIN departments ON educode_sales_businesses.department_id = departments.id").where("departments.school_id in (?) OR educode_sales_businesses.staff_id = #{@current_admin.id} OR educode_sales_businesses.id in (?)", school_ids, business_ids)
26
26
  business_ids = @businesses.pluck(:id)
@@ -57,6 +57,12 @@ module EducodeSales
57
57
  @staffs = @staffs.where(is_admin: false).where.not(id: @current_admin.id).where(job_type: common.id).page(params[:page]).per(10)
58
58
  end
59
59
  end
60
+ def staff_schools
61
+ @schools = School.all
62
+ if params[:q].present?
63
+ @schools = @schools.where("name like :q OR province like :q",q: "%#{params[:q]}%").page(params[:page]).per(10)
64
+ end
65
+ end
60
66
 
61
67
  def sales_place
62
68
  @places = EducodeSales::Place
@@ -21,11 +21,11 @@ module EducodeSales
21
21
  when '自己'
22
22
  @money_plans = MoneyPlan.joins(:follow_up).where("educode_sales_follow_ups.clazz_id != ?", x_id).where(follow_up_id: follow_up_ids).where(staff_id: @current_admin.id)
23
23
  when '区域'
24
- a_ids = MoneyPlan.where(follow_up_id: follow_up_ids).where(staff_id: @current_admin.id).ids
25
- school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id)
24
+ a_ids = MoneyPlan.where(follow_up_id: follow_up_ids).where(staff_id: @current_admin.id).pluck(:follow_up_id)
25
+ school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id) + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
26
26
  b_ids = Business.where(school_id: school_ids).pluck(:last_follow_up_id)
27
27
  ids = a_ids + b_ids
28
- @money_plans = MoneyPlan.joins(:follow_up).where("educode_sales_follow_ups.clazz_id != ?", x_id).where(id: ids)
28
+ @money_plans = MoneyPlan.joins(:follow_up).where("educode_sales_follow_ups.clazz_id != ?", x_id).where(follow_up_id: ids)
29
29
  else
30
30
  @money_plans = MoneyPlan.joins(:follow_up).where("educode_sales_follow_ups.clazz_id != ?", x_id).where(follow_up_id: follow_up_ids)
31
31
  end
@@ -21,7 +21,10 @@ module EducodeSales
21
21
  @sale_plans = OperationPlan.where(staff_id: @current_admin.id)
22
22
  when '区域'
23
23
  staff_ids = Staff.joins(user: [user_extension: [department: :school]]).where("schools.province in (?)", @current_admin.areas.pluck(:name)).pluck(:id)
24
- @sale_plans = OperationPlan.where("staff_id in (?) OR educode_sales_operation_plans.staff_id = ?", staff_ids, @current_admin.id)
24
+ school_ids = StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
25
+ department_ids = Department.where(school_id: school_ids).pluck(:id)
26
+ teacher_ids = Teacher.where(department_id: department_ids).pluck(:id)
27
+ @sale_plans = OperationPlan.where("staff_id in (?) OR educode_sales_operation_plans.staff_id = ? OR educode_sales_operation_plans.teacher_id in (?)", staff_ids, @current_admin.id,teacher_ids)
25
28
  else
26
29
  @sale_plans = OperationPlan
27
30
  end
@@ -22,7 +22,8 @@ module EducodeSales
22
22
  @sale_plans = SalePlan.where(staff_id: @current_admin.id)
23
23
  when '区域'
24
24
  staff_ids = Staff.joins(user: [user_extension: [department: :school]]).where("schools.province in (?)", @current_admin.areas.pluck(:name)).pluck(:id)
25
- @sale_plans = SalePlan.where("staff_id in (?) OR educode_sales_sale_plans.staff_id = ?", staff_ids, @current_admin.id)
25
+ business_ids = Business.where(school_id: StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)).pluck(:id)
26
+ @sale_plans = SalePlan.where("staff_id in (?) OR educode_sales_sale_plans.staff_id = ? OR educode_sales_sale_plans.business_id in (?)", staff_ids, @current_admin.id,business_ids)
26
27
  else
27
28
  @sale_plans = SalePlan
28
29
  end
@@ -162,10 +162,12 @@ module EducodeSales
162
162
  when 'diy'
163
163
  if params[:customer_date].present?
164
164
  date = params[:customer_date].split(" - ")
165
- begin_time = date[0]
166
- end_time = date[1]
165
+ begin_time = date[0] + "00:00:00"
166
+ end_time = date[1] + "23:59:59"
167
167
  end
168
168
  end
169
+ 100.times{p begin_time}
170
+ 100.times{p end_time}
169
171
  common = Common.find_by(clazz: 'staff_type', name: '销售')
170
172
  staff_names = Staff.joins(:user).where(job_type: common.id).map { |d| d.user.real_name}
171
173
  staff_ids = Staff.joins(:user).where(job_type: common.id).pluck(:id)
@@ -9,6 +9,25 @@ module EducodeSales
9
9
  end
10
10
  format.json do
11
11
  @staffs = Staff.where(is_admin: false, deleted_at: nil).page(params[:page]).per(params[:limit])
12
+ if params[:q].present? && params[:q][:name].present?
13
+ @staffs = @staffs.joins(:user).where('CONCAT(lastname, firstname) LIKE :name', name: "%#{params[:q][:name]}%")
14
+ end
15
+ if params[:q].present? && params[:q][:role].present?
16
+ @staffs = @staffs.where(role: params[:q][:role])
17
+ end
18
+ if params[:q].present? && params[:q][:staff_id].present?
19
+ @staffs = @staffs.where(staff_id: params[:q][:staff_id])
20
+ end
21
+ if params[:q].present? && params[:q][:staff_type].present?
22
+ @staffs = @staffs.where(job_type: params[:q][:staff_type])
23
+ end
24
+ if params[:q].present? && params[:q][:banned].present?
25
+ if params[:q][:banned] == "0"
26
+ @staffs = @staffs.where("educode_sales_staffs.expired_at is null or educode_sales_staffs.expired_at > ?", Time.now)
27
+ else
28
+ @staffs = @staffs.where("educode_sales_staffs.expired_at is null or educode_sales_staffs.expired_at < ?", Time.now)
29
+ end
30
+ end
12
31
  end
13
32
  end
14
33
  end
@@ -27,6 +46,10 @@ module EducodeSales
27
46
  @staff = Staff.find(params[:id])
28
47
  gon.area_ids = @staff.area_ids
29
48
  gon.areas = Common.where(clazz: 'area').map { |d| { value: d.id, title: d.name } } #.unshift({value: -1, title: '全国'})
49
+ gon.school_ids = @staff.staff_schools.ids
50
+ gon.schools = @staff.staff_schools.pluck(:school_id).map { |d| { value: d, name: "#{School.find(d)&.name}-#{School.find(d)&.province}" } } #.unshift({value: -1, title: '全国'})
51
+ # gon.school_ids = School.all.ids
52
+ # gon.schools = School.all.first(100).map { |d| { value: d.id, title: d.name } } #.unshift({value: -1, title: '全国'})
30
53
  @staff_types = Common.where(clazz: 'staff_type').pluck(:name, :id)
31
54
  render layout: false
32
55
  end
@@ -58,6 +81,14 @@ module EducodeSales
58
81
  commons << Common.find(d)
59
82
  end
60
83
  staff.areas = commons
84
+ if params[:school_ids].present?
85
+ staff.staff_schools.destroy_all
86
+ params[:school_ids].each do |d|
87
+ staff.staff_schools.create(school_id: d)
88
+ end
89
+ else
90
+ staff.staff_schools.destroy_all
91
+ end
61
92
  if staff.save
62
93
  render_success
63
94
  else
@@ -48,7 +48,7 @@ module EducodeSales
48
48
  teacher_ids = EducodeSales::Teacher.where(staff_id: 0).pluck(:id) - EducodeSales::TeacherAssignFollow.all.pluck(:Teacher_id) + EducodeSales::TeacherAssignFollow.where(staff_id: @current_admin.id).pluck(:teacher_id) + @teachers.ids
49
49
  @teachers = Teacher.where(id: teacher_ids)
50
50
  when '区域'
51
- school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id)
51
+ school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id) + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
52
52
  @teachers = Teacher.joins("JOIN departments ON educode_sales_teachers.department_id = departments.id").where(is_key: false).where("departments.school_id in (?) OR educode_sales_teachers.staff_id = #{@current_admin.id}", school_ids)
53
53
  teacher_ids = EducodeSales::Teacher.where(staff_id: 0).pluck(:id) - EducodeSales::TeacherAssignFollow.all.pluck(:Teacher_id) + EducodeSales::TeacherAssignFollow.where(staff_id: @current_admin.id).pluck(:teacher_id) + @teachers.ids
54
54
  @teachers = Teacher.where(id: teacher_ids)
@@ -0,0 +1,4 @@
1
+ module EducodeSales
2
+ class CustomerAdd < ApplicationRecord
3
+ end
4
+ end
@@ -14,6 +14,7 @@ module EducodeSales
14
14
  has_many :businesses, dependent: :destroy
15
15
  has_many :activities, dependent: :destroy
16
16
  has_many :sale_plans, dependent: :destroy
17
+ has_many :staff_schools, dependent: :destroy
17
18
 
18
19
  has_many :areas, through: :market_areas
19
20
  validates :user_id, uniqueness: { message: '已存在' }
@@ -0,0 +1,6 @@
1
+ module EducodeSales
2
+ class StaffSchool < ApplicationRecord
3
+ belongs_to :school
4
+ belongs_to :staff
5
+ end
6
+ end
@@ -0,0 +1,30 @@
1
+ json.data do
2
+ json.array! @businesses do |d|
3
+ json.id d.id
4
+ json.name d.name
5
+ json.department d.department.name
6
+ json.school d.department.school.name
7
+ json.school_id d.department.school.id
8
+ follow_ups_count = d.follow_ups.where(deleted_at: nil).size
9
+ json.follow_ups_count follow_ups_count
10
+ json.follow_up_id d.last_follow_up_id
11
+ json.clazz d.last_follow_up&.clazz&.name || ""
12
+ json.stage d.last_follow_up&.stage&.name
13
+ json.invitation_at d.last_follow_up&.invitation_at.to_s
14
+ json.reception_at d.last_follow_up&.reception_at.to_s
15
+ json.bidded_date d.last_follow_up&.bidded_date.to_s
16
+ json.signed_date d.last_follow_up&.signed_date.to_s
17
+ json.total_amount d.last_follow_up&.total_amount
18
+ json.actual_amount d.last_follow_up&.actual_amount
19
+ json.return_money d.return_money
20
+ json.wait_return_money d.wait_return_money.to_i.round(2)
21
+ json.return_money_days d.last_follow_up&.reception_at.present? && d.last_follow_up.money_plans.where(clazz: '已完成').present? ? (d.last_follow_up.money_plans.where(clazz: '已完成').order(created_at: :asc).first.date_at.to_s(:date).to_date - d.last_follow_up&.reception_at).to_i : ''
22
+ json.place d.last_follow_up&.place&.name
23
+ json.last_follow_person d.last_follow_up.present? ? d.last_follow_up.staff.user.real_name : EducodeSales::Staff.find(d.staff_id).user.real_name
24
+ json.source d.source
25
+ json.assign_follow_ups d.last_follow_up.present? ? d.last_follow_up.assign_follow_ups.pluck(:staff_id) : []
26
+ json.current_staff_id @current_admin.id
27
+ json.staff_id d.staff_id
28
+ json.latest_time d.last_follow_up.present? ? d.last_follow_up.created_at.to_s : ''
29
+ end
30
+ end