educode_sales 0.6.8 → 0.7.2

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 (56) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/educode_sales/businesses_controller.rb +191 -7
  3. data/app/controllers/educode_sales/customers_controller.rb +48 -15
  4. data/app/controllers/educode_sales/follow_ups_controller.rb +2 -2
  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 +118 -116
  10. data/app/controllers/educode_sales/staffs_controller.rb +12 -0
  11. data/app/controllers/educode_sales/teachers_controller.rb +1 -1
  12. data/app/helpers/educode_sales/follow_up_helper.rb +7 -0
  13. data/app/models/educode_sales/customer_add.rb +4 -0
  14. data/app/models/educode_sales/money_plan.rb +3 -3
  15. data/app/models/educode_sales/staff.rb +1 -0
  16. data/app/models/educode_sales/staff_school.rb +6 -0
  17. data/app/views/educode_sales/businesses/edit_plan.html.erb +4 -4
  18. data/app/views/educode_sales/businesses/export_records.json.jbuilder +1 -2
  19. data/app/views/educode_sales/businesses/get_export_data.json.jbuilder +30 -0
  20. data/app/views/educode_sales/businesses/index.html.erb +209 -100
  21. data/app/views/educode_sales/businesses/index.json.jbuilder +6 -32
  22. data/app/views/educode_sales/businesses/show_follow.html.erb +49 -8
  23. data/app/views/educode_sales/businesses/show_follow.json.jbuilder +2 -0
  24. data/app/views/educode_sales/customers/index.html.erb +30 -1
  25. data/app/views/educode_sales/customers/index.json.jbuilder +12 -0
  26. data/app/views/educode_sales/customers/new.html.erb +106 -53
  27. data/app/views/educode_sales/customers/show_follow.html.erb +1 -1
  28. data/app/views/educode_sales/follow_ups/index.json.jbuilder +1 -1
  29. data/app/views/educode_sales/follow_ups/money_plans.json.jbuilder +2 -4
  30. data/app/views/educode_sales/home/staff_schools.json.jbuilder +9 -0
  31. data/app/views/educode_sales/money_plans/index.html.erb +1 -1
  32. data/app/views/educode_sales/operation_plans/_monthPlan.html.erb +8 -3
  33. data/app/views/educode_sales/operation_plans/_monthly.html.erb +2 -2
  34. data/app/views/educode_sales/operation_plans/_weekPlan.html.erb +2 -2
  35. data/app/views/educode_sales/operation_plans/_weekly.html.erb +2 -2
  36. data/app/views/educode_sales/plans/_monthPlan.html.erb +8 -3
  37. data/app/views/educode_sales/plans/_monthly.html.erb +2 -2
  38. data/app/views/educode_sales/plans/_weekPlan.html.erb +2 -2
  39. data/app/views/educode_sales/plans/_weekly.html.erb +2 -2
  40. data/app/views/educode_sales/roles/edit.html.erb +17 -11
  41. data/app/views/educode_sales/sale_reports/audit.html.erb +2 -0
  42. data/app/views/educode_sales/sale_reports/edit.html.erb +2 -0
  43. data/app/views/educode_sales/sale_reports/show.html.erb +2 -0
  44. data/app/views/educode_sales/sale_trends/trends.html.erb +1 -1
  45. data/app/views/educode_sales/sales/index.html.erb +7 -7
  46. data/app/views/educode_sales/sales/index.json.jbuilder +1 -1
  47. data/app/views/educode_sales/staffs/edit.html.erb +46 -5
  48. data/app/views/educode_sales/staffs/index.html.erb +6 -0
  49. data/app/views/educode_sales/staffs/index.json.jbuilder +1 -0
  50. data/app/views/educode_sales/teachers/show_follow.html.erb +1 -1
  51. data/config/routes.rb +2 -0
  52. data/db/migrate/20210902064109_create_educode_sales_role_permissions.rb +5 -0
  53. data/db/migrate/20220125013811_create_educode_sales_staff_schools.rb +10 -0
  54. data/db/migrate/20220125033552_create_educode_sales_customer_adds.rb +9 -0
  55. data/lib/educode_sales/version.rb +1 -1
  56. metadata +9 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41b7c2e662fd724e27b8a995fe3f8fe5733384fe5454ffff038a22fe7526b6ad
