educode_sales 0.6.6 → 0.7.0
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.
- checksums.yaml +4 -4
- data/app/controllers/educode_sales/activities_controller.rb +0 -2
- data/app/controllers/educode_sales/businesses_controller.rb +259 -43
- data/app/controllers/educode_sales/customers_controller.rb +48 -15
- data/app/controllers/educode_sales/home_controller.rb +6 -0
- data/app/controllers/educode_sales/money_plans_controller.rb +3 -3
- data/app/controllers/educode_sales/operation_plans_controller.rb +1 -1
- data/app/controllers/educode_sales/plans_controller.rb +1 -1
- data/app/controllers/educode_sales/sale_trends_controller.rb +107 -18
- data/app/controllers/educode_sales/staffs_controller.rb +29 -0
- data/app/controllers/educode_sales/teacher_follows_controller.rb +1 -93
- data/app/controllers/educode_sales/teachers_controller.rb +1 -1
- data/app/models/educode_sales/business_export_record.rb +5 -0
- data/app/models/educode_sales/customer_add.rb +4 -0
- data/app/models/educode_sales/staff.rb +1 -0
- data/app/models/educode_sales/staff_school.rb +6 -0
- data/app/views/educode_sales/activities/index.html.erb +7 -1
- data/app/views/educode_sales/activities/new.html.erb +1 -1
- data/app/views/educode_sales/businesses/edit_follow_record.html.erb +4 -4
- data/app/views/educode_sales/businesses/edit_plan.html.erb +5 -2
- data/app/views/educode_sales/businesses/export_records.html.erb +53 -0
- data/app/views/educode_sales/businesses/export_records.json.jbuilder +11 -0
- data/app/views/educode_sales/businesses/get_export_data.json.jbuilder +30 -0
- data/app/views/educode_sales/businesses/index.html.erb +161 -8
- data/app/views/educode_sales/businesses/index.json.jbuilder +10 -7
- data/app/views/educode_sales/businesses/new_follow_record.html.erb +6 -5
- data/app/views/educode_sales/businesses/show_follow.html.erb +37 -3
- data/app/views/educode_sales/businesses/show_follow.json.jbuilder +1 -0
- data/app/views/educode_sales/commons/index.html.erb +7 -1
- data/app/views/educode_sales/customers/index.html.erb +31 -1
- data/app/views/educode_sales/customers/index.json.jbuilder +12 -0
- data/app/views/educode_sales/customers/new.html.erb +106 -53
- data/app/views/educode_sales/home/staff_schools.json.jbuilder +9 -0
- data/app/views/educode_sales/money_plans/index.html.erb +2 -2
- data/app/views/educode_sales/roles/edit.html.erb +16 -10
- data/app/views/educode_sales/roles/index.html.erb +7 -1
- data/app/views/educode_sales/sale_trends/trends.html.erb +96 -44
- data/app/views/educode_sales/sale_trends/trends.json.jbuilder +2 -1
- data/app/views/educode_sales/sales/index.json.jbuilder +1 -1
- data/app/views/educode_sales/staffs/edit.html.erb +46 -5
- data/app/views/educode_sales/staffs/index.html.erb +74 -2
- data/app/views/educode_sales/staffs/index.json.jbuilder +1 -0
- data/app/views/educode_sales/teachers/index.html.erb +1 -1
- data/app/views/layouts/educode_sales/application.html.erb +1 -1
- data/config/routes.rb +4 -0
- data/db/migrate/20210902064109_create_educode_sales_role_permissions.rb +7 -0
- data/db/migrate/20220121060006_create_educode_sales_business_export_records.rb +10 -0
- data/db/migrate/20220125013811_create_educode_sales_staff_schools.rb +10 -0
- data/db/migrate/20220125033552_create_educode_sales_customer_adds.rb +9 -0
- data/lib/educode_sales/version.rb +1 -1
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c243136aa29c06071bc7f5178e7c6eab7a7711c29a664ed12b4141b823102e1
|
4
|
+
data.tar.gz: db224456ae6c27346fadb5ae65b2ed6973ba11e1c384f2b833f994e6371540cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5df7256338dc4a0bcc7f3ef6933c573f79b186a77ba12fcb10bcbfc80a11cfb3253d57ae2ea2325346a76c089fe9c9a71751407697bb4e3706ee6b58e11abf1
|
7
|
+
data.tar.gz: fa152803f2738331a1324e530275b6c31ff0420f5f725c537587b754555ae6eaeb0ce4bf5e522ef81ae109224e74b65effdf4435e7cb71e88fd11d6409c42580
|
@@ -3,29 +3,6 @@ require_dependency "educode_sales/application_controller"
|
|
3
3
|
module EducodeSales
|
4
4
|
class BusinessesController < ApplicationController
|
5
5
|
|
6
|
-
def file
|
7
|
-
gon.folder = edu_setting('attachment_folder') + '/'
|
8
|
-
render layout: false
|
9
|
-
end
|
10
|
-
def upload_file
|
11
|
-
render layout: false
|
12
|
-
end
|
13
|
-
def time_line
|
14
|
-
@business = Business.find(params[:business_id])
|
15
|
-
respond_to do |format|
|
16
|
-
format.html do
|
17
|
-
@follow_ups = @business.follow_ups.order(created_at: :desc)
|
18
|
-
# @latest = @follow_ups.order(created_at: :desc).first
|
19
|
-
# if params[:field]
|
20
|
-
# @follow_ups = @follow_ups.order("#{params[:field]} #{params[:order]}")
|
21
|
-
# else
|
22
|
-
# @follow_ups = @follow_ups.order("created_at desc")
|
23
|
-
# end
|
24
|
-
# @follow_ups = @follow_ups.page(params[:page]).per(params[:limit])
|
25
|
-
render layout: false
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
6
|
|
30
7
|
def index
|
31
8
|
authorize! :read, Business
|
@@ -36,6 +13,7 @@ module EducodeSales
|
|
36
13
|
# @more = can?(:create, EducodeSales::SalePlan) || can?(:update, EducodeSales::Business) || can?(:destroy, EducodeSales::Business) || can?(:show_file, EducodeSales::Business)
|
37
14
|
@more = true
|
38
15
|
gon.menus = []
|
16
|
+
gon.export_menus = []
|
39
17
|
gon.place = params[:place_id].present? ? [{ value: params[:place_id], name: EducodeSales::Place.find(params[:place_id]).name }] : []
|
40
18
|
gon.business_type = Common.where(clazz: 'business_type').map do |d|
|
41
19
|
{value: d.id, name: d.name}
|
@@ -53,11 +31,16 @@ module EducodeSales
|
|
53
31
|
gon.menus << { title: '附件管理', event: 'file' }
|
54
32
|
end
|
55
33
|
if can?(:update, EducodeSales::Business)
|
56
|
-
gon.menus << { title: '编辑', event: 'edit' }
|
34
|
+
# gon.menus << { title: '编辑', event: 'edit' }
|
57
35
|
end
|
58
36
|
if can?(:destroy, EducodeSales::Business)
|
59
37
|
gon.menus << { title: '删除', event: 'delete' }
|
60
38
|
end
|
39
|
+
if can?(:export_business, EducodeSales::Business)
|
40
|
+
gon.export_menus << { title: '导出到Csv文件', event: 'export_csv' }
|
41
|
+
gon.export_menus << { title: '导出到Excel文件', event: 'export_excel' }
|
42
|
+
end
|
43
|
+
gon.export_menus << { title: '导出记录', event: 'export_records' }
|
61
44
|
end
|
62
45
|
format.json do
|
63
46
|
if @current_admin.is_admin?
|
@@ -69,7 +52,7 @@ module EducodeSales
|
|
69
52
|
business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
|
70
53
|
@businesses = Business.where("educode_sales_businesses.staff_id = ? OR educode_sales_businesses.id in (?)", @current_admin.id, business_ids)
|
71
54
|
when '区域'
|
72
|
-
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)
|
73
56
|
business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
|
74
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)
|
75
58
|
else
|
@@ -81,41 +64,56 @@ module EducodeSales
|
|
81
64
|
@year = params[:q][:name].split("-")[1].present? ? params[:q][:name].split("-")[1] : ''
|
82
65
|
end
|
83
66
|
|
84
|
-
if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
d_id = Common.find_by(extras: EducodeSales::Common::DTYPE)&.id
|
89
|
-
e_id = Common.find_by(extras: EducodeSales::Common::ETYPE)&.id
|
90
|
-
o_id = Common.find_by(extras: EducodeSales::Common::OTYPE)&.id
|
91
|
-
ids = [a_id ,b_id ,c_id ,d_id ,e_id ,o_id]
|
92
|
-
@businesses = @businesses.joins("
|
67
|
+
if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-" + @year + "-现有商机)"
|
68
|
+
ids = Common.where(extras: %w[a_class b_class c_class d_class e_class o_class]).pluck(:id)
|
69
|
+
if @year == '全部'
|
70
|
+
@businesses = @businesses.joins("
|
93
71
|
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
94
72
|
").where("educode_sales_follow_ups.clazz_id in (?)",ids)
|
73
|
+
else
|
74
|
+
@businesses = @businesses.joins("
|
75
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
76
|
+
").where("educode_sales_follow_ups.clazz_id in (?)",ids).where("educode_sales_follow_ups.year = ?",@year)
|
77
|
+
end
|
78
|
+
|
95
79
|
end
|
96
80
|
|
97
81
|
if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-" + @year + "-已中标商机)"
|
98
82
|
stage_ids = Common.where(clazz: '商机阶段', name: ['已中标','已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
|
99
|
-
@
|
83
|
+
if @year == '全部'
|
84
|
+
@businesses = @businesses.joins("
|
85
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
86
|
+
").where("educode_sales_follow_ups.stage_id IN (?)",stage_ids)
|
87
|
+
else
|
88
|
+
@businesses = @businesses.joins("
|
100
89
|
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
101
90
|
").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)
|
91
|
+
end
|
92
|
+
|
102
93
|
end
|
103
94
|
|
104
95
|
if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-" + @year + "-已签单商机)"
|
105
96
|
s_stage_ids = Common.where(clazz: '商机阶段', name: ['已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
|
106
|
-
@
|
97
|
+
if @year == '全部'
|
98
|
+
@businesses = @businesses.joins("
|
99
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
100
|
+
").where("educode_sales_follow_ups.stage_id IN (?)",s_stage_ids)
|
101
|
+
else
|
102
|
+
@businesses = @businesses.joins("
|
107
103
|
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
108
104
|
").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)
|
105
|
+
end
|
109
106
|
end
|
110
107
|
|
111
108
|
if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-" + @year + "-已回款商机)"
|
112
109
|
x_id = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
|
113
|
-
# @businesses = @businesses.where("educode_sales_businesses.created_at > ? AND educode_sales_businesses.created_at < ? AND educode_sales_businesses.return_money > 0", "#{@year}-01-01", "#{@year}-12-31").joins("
|
114
|
-
# JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
115
|
-
# ").where.not("educode_sales_follow_ups.clazz_id = ?",x_id)
|
116
110
|
year_time = "#{@year}-01-01 00:00:00"
|
117
111
|
year_over_time = "#{@year}-12-31 23:59:59"
|
118
|
-
|
112
|
+
if @year == '全部'
|
113
|
+
@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
|
114
|
+
else
|
115
|
+
@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
|
116
|
+
end
|
119
117
|
end
|
120
118
|
|
121
119
|
if params[:q].present? && params[:q][:all].present?
|
@@ -129,7 +127,7 @@ module EducodeSales
|
|
129
127
|
end
|
130
128
|
|
131
129
|
@businesses = @businesses
|
132
|
-
if params[:q].present? && params[:q][:name].present? && params[:q][:name] != "(销售态势-" + @year + "-已中标商机)" && params[:q][:name] != "(销售态势-" + @year + "-已签单商机)" && params[:q][:name] != "(销售态势-" + @year + "-已回款商机)" && params[:q][:name] != "(
|
130
|
+
if params[:q].present? && params[:q][:name].present? && params[:q][:name] != "(销售态势-" + @year + "-已中标商机)" && params[:q][:name] != "(销售态势-" + @year + "-已签单商机)" && params[:q][:name] != "(销售态势-" + @year + "-已回款商机)" && params[:q][:name] != "(销售态势-" + @year + "-现有商机)"
|
133
131
|
@businesses = @businesses.where("educode_sales_businesses.name like ?", "%#{params[:q][:name]}%")
|
134
132
|
end
|
135
133
|
if params[:q].present? && params[:q][:department].present?
|
@@ -202,8 +200,6 @@ module EducodeSales
|
|
202
200
|
|
203
201
|
@business_count = @businesses.count
|
204
202
|
|
205
|
-
|
206
|
-
|
207
203
|
@businesses = @businesses.select("
|
208
204
|
educode_sales_businesses.*,
|
209
205
|
last_follow.invitation_at,
|
@@ -216,6 +212,7 @@ module EducodeSales
|
|
216
212
|
last_follow.total_amount").joins("
|
217
213
|
LEFT JOIN educode_sales_follow_ups AS last_follow ON educode_sales_businesses.last_follow_up_id = last_follow.id
|
218
214
|
").page(params[:page]).per(params[:limit])
|
215
|
+
|
219
216
|
end
|
220
217
|
end
|
221
218
|
end
|
@@ -350,6 +347,225 @@ module EducodeSales
|
|
350
347
|
render layout: false
|
351
348
|
end
|
352
349
|
|
350
|
+
def file
|
351
|
+
gon.folder = edu_setting('attachment_folder') + '/'
|
352
|
+
render layout: false
|
353
|
+
end
|
354
|
+
def upload_file
|
355
|
+
render layout: false
|
356
|
+
end
|
357
|
+
def time_line
|
358
|
+
@business = Business.find(params[:business_id])
|
359
|
+
respond_to do |format|
|
360
|
+
format.html do
|
361
|
+
@follow_ups = @business.follow_ups.order(created_at: :desc)
|
362
|
+
render layout: false
|
363
|
+
end
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
def export_records
|
368
|
+
respond_to do |format|
|
369
|
+
format.html do
|
370
|
+
render layout: false
|
371
|
+
end
|
372
|
+
format.json do
|
373
|
+
@records = BusinessExportRecord.all.page(params[:page]).per(params[:limit])
|
374
|
+
end
|
375
|
+
end
|
376
|
+
end
|
377
|
+
def add_export_records
|
378
|
+
if params[:type] == 'csv'
|
379
|
+
record = BusinessExportRecord.new(name: '商机数据表.csv', staff_id: @current_admin.id)
|
380
|
+
else params[:type] == 'excel'
|
381
|
+
record = BusinessExportRecord.new(name: '商机数据表.xls', staff_id: @current_admin.id)
|
382
|
+
end
|
383
|
+
if record.save
|
384
|
+
render_success
|
385
|
+
else
|
386
|
+
render_failure business
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
390
|
+
def get_export_data
|
391
|
+
respond_to do |format|
|
392
|
+
format.html do
|
393
|
+
end
|
394
|
+
format.json do
|
395
|
+
if @current_admin.is_admin?
|
396
|
+
@businesses = Business
|
397
|
+
else
|
398
|
+
level = @current_admin.role.role_areas.find_by(clazz: '商机管理').level
|
399
|
+
case level
|
400
|
+
when '自己'
|
401
|
+
business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
|
402
|
+
@businesses = Business.where("educode_sales_businesses.staff_id = ? OR educode_sales_businesses.id in (?)", @current_admin.id, business_ids)
|
403
|
+
when '区域'
|
404
|
+
school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id)
|
405
|
+
business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
|
406
|
+
@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)
|
407
|
+
else
|
408
|
+
@businesses = Business
|
409
|
+
end
|
410
|
+
end
|
411
|
+
|
412
|
+
if params[:name].present?
|
413
|
+
@year = params[:name].split("-")[1].present? ? params[:name].split("-")[1] : ''
|
414
|
+
end
|
415
|
+
|
416
|
+
if params[:name].present? && params[:name] == "(销售态势-" + @year + "-现有商机)"
|
417
|
+
ids = Common.where(extras: %w[a_class b_class c_class d_class e_class o_class]).pluck(:id)
|
418
|
+
if @year == '全部'
|
419
|
+
@businesses = @businesses.joins("
|
420
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
421
|
+
").where("educode_sales_follow_ups.clazz_id in (?)",ids)
|
422
|
+
else
|
423
|
+
@businesses = @businesses.joins("
|
424
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
425
|
+
").where("educode_sales_follow_ups.clazz_id in (?)",ids).where("educode_sales_follow_ups.year = ?",@year)
|
426
|
+
end
|
427
|
+
|
428
|
+
end
|
429
|
+
|
430
|
+
if params[:name].present? && params[:name] == "(销售态势-" + @year + "-已中标商机)"
|
431
|
+
stage_ids = Common.where(clazz: '商机阶段', name: ['已中标','已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
|
432
|
+
if @year == '全部'
|
433
|
+
@businesses = @businesses.joins("
|
434
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
435
|
+
").where("educode_sales_follow_ups.stage_id IN (?)",stage_ids)
|
436
|
+
else
|
437
|
+
@businesses = @businesses.joins("
|
438
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
439
|
+
").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)
|
440
|
+
end
|
441
|
+
|
442
|
+
end
|
443
|
+
|
444
|
+
if params[:name].present? && params[:name] == "(销售态势-" + @year + "-已签单商机)"
|
445
|
+
s_stage_ids = Common.where(clazz: '商机阶段', name: ['已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
|
446
|
+
if @year == '全部'
|
447
|
+
@businesses = @businesses.joins("
|
448
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
449
|
+
").where("educode_sales_follow_ups.stage_id IN (?)",s_stage_ids)
|
450
|
+
else
|
451
|
+
@businesses = @businesses.joins("
|
452
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
453
|
+
").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)
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
if params[:name].present? && params[:name] == "(销售态势-" + @year + "-已回款商机)"
|
458
|
+
x_id = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
|
459
|
+
year_time = "#{@year}-01-01 00:00:00"
|
460
|
+
year_over_time = "#{@year}-12-31 23:59:59"
|
461
|
+
if @year == '全部'
|
462
|
+
@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
|
463
|
+
else
|
464
|
+
@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
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
if params[:all].present?
|
469
|
+
@businesses = @businesses
|
470
|
+
end
|
471
|
+
|
472
|
+
if params[:mine].present?
|
473
|
+
ids = AssignFollowUp.where(staff_id: @current_admin.id).pluck(:follow_up_id)
|
474
|
+
ids1 = FollowUp.where(id: ids).pluck(:business_id)
|
475
|
+
@businesses =@businesses.where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", ids1, @current_admin.id)
|
476
|
+
end
|
477
|
+
|
478
|
+
@businesses = @businesses
|
479
|
+
if params[:name].present? && params[:name] != "(销售态势-" + @year + "-已中标商机)" && params[:name] != "(销售态势-" + @year + "-已签单商机)" && params[:name] != "(销售态势-" + @year + "-已回款商机)" && params[:name] != "(销售态势-" + @year + "-现有商机)"
|
480
|
+
@businesses = @businesses.where("educode_sales_businesses.name like ?", "%#{params[:name]}%")
|
481
|
+
end
|
482
|
+
if params[:department].present?
|
483
|
+
departments_ids = Department.joins(:school).where("schools.name like ?", "%#{params[:department]}%").pluck(:id)
|
484
|
+
@businesses = @businesses.joins(:department).where("departments.id in (?)", departments_ids)
|
485
|
+
end
|
486
|
+
if params[:staff_id].present?
|
487
|
+
part_a_ids = @businesses.where("educode_sales_businesses.last_follow_up_id is null AND educode_sales_businesses.staff_id = ?",params[:staff_id]).ids
|
488
|
+
part_b_ids = @businesses.where("educode_sales_businesses.last_follow_up_id is not null").joins("
|
489
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
490
|
+
").where("educode_sales_follow_ups.staff_id = ?", params[:staff_id]).ids
|
491
|
+
business_ids = part_a_ids + part_b_ids
|
492
|
+
@businesses = EducodeSales::Business.where(id:business_ids)
|
493
|
+
end
|
494
|
+
if params[:business_type].present?
|
495
|
+
@businesses = @businesses.joins("
|
496
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
497
|
+
").where("educode_sales_follow_ups.clazz_id in (?)", params[:business_type].split(",").map(&:to_i))
|
498
|
+
end
|
499
|
+
if params[:business_step].present?
|
500
|
+
@businesses = @businesses.joins("
|
501
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
502
|
+
").where("educode_sales_follow_ups.stage_id in (?)", params[:business_step].split(",").map(&:to_i))
|
503
|
+
end
|
504
|
+
if params[:place_id].present?
|
505
|
+
@businesses = @businesses.joins("
|
506
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
507
|
+
").where("educode_sales_follow_ups.place_id = ?", params[:place_id])
|
508
|
+
end
|
509
|
+
|
510
|
+
if params[:area].present?
|
511
|
+
p = EducodeSales::Common.find(params[:area]).name
|
512
|
+
if @current_admin.is_admin?
|
513
|
+
@businesses = @businesses.joins("
|
514
|
+
JOIN departments ON educode_sales_businesses.department_id = departments.id
|
515
|
+
JOIN schools ON departments.school_id = schools.id
|
516
|
+
").where("province = ?", p)
|
517
|
+
else
|
518
|
+
level = @current_admin.role.role_areas.find_by(clazz: '商机管理').level
|
519
|
+
if level == "区域"
|
520
|
+
@businesses = @businesses.joins("
|
521
|
+
JOIN schools ON departments.school_id = schools.id
|
522
|
+
").where("province = ?", p)
|
523
|
+
else
|
524
|
+
@businesses = @businesses.joins("
|
525
|
+
JOIN departments ON educode_sales_businesses.department_id = departments.id
|
526
|
+
JOIN schools ON departments.school_id = schools.id
|
527
|
+
").where("province = ?", p)
|
528
|
+
end
|
529
|
+
end
|
530
|
+
end
|
531
|
+
|
532
|
+
if params[:date].present?
|
533
|
+
date = params[:date].split(" - ")
|
534
|
+
@businesses = @businesses.where("educode_sales_businesses.created_at > ? AND educode_sales_businesses.created_at < ?", date[0], date[1] + '23:59:59')
|
535
|
+
end
|
536
|
+
|
537
|
+
if params[:invitation_at].present?
|
538
|
+
date = params[:invitation_at].split(" - ")
|
539
|
+
@businesses = @businesses.joins("
|
540
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
541
|
+
").where("educode_sales_follow_ups.invitation_at > ? AND educode_sales_follow_ups.invitation_at < ?", date[0] + '00:00:00', date[1] + '23:59:59')
|
542
|
+
end
|
543
|
+
|
544
|
+
if params[:sort].present? && params[:sort][:field]
|
545
|
+
@businesses = @businesses.order("#{params[:sort][:field]} #{params[:sort][:order]}")
|
546
|
+
else
|
547
|
+
@businesses = @businesses.order("educode_sales_businesses.created_at desc")
|
548
|
+
end
|
549
|
+
|
550
|
+
@business_count = @businesses.count
|
551
|
+
|
552
|
+
@businesses = @businesses.select("
|
553
|
+
educode_sales_businesses.*,
|
554
|
+
last_follow.invitation_at,
|
555
|
+
last_follow.reception_at,
|
556
|
+
last_follow.bidded_date,
|
557
|
+
last_follow.signed_date,
|
558
|
+
last_follow.created_at as latest_time,
|
559
|
+
last_follow.actual_amount,
|
560
|
+
(last_follow.actual_amount - educode_sales_businesses.return_money) as wait_return_money,
|
561
|
+
last_follow.total_amount").joins("
|
562
|
+
LEFT JOIN educode_sales_follow_ups AS last_follow ON educode_sales_businesses.last_follow_up_id = last_follow.id
|
563
|
+
")
|
564
|
+
|
565
|
+
end
|
566
|
+
end
|
567
|
+
end
|
568
|
+
|
353
569
|
private
|
354
570
|
|
355
571
|
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
|
-
|
154
|
-
|
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
|
@@ -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
|
@@ -19,10 +19,10 @@ module EducodeSales
|
|
19
19
|
level = @current_admin.role.role_areas.find_by(clazz: '回款管理').level
|
20
20
|
case level
|
21
21
|
when '自己'
|
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.
|
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.
|
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).ids
|
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
28
|
@money_plans = MoneyPlan.joins(:follow_up).where("educode_sales_follow_ups.clazz_id != ?", x_id).where(id: ids)
|
@@ -20,7 +20,7 @@ module EducodeSales
|
|
20
20
|
when '自己'
|
21
21
|
@sale_plans = OperationPlan.where(staff_id: @current_admin.id)
|
22
22
|
when '区域'
|
23
|
-
staff_ids = Staff.joins(user: [user_extension: [department: :school]]).where("schools.province in (?)", @current_admin.areas.pluck(:name)).pluck(:id)
|
23
|
+
staff_ids = Staff.joins(user: [user_extension: [department: :school]]).where("schools.province in (?) OR schools.id in (?)", @current_admin.areas.pluck(:name), StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)).pluck(:id)
|
24
24
|
@sale_plans = OperationPlan.where("staff_id in (?) OR educode_sales_operation_plans.staff_id = ?", staff_ids, @current_admin.id)
|
25
25
|
else
|
26
26
|
@sale_plans = OperationPlan
|
@@ -21,7 +21,7 @@ module EducodeSales
|
|
21
21
|
when '自己'
|
22
22
|
@sale_plans = SalePlan.where(staff_id: @current_admin.id)
|
23
23
|
when '区域'
|
24
|
-
staff_ids = Staff.joins(user: [user_extension: [department: :school]]).where("schools.province in (?)", @current_admin.areas.pluck(:name)).pluck(:id)
|
24
|
+
staff_ids = Staff.joins(user: [user_extension: [department: :school]]).where("schools.province in (?) OR schools.id in (?)", @current_admin.areas.pluck(:name),StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)).pluck(:id)
|
25
25
|
@sale_plans = SalePlan.where("staff_id in (?) OR educode_sales_sale_plans.staff_id = ?", staff_ids, @current_admin.id)
|
26
26
|
else
|
27
27
|
@sale_plans = SalePlan
|