4
- data.tar.gz: '09abc1d2d95817c2fc4e1dbc73beb1a31beb24239e2401b25c41125bf7864130'
3
+ metadata.gz: 745a9b47b47d917186df80e64b85698ecb980c6348773520b8dc03ca0b2cd985
4
+ data.tar.gz: c2e13cdd710e59bc828a7af7c28f944a65a11bc4419225c89fbbb20fb830e13a
5
5
  SHA512:
6
- metadata.gz: 7305c066cefb80249560e179eee5f84caedde9e223cb45311ebca66462251be8280cfb5c577da14d3c946ed485fadcca6342160e571203f0d25ccb987fca0f7b
7
- data.tar.gz: 3896cf2a1252a590053116ceac804abbc6cdae787b8f055a4258cfc388b8832aea623d561e5fe3ae4ce76e22347aa606f3e0f40e138c4747d535b5d75e2070c3
6
+ metadata.gz: 7b530302422fffd437080d469f59851436f3d3667e52c05da0804c5ccf9ab13038563809918a94d5842622ac478beaf4c4c7e77842ced01e8eb43bcd486eadf3
7
+ data.tar.gz: f2476d1ad5479026a211698f4e0f3c49f9e060da98bbf319c99a25181457e158fc8df186ac00b0221e310a67142f2cacf06b9fd55cb1e9ee207590501e50bb43
@@ -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
@@ -152,11 +152,16 @@ module EducodeSales
152
152
  JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
153
153
  ").where("educode_sales_follow_ups.stage_id in (?)", params[:q][:business_step].split(",").map(&:to_i))
154
154
  end
155
- if params[:q].present? && params[:q][:place_id].present?
155
+ if params[:q].present? && params[:q][:place_id].present?
156
156
  @businesses = @businesses.joins("
157
157
  JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
158
158
  ").where("educode_sales_follow_ups.place_id = ?", params[:q][:place_id])
159
159
  end
160
+ if params[:q].present? && params[:q][:business_year].present?
161
+ @businesses = @businesses.joins("
162
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
163
+ ").where("educode_sales_follow_ups.year = ?", params[:q][:business_year])
164
+ end
160
165
 
161
166
  if params[:q].present? && params[:q][:area].present?
162
167
  p = EducodeSales::Common.find(params[:q][:area]).name
@@ -200,20 +205,20 @@ module EducodeSales
200
205
 
201
206
  @business_count = @businesses.count
202
207
 
203
- @businesses_exports = @businesses.select("
208
+ @businesses = @businesses.select("
204
209
  educode_sales_businesses.*,
205
210
  last_follow.invitation_at,
206
211
  last_follow.reception_at,
207
212
  last_follow.bidded_date,
208
213
  last_follow.signed_date,
214
+ last_follow.year,
209
215
  last_follow.created_at as latest_time,
210
216
  last_follow.actual_amount,
211
217
  (last_follow.actual_amount - educode_sales_businesses.return_money) as wait_return_money,
212
218
  last_follow.total_amount").joins("
213
219
  LEFT JOIN educode_sales_follow_ups AS last_follow ON educode_sales_businesses.last_follow_up_id = last_follow.id
214
- ")
220
+ ").page(params[:page]).per(params[:limit])
215
221
 
216
- @businesses = @businesses_exports.page(params[:page]).per(params[:limit])
217
222
  end
218
223
  end
219
224
  end
@@ -371,7 +376,7 @@ module EducodeSales
371
376
  render layout: false
372
377
  end
373
378
  format.json do
374
- @records = BusinessExportRecord.all.page(params[:page]).per(params[:limit])
379
+ @records = BusinessExportRecord.all.order(id: :desc).page(params[:page]).per(params[:limit])
375
380
  end
376
381
  end
377
382
  end
@@ -388,6 +393,185 @@ module EducodeSales
388
393
  end
389
394
  end
390
395
 
396
+ def get_export_data
397
+ respond_to do |format|
398
+ format.html do
399
+ end
400
+ format.json do
401
+ if @current_admin.is_admin?
402
+ @businesses = Business
403
+ else
404
+ level = @current_admin.role.role_areas.find_by(clazz: '商机管理').level
405
+ case level
406
+ when '自己'
407
+ business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
408
+ @businesses = Business.where("educode_sales_businesses.staff_id = ? OR educode_sales_businesses.id in (?)", @current_admin.id, business_ids)
409
+ when '区域'
410
+ school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id)
411
+ business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
412
+ @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)
413
+ else
414
+ @businesses = Business
415
+ end
416
+ end
417
+
418
+ if params[:name].present?
419
+ @year = params[:name].split("-")[1].present? ? params[:name].split("-")[1] : ''
420
+ end
421
+
422
+ if params[:name].present? && params[:name] == "(销售态势-" + @year + "-现有商机)"
423
+ ids = Common.where(extras: %w[a_class b_class c_class d_class e_class o_class]).pluck(:id)
424
+ if @year == '全部'
425
+ @businesses = @businesses.joins("
426
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
427
+ ").where("educode_sales_follow_ups.clazz_id in (?)",ids)
428
+ else
429
+ @businesses = @businesses.joins("
430
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
431
+ ").where("educode_sales_follow_ups.clazz_id in (?)",ids).where("educode_sales_follow_ups.year = ?",@year)
432
+ end
433
+
434
+ end
435
+
436
+ if params[:name].present? && params[:name] == "(销售态势-" + @year + "-已中标商机)"
437
+ stage_ids = Common.where(clazz: '商机阶段', name: ['已中标','已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
438
+ if @year == '全部'
439
+ @businesses = @businesses.joins("
440
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
441
+ ").where("educode_sales_follow_ups.stage_id IN (?)",stage_ids)
442
+ else
443
+ @businesses = @businesses.joins("
444
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
445
+ ").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)
446
+ end
447
+
448
+ end
449
+
450
+ if params[:name].present? && params[:name] == "(销售态势-" + @year + "-已签单商机)"
451
+ s_stage_ids = Common.where(clazz: '商机阶段', name: ['已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
452
+ if @year == '全部'
453
+ @businesses = @businesses.joins("
454
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
455
+ ").where("educode_sales_follow_ups.stage_id IN (?)",s_stage_ids)
456
+ else
457
+ @businesses = @businesses.joins("
458
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
459
+ ").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)
460
+ end
461
+ end
462
+
463
+ if params[:name].present? && params[:name] == "(销售态势-" + @year + "-已回款商机)"
464
+ x_id = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
465
+ year_time = "#{@year}-01-01 00:00:00"
466
+ year_over_time = "#{@year}-12-31 23:59:59"
467
+ if @year == '全部'
468
+ @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
469
+ else
470
+ @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
471
+ end
472
+ end
473
+
474
+ if params[:all].present?
475
+ @businesses = @businesses
476
+ end
477
+
478
+ if params[:mine].present?
479
+ ids = AssignFollowUp.where(staff_id: @current_admin.id).pluck(:follow_up_id)
480
+ ids1 = FollowUp.where(id: ids).pluck(:business_id)
481
+ @businesses =@businesses.where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", ids1, @current_admin.id)
482
+ end
483
+
484
+ @businesses = @businesses
485
+ if params[:name].present? && params[:name] != "(销售态势-" + @year + "-已中标商机)" && params[:name] != "(销售态势-" + @year + "-已签单商机)" && params[:name] != "(销售态势-" + @year + "-已回款商机)" && params[:name] != "(销售态势-" + @year + "-现有商机)"
486
+ @businesses = @businesses.where("educode_sales_businesses.name like ?", "%#{params[:name]}%")
487
+ end
488
+ if params[:department].present?
489
+ departments_ids = Department.joins(:school).where("schools.name like ?", "%#{params[:department]}%").pluck(:id)
490
+ @businesses = @businesses.joins(:department).where("departments.id in (?)", departments_ids)
491
+ end
492
+ if params[:staff_id].present?
493
+ part_a_ids = @businesses.where("educode_sales_businesses.last_follow_up_id is null AND educode_sales_businesses.staff_id = ?",params[:staff_id]).ids
494
+ part_b_ids = @businesses.where("educode_sales_businesses.last_follow_up_id is not null").joins("
495
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
496
+ ").where("educode_sales_follow_ups.staff_id = ?", params[:staff_id]).ids
497
+ business_ids = part_a_ids + part_b_ids
498
+ @businesses = EducodeSales::Business.where(id:business_ids)
499
+ end
500
+ if params[:business_type].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.clazz_id in (?)", params[:business_type].split(",").map(&:to_i))
504
+ end
505
+ if params[:business_step].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.stage_id in (?)", params[:business_step].split(",").map(&:to_i))
509
+ end
510
+ if params[:place_id].present?
511
+ @businesses = @businesses.joins("
512
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
513
+ ").where("educode_sales_follow_ups.place_id = ?", params[:place_id])
514
+ end
515
+
516
+ if params[:area].present?
517
+ p = EducodeSales::Common.find(params[:area]).name
518
+ if @current_admin.is_admin?
519
+ @businesses = @businesses.joins("
520
+ JOIN departments ON educode_sales_businesses.department_id = departments.id
521
+ JOIN schools ON departments.school_id = schools.id
522
+ ").where("province = ?", p)
523
+ else
524
+ level = @current_admin.role.role_areas.find_by(clazz: '商机管理').level
525
+ if level == "区域"
526
+ @businesses = @businesses.joins("
527
+ JOIN schools ON departments.school_id = schools.id
528
+ ").where("province = ?", p)
529
+ else
530
+ @businesses = @businesses.joins("
531
+ JOIN departments ON educode_sales_businesses.department_id = departments.id
532
+ JOIN schools ON departments.school_id = schools.id
533
+ ").where("province = ?", p)
534
+ end
535
+ end
536
+ end
537
+
538
+ if params[:date].present?
539
+ date = params[:date].split(" - ")
540
+ @businesses = @businesses.where("educode_sales_businesses.created_at > ? AND educode_sales_businesses.created_at < ?", date[0], date[1] + '23:59:59')
541
+ end
542
+
543
+ if params[:invitation_at].present?
544
+ date = params[:invitation_at].split(" - ")
545
+ @businesses = @businesses.joins("
546
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
547
+ ").where("educode_sales_follow_ups.invitation_at > ? AND educode_sales_follow_ups.invitation_at < ?", date[0] + '00:00:00', date[1] + '23:59:59')
548
+ end
549
+
550
+ if params[:sort].present? && params[:sort][:field]
551
+ @businesses = @businesses.order("#{params[:sort][:field]} #{params[:sort][:order]}")
552
+ else
553
+ @businesses = @businesses.order("educode_sales_businesses.created_at desc")
554
+ end
555
+
556
+ @business_count = @businesses.count
557
+
558
+ @businesses = @businesses.select("
559
+ educode_sales_businesses.*,
560
+ last_follow.invitation_at,
561
+ last_follow.reception_at,
562
+ last_follow.bidded_date,
563
+ last_follow.signed_date,
564
+ last_follow.created_at as latest_time,
565
+ last_follow.actual_amount,
566
+ (last_follow.actual_amount - educode_sales_businesses.return_money) as wait_return_money,
567
+ last_follow.total_amount").joins("
568
+ LEFT JOIN educode_sales_follow_ups AS last_follow ON educode_sales_businesses.last_follow_up_id = last_follow.id
569
+ ")
570
+
571
+ end
572
+ end
573
+ end
574
+
391
575
  private
392
576
 
393
577
  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)
@@ -95,7 +95,7 @@ module EducodeSales
95
95
  business = follow_up.business
96
96
  if follow_up.soft_destroy(@current_admin.id)
97
97
  if follow_up.id == business.last_follow_up_id
98
- business.update(last_follow_up: business.follow_ups.last, return_money: MoneyPlan.where(clazz: '已完成', follow_up_id: business.follow_ups.last&.id).sum(:amount))
98
+ business.update(last_follow_up: business.follow_ups.last, return_money: MoneyPlan.where(clazz: '实际回款', follow_up_id: business.follow_ups.last&.id).sum(:amount))
99
99
  end
100
100
  render_success
101
101
  else
@@ -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