educode_sales 0.6.3 → 0.6.7
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/assets/images/educode_sales/money_plans.png +0 -0
- data/app/controllers/educode_sales/activities_controller.rb +0 -2
- data/app/controllers/educode_sales/businesses_controller.rb +103 -47
- data/app/controllers/educode_sales/money_plans_controller.rb +65 -0
- data/app/controllers/educode_sales/roles_controller.rb +4 -1
- data/app/controllers/educode_sales/sale_trends_controller.rb +145 -30
- data/app/controllers/educode_sales/staffs_controller.rb +3 -4
- data/app/controllers/educode_sales/teacher_follows_controller.rb +1 -93
- data/app/models/educode_sales/business_export_record.rb +5 -0
- data/app/models/educode_sales/permission.rb +2 -1
- data/app/models/educode_sales/role_area.rb +1 -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/_follows.html.erb +15 -15
- data/app/views/educode_sales/businesses/edit_follow_record.html.erb +13 -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/file.html.erb +8 -4
- data/app/views/educode_sales/businesses/index.html.erb +121 -14
- data/app/views/educode_sales/businesses/index.json.jbuilder +34 -4
- data/app/views/educode_sales/businesses/new_follow_record.html.erb +10 -5
- data/app/views/educode_sales/businesses/show_follow.html.erb +1 -0
- data/app/views/educode_sales/commons/index.html.erb +7 -1
- data/app/views/educode_sales/customers/edit.html.erb +690 -10
- data/app/views/educode_sales/customers/edit_follow_record.html.erb +1 -1
- data/app/views/educode_sales/customers/index.json.jbuilder +2 -1
- data/app/views/educode_sales/customers/new.html.erb +691 -11
- data/app/views/educode_sales/customers/new_follow_record.html.erb +1 -1
- data/app/views/educode_sales/customers/show_follow.html.erb +1 -1
- data/app/views/educode_sales/money_plans/index.html.erb +222 -0
- data/app/views/educode_sales/money_plans/index.json.jbuilder +21 -0
- data/app/views/educode_sales/places/index.html.erb +16 -2
- data/app/views/educode_sales/places/index.json.jbuilder +3 -1
- data/app/views/educode_sales/plans/_monthPlan.html.erb +2 -1
- data/app/views/educode_sales/plans/_weekPlan.html.erb +2 -1
- data/app/views/educode_sales/recycles/business.json.jbuilder +2 -2
- data/app/views/educode_sales/roles/edit.html.erb +8 -0
- data/app/views/educode_sales/roles/index.html.erb +7 -1
- data/app/views/educode_sales/sale_trends/trends.html.erb +145 -33
- data/app/views/educode_sales/sale_trends/trends.json.jbuilder +4 -14
- data/app/views/educode_sales/sales/index.html.erb +2 -0
- data/app/views/educode_sales/sales/index.json.jbuilder +2 -2
- data/app/views/educode_sales/sales/operations.json.jbuilder +2 -2
- data/app/views/educode_sales/teachers/index.html.erb +15 -7
- data/app/views/layouts/educode_sales/application.html.erb +18 -2
- data/config/routes.rb +4 -0
- data/db/migrate/20210902064109_create_educode_sales_role_permissions.rb +10 -0
- data/lib/educode_sales/version.rb +1 -1
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6dbbb6a86049648541dc1d2fb1ec36eec9e24562bd17693725b1e3b498be3c0
|
4
|
+
data.tar.gz: 7d4dffa34c61c38e66664d685244f4485d1cf7021c7115fb52903155efd3aac8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc84606ad701fb65520d5be1d79f59c83bad909b93fb3d6b4b61b7bc22e037c7b58a94bd9f13f9d8f9bfc6a37d891a168e04c23453fb5590fb4e479878025ed2
|
7
|
+
data.tar.gz: fefca5856e9a3c84876b2dcff7fd9c7415ca1d935f141a367b4dcc3c6b549965febef90454afcfe6462b93fd716a38b21b1899947fe0292353c5dc9f7dfaaaf3
|
Binary file
|
@@ -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
|
@@ -33,21 +10,37 @@ module EducodeSales
|
|
33
10
|
format.html do
|
34
11
|
common = Common.find_by(clazz: 'staff_type', name: '销售')
|
35
12
|
@staffs = Staff.joins(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id]}
|
36
|
-
@more = can?(:create, EducodeSales::SalePlan) || can?(:update, EducodeSales::Business) || can?(:destroy, EducodeSales::Business)
|
13
|
+
# @more = can?(:create, EducodeSales::SalePlan) || can?(:update, EducodeSales::Business) || can?(:destroy, EducodeSales::Business) || can?(:show_file, EducodeSales::Business)
|
14
|
+
@more = true
|
37
15
|
gon.menus = []
|
16
|
+
gon.export_menus = []
|
38
17
|
gon.place = params[:place_id].present? ? [{ value: params[:place_id], name: EducodeSales::Place.find(params[:place_id]).name }] : []
|
18
|
+
gon.business_type = Common.where(clazz: 'business_type').map do |d|
|
19
|
+
{value: d.id, name: d.name}
|
20
|
+
end
|
21
|
+
gon.type = params[:clazz_id].present? ? [{ value: params[:clazz_id], name: Common.find(params[:clazz_id]).name }] : []
|
22
|
+
gon.business_step = Common.where(clazz: 'business_step').map do |d|
|
23
|
+
{value: d.id, name: d.name}
|
24
|
+
end
|
39
25
|
if can?(:create, EducodeSales::SalePlan)
|
40
26
|
gon.menus << { title: '添加周计划', event: 'week' }
|
41
27
|
gon.menus << { title: '添加月计划', event: 'month' }
|
42
28
|
end
|
43
29
|
gon.menus << { title: '跟进时间线', event: 'time_line' }
|
44
|
-
|
30
|
+
if can?(:show_file, EducodeSales::Business)
|
31
|
+
gon.menus << { title: '附件管理', event: 'file' }
|
32
|
+
end
|
45
33
|
if can?(:update, EducodeSales::Business)
|
46
34
|
gon.menus << { title: '编辑', event: 'edit' }
|
47
35
|
end
|
48
36
|
if can?(:destroy, EducodeSales::Business)
|
49
37
|
gon.menus << { title: '删除', event: 'delete' }
|
50
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' }
|
51
44
|
end
|
52
45
|
format.json do
|
53
46
|
if @current_admin.is_admin?
|
@@ -71,41 +64,56 @@ module EducodeSales
|
|
71
64
|
@year = params[:q][:name].split("-")[1].present? ? params[:q][:name].split("-")[1] : ''
|
72
65
|
end
|
73
66
|
|
74
|
-
if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
d_id = Common.find_by(extras: EducodeSales::Common::DTYPE)&.id
|
79
|
-
e_id = Common.find_by(extras: EducodeSales::Common::ETYPE)&.id
|
80
|
-
o_id = Common.find_by(extras: EducodeSales::Common::OTYPE)&.id
|
81
|
-
ids = [a_id ,b_id ,c_id ,d_id ,e_id ,o_id]
|
82
|
-
@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("
|
83
71
|
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
84
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
|
+
|
85
79
|
end
|
86
80
|
|
87
81
|
if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-" + @year + "-已中标商机)"
|
88
82
|
stage_ids = Common.where(clazz: '商机阶段', name: ['已中标','已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
|
89
|
-
@
|
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("
|
90
89
|
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
91
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
|
+
|
92
93
|
end
|
93
94
|
|
94
95
|
if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-" + @year + "-已签单商机)"
|
95
96
|
s_stage_ids = Common.where(clazz: '商机阶段', name: ['已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
|
96
|
-
@
|
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("
|
97
103
|
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
98
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
|
99
106
|
end
|
100
107
|
|
101
108
|
if params[:q].present? && params[:q][:name].present? && params[:q][:name] == "(销售态势-" + @year + "-已回款商机)"
|
102
109
|
x_id = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
|
103
|
-
# @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("
|
104
|
-
# JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
105
|
-
# ").where.not("educode_sales_follow_ups.clazz_id = ?",x_id)
|
106
110
|
year_time = "#{@year}-01-01 00:00:00"
|
107
111
|
year_over_time = "#{@year}-12-31 23:59:59"
|
108
|
-
|
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
|
109
117
|
end
|
110
118
|
|
111
119
|
if params[:q].present? && params[:q][:all].present?
|
@@ -119,7 +127,7 @@ module EducodeSales
|
|
119
127
|
end
|
120
128
|
|
121
129
|
@businesses = @businesses
|
122
|
-
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 + "-现有商机)"
|
123
131
|
@businesses = @businesses.where("educode_sales_businesses.name like ?", "%#{params[:q][:name]}%")
|
124
132
|
end
|
125
133
|
if params[:q].present? && params[:q][:department].present?
|
@@ -137,12 +145,12 @@ module EducodeSales
|
|
137
145
|
if params[:q].present? && params[:q][:business_type].present?
|
138
146
|
@businesses = @businesses.joins("
|
139
147
|
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
140
|
-
").where("educode_sales_follow_ups.clazz_id
|
148
|
+
").where("educode_sales_follow_ups.clazz_id in (?)", params[:q][:business_type].split(",").map(&:to_i))
|
141
149
|
end
|
142
150
|
if params[:q].present? && params[:q][:business_step].present?
|
143
151
|
@businesses = @businesses.joins("
|
144
152
|
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
145
|
-
").where("educode_sales_follow_ups.stage_id
|
153
|
+
").where("educode_sales_follow_ups.stage_id in (?)", params[:q][:business_step].split(",").map(&:to_i))
|
146
154
|
end
|
147
155
|
if params[:q].present? && params[:q][:place_id].present?
|
148
156
|
@businesses = @businesses.joins("
|
@@ -177,6 +185,13 @@ module EducodeSales
|
|
177
185
|
@businesses = @businesses.where("educode_sales_businesses.created_at > ? AND educode_sales_businesses.created_at < ?", date[0], date[1] + '23:59:59')
|
178
186
|
end
|
179
187
|
|
188
|
+
if params[:q].present? && params[:q][:invitation_at].present?
|
189
|
+
date = params[:q][:invitation_at].split(" - ")
|
190
|
+
@businesses = @businesses.joins("
|
191
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
192
|
+
").where("educode_sales_follow_ups.invitation_at > ? AND educode_sales_follow_ups.invitation_at < ?", date[0] + '00:00:00', date[1] + '23:59:59')
|
193
|
+
end
|
194
|
+
|
180
195
|
if params[:sort].present? && params[:sort][:field]
|
181
196
|
@businesses = @businesses.order("#{params[:sort][:field]} #{params[:sort][:order]}")
|
182
197
|
else
|
@@ -185,9 +200,7 @@ module EducodeSales
|
|
185
200
|
|
186
201
|
@business_count = @businesses.count
|
187
202
|
|
188
|
-
|
189
|
-
|
190
|
-
@businesses = @businesses.select("
|
203
|
+
@businesses_exports = @businesses.select("
|
191
204
|
educode_sales_businesses.*,
|
192
205
|
last_follow.invitation_at,
|
193
206
|
last_follow.reception_at,
|
@@ -195,9 +208,12 @@ module EducodeSales
|
|
195
208
|
last_follow.signed_date,
|
196
209
|
last_follow.created_at as latest_time,
|
197
210
|
last_follow.actual_amount,
|
211
|
+
(last_follow.actual_amount - educode_sales_businesses.return_money) as wait_return_money,
|
198
212
|
last_follow.total_amount").joins("
|
199
213
|
LEFT JOIN educode_sales_follow_ups AS last_follow ON educode_sales_businesses.last_follow_up_id = last_follow.id
|
200
|
-
")
|
214
|
+
")
|
215
|
+
|
216
|
+
@businesses = @businesses_exports.page(params[:page]).per(params[:limit])
|
201
217
|
end
|
202
218
|
end
|
203
219
|
end
|
@@ -332,6 +348,46 @@ module EducodeSales
|
|
332
348
|
render layout: false
|
333
349
|
end
|
334
350
|
|
351
|
+
def file
|
352
|
+
gon.folder = edu_setting('attachment_folder') + '/'
|
353
|
+
render layout: false
|
354
|
+
end
|
355
|
+
def upload_file
|
356
|
+
render layout: false
|
357
|
+
end
|
358
|
+
def time_line
|
359
|
+
@business = Business.find(params[:business_id])
|
360
|
+
respond_to do |format|
|
361
|
+
format.html do
|
362
|
+
@follow_ups = @business.follow_ups.order(created_at: :desc)
|
363
|
+
render layout: false
|
364
|
+
end
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
def export_records
|
369
|
+
respond_to do |format|
|
370
|
+
format.html do
|
371
|
+
render layout: false
|
372
|
+
end
|
373
|
+
format.json do
|
374
|
+
@records = BusinessExportRecord.all.page(params[:page]).per(params[:limit])
|
375
|
+
end
|
376
|
+
end
|
377
|
+
end
|
378
|
+
def add_export_records
|
379
|
+
if params[:type] == 'csv'
|
380
|
+
record = BusinessExportRecord.new(name: '商机数据表.csv', staff_id: @current_admin.id)
|
381
|
+
else params[:type] == 'excel'
|
382
|
+
record = BusinessExportRecord.new(name: '商机数据表.xls', staff_id: @current_admin.id)
|
383
|
+
end
|
384
|
+
if record.save
|
385
|
+
render_success
|
386
|
+
else
|
387
|
+
render_failure business
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
335
391
|
private
|
336
392
|
|
337
393
|
def load_business
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require_dependency "educode_sales/application_controller"
|
2
|
+
|
3
|
+
module EducodeSales
|
4
|
+
class MoneyPlansController < ApplicationController
|
5
|
+
|
6
|
+
def index
|
7
|
+
follow_up_ids = Business.pluck(:last_follow_up_id)
|
8
|
+
authorize! :read, MoneyPlan
|
9
|
+
respond_to do |format|
|
10
|
+
format.html do
|
11
|
+
common = Common.find_by(clazz: 'staff_type', name: '销售')
|
12
|
+
@staffs = Staff.joins(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id]}
|
13
|
+
end
|
14
|
+
format.json do
|
15
|
+
x_id = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
|
16
|
+
if @current_admin.is_admin?
|
17
|
+
@money_plans = MoneyPlan.joins(:follow_up).where("educode_sales_follow_ups.clazz_id != ?", x_id).where(follow_up_id: follow_up_ids)
|
18
|
+
else
|
19
|
+
level = @current_admin.role.role_areas.find_by(clazz: '回款管理').level
|
20
|
+
case level
|
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.id)
|
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)
|
26
|
+
b_ids = Business.where(school_id: school_ids).pluck(:last_follow_up_id)
|
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)
|
29
|
+
else
|
30
|
+
@money_plans = MoneyPlan.joins(:follow_up).where("educode_sales_follow_ups.clazz_id != ?", x_id).where(follow_up_id: follow_up_ids)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
if params[:q].present? && params[:q][:business].present?
|
35
|
+
follow_up_ids = Business.where("name like ?", "%#{params[:q][:business]}%").pluck(:last_follow_up_id)
|
36
|
+
@money_plans = @money_plans.where(follow_up_id: follow_up_ids)
|
37
|
+
end
|
38
|
+
if params[:q].present? && params[:q][:school].present?
|
39
|
+
school_ids = School.where("name like ?", "%#{params[:q][:school]}%").pluck(:id)
|
40
|
+
follow_up_ids = Business.where(school_id: school_ids).pluck(:last_follow_up_id)
|
41
|
+
@money_plans = @money_plans.where(follow_up_id: follow_up_ids)
|
42
|
+
end
|
43
|
+
if params[:q].present? && params[:q][:staff_id].present?
|
44
|
+
@money_plans = @money_plans.where(staff_id: params[:q][:staff_id])
|
45
|
+
end
|
46
|
+
if params[:q].present? && params[:q][:clazz].present?
|
47
|
+
@money_plans = @money_plans.where(clazz: params[:q][:clazz])
|
48
|
+
end
|
49
|
+
if params[:q].present? && params[:q][:date].present?
|
50
|
+
date = params[:q][:date].split(" - ")
|
51
|
+
@money_plans = @money_plans.where("educode_sales_money_plans.date_at >= ? AND educode_sales_money_plans.date_at < ?", date[0], date[1] + '23:59:59')
|
52
|
+
end
|
53
|
+
|
54
|
+
if params[:sort].present? && params[:sort][:field]
|
55
|
+
@money_plans = @money_plans.order("#{params[:sort][:field]} #{params[:sort][:order]}")
|
56
|
+
else
|
57
|
+
@money_plans = @money_plans.order(date_at: :desc)
|
58
|
+
end
|
59
|
+
@total_amount = @money_plans.sum(:amount)
|
60
|
+
@money_plans = @money_plans.page(params[:page]).per(params[:limit])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -16,7 +16,7 @@ module EducodeSales
|
|
16
16
|
|
17
17
|
def create
|
18
18
|
role = Role.new(name: params[:name])
|
19
|
-
role.role_areas.build([{ clazz: 'Business' }, { clazz: 'SalePlan' }, { clazz: 'Teacher' }, { clazz: 'Operation' }, {clazz:'Customer'}])
|
19
|
+
role.role_areas.build([{ clazz: 'Business' }, { clazz: 'SalePlan' }, { clazz: 'Teacher' }, { clazz: 'Operation' }, {clazz:'Customer'}, {clazz:'MoneyPlan'}])
|
20
20
|
if role.save
|
21
21
|
render_success
|
22
22
|
else
|
@@ -81,6 +81,9 @@ module EducodeSales
|
|
81
81
|
r = role.role_areas.find_or_initialize_by(clazz: 'Customer')
|
82
82
|
r.level = params[:customer]
|
83
83
|
r.save
|
84
|
+
r = role.role_areas.find_or_initialize_by(clazz: 'MoneyPlan')
|
85
|
+
r.level = params[:money_plan]
|
86
|
+
r.save
|
84
87
|
render_success
|
85
88
|
end
|
86
89
|
|
@@ -7,24 +7,41 @@ module EducodeSales
|
|
7
7
|
def trends
|
8
8
|
# authorize! :trends, EducodeSales::SaleTrend
|
9
9
|
@year = params[:year] ? params[:year] : Time.now.year
|
10
|
-
@years = (1..(Time.now.year - 2014)).reverse_each.map { |d| 2014 + d }
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
10
|
+
@years = ['全部'] + (1..(Time.now.year - 2014)).reverse_each.map { |d| 2014 + d }
|
11
|
+
if(@year == '全部')
|
12
|
+
x = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
|
13
|
+
o = Common.find_by(extras: EducodeSales::Common::OTYPE)&.id
|
14
|
+
@business_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).sum(:total_amount).round(2)
|
15
|
+
stage_ids = Common.where(clazz: '商机阶段', name: ['已中标','已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
|
16
|
+
@goal_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.stage_id IN (?)", stage_ids).sum(:total_amount).round(2)
|
17
|
+
@actual_goal_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.stage_id IN (?)", stage_ids).sum(:actual_amount).round(2)
|
18
|
+
s_stage_ids = Common.where(clazz: '商机阶段', name: ['已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
|
19
|
+
@service_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.stage_id IN (?)", s_stage_ids).sum(:total_amount).round(2)
|
20
|
+
@actual_service_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.stage_id IN (?)", s_stage_ids).sum(:actual_amount).round(2)
|
21
|
+
@return_amount = Business.joins(last_follow_up: :money_plans).where("educode_sales_follow_ups.clazz_id != ?", x).where.not("educode_sales_money_plans.clazz!= ?", 1).sum(:amount).round(2)
|
22
|
+
a = Common.where(clazz: '商机类型', name: Common.find_by(extras: EducodeSales::Common::ATYPE)&.name).pluck(:id)
|
23
|
+
@a_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id IN (?)", a).sum(:total_amount).round(2)
|
24
|
+
b = Common.where(clazz: '商机类型', name: Common.find_by(extras: EducodeSales::Common::BTYPE)&.name).pluck(:id)
|
25
|
+
@b_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id IN (?)", b).sum(:total_amount).round(2)
|
26
|
+
else
|
27
|
+
year_time = "#{@year}-01-01 00:00:00"
|
28
|
+
year_over_time = "#{@year}-12-31 23:59:59"
|
29
|
+
x = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
|
30
|
+
o = Common.find_by(extras: EducodeSales::Common::OTYPE)&.id
|
31
|
+
@sale_trend = SaleTrend.find_or_create_by(year: @year)
|
32
|
+
@business_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).where("educode_sales_follow_ups.year = ?",@year).sum(:total_amount).round(2)
|
33
|
+
stage_ids = Common.where(clazz: '商机阶段', name: ['已中标','已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
|
34
|
+
@goal_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).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).sum(:total_amount).round(2)
|
35
|
+
@actual_goal_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).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).sum(:actual_amount).round(2)
|
36
|
+
s_stage_ids = Common.where(clazz: '商机阶段', name: ['已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
|
37
|
+
@service_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).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).sum(:total_amount).round(2)
|
38
|
+
@actual_service_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).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).sum(:actual_amount).round(2)
|
39
|
+
@return_amount = Business.joins(last_follow_up: :money_plans).where("educode_sales_follow_ups.clazz_id != ?", x).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).sum(:amount).round(2)
|
40
|
+
a = Common.where(clazz: '商机类型', name: Common.find_by(extras: EducodeSales::Common::ATYPE)&.name).pluck(:id)
|
41
|
+
@a_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id IN (?)", a).where("educode_sales_follow_ups.year = ?",@year).sum(:total_amount).round(2)
|
42
|
+
b = Common.where(clazz: '商机类型', name: Common.find_by(extras: EducodeSales::Common::BTYPE)&.name).pluck(:id)
|
43
|
+
@b_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id IN (?)", b).where("educode_sales_follow_ups.year = ?",@year).sum(:total_amount).round(2)
|
44
|
+
end
|
28
45
|
|
29
46
|
count_type = params[:count_type] || "actual_amount"
|
30
47
|
common = Common.find_by(clazz: 'staff_type', name: '销售')
|
@@ -74,18 +91,116 @@ module EducodeSales
|
|
74
91
|
|
75
92
|
#商机区域分布图表
|
76
93
|
provinces = EducodeSales::Common.where(clazz: 'area').pluck(:name)
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
94
|
+
if params[:business_count_type] == 'money' || params[:business_count_type].blank?
|
95
|
+
@business_data = {
|
96
|
+
labels: provinces,
|
97
|
+
datasets:[
|
98
|
+
{
|
99
|
+
label: "商机总额",
|
100
|
+
data: provinces.map{|province|
|
101
|
+
if params[:business_type].blank?
|
102
|
+
Business.joins(:last_follow_up).where("educode_sales_businesses.department_id in (?)", School.joins(:departments).where(province: province).pluck("departments.id")).where("educode_sales_follow_ups.clazz_id != ?", x).sum(:total_amount).round(2)
|
103
|
+
else
|
104
|
+
Business.joins(:last_follow_up).where("educode_sales_businesses.department_id in (?)", School.joins(:departments).where(province: province).pluck("departments.id")).where("educode_sales_follow_ups.clazz_id = ?", params[:business_type]).sum(:total_amount).round(2)
|
105
|
+
end
|
106
|
+
},
|
107
|
+
backgroundColor: colors[0],
|
108
|
+
borderColor: colors[0],
|
109
|
+
borderWidth: 1
|
110
|
+
}
|
111
|
+
]
|
112
|
+
}
|
113
|
+
else
|
114
|
+
@business_data = {
|
115
|
+
labels: provinces,
|
116
|
+
datasets:[
|
117
|
+
{
|
118
|
+
label: "商机数量",
|
119
|
+
data: provinces.map{|province|
|
120
|
+
if params[:business_type].blank?
|
121
|
+
Business.joins(:last_follow_up).where("educode_sales_businesses.department_id in (?)", School.joins(:departments).where(province: province).pluck("departments.id")).where("educode_sales_follow_ups.clazz_id != ?", x).count
|
122
|
+
else
|
123
|
+
Business.joins(:last_follow_up).where("educode_sales_businesses.department_id in (?)", School.joins(:departments).where(province: province).pluck("departments.id")).where("educode_sales_follow_ups.clazz_id = ?", params[:business_type]).count
|
124
|
+
end
|
125
|
+
},
|
126
|
+
backgroundColor: colors[0],
|
127
|
+
borderColor: colors[0],
|
128
|
+
borderWidth: 1
|
129
|
+
}
|
130
|
+
]
|
131
|
+
}
|
132
|
+
end
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
# 销售人员跟进分析
|
137
|
+
begin_time = Time.now.at_beginning_of_year.to_s
|
138
|
+
end_time = Time.now.at_end_of_year.to_s
|
139
|
+
customer_time_range = params[:customer_time_range]
|
140
|
+
case customer_time_range
|
141
|
+
when 'last_week'
|
142
|
+
begin_time = (Time.now - 1.week).at_beginning_of_week.to_s
|
143
|
+
end_time = (Time.now - 1.week).at_end_of_week.to_s
|
144
|
+
when 'this_week'
|
145
|
+
begin_time = Time.now.at_beginning_of_week.to_s
|
146
|
+
end_time = Time.now.at_end_of_week.to_s
|
147
|
+
when 'last_month'
|
148
|
+
begin_time = (Time.now - 1.month).at_beginning_of_month.to_s
|
149
|
+
end_time = (Time.now - 1.month).at_end_of_month.to_s
|
150
|
+
when 'this_month'
|
151
|
+
begin_time = Time.now.at_beginning_of_month.to_s
|
152
|
+
end_time = Time.now.at_end_of_month.to_s
|
153
|
+
when 'last_year'
|
154
|
+
begin_time = (Time.now - 1.year).at_beginning_of_year.to_s
|
155
|
+
end_time = (Time.now - 1.year).at_end_of_year.to_s
|
156
|
+
when 'this_year'
|
157
|
+
begin_time = Time.now.at_beginning_of_year.to_s
|
158
|
+
end_time = Time.now.at_end_of_year.to_s
|
159
|
+
when 'all'
|
160
|
+
begin_time = (Time.now - 5.year).at_beginning_of_year.to_s
|
161
|
+
end_time = (Time.now + 5.year).at_end_of_year.to_s
|
162
|
+
when 'diy'
|
163
|
+
if params[:customer_date].present?
|
164
|
+
date = params[:customer_date].split(" - ")
|
165
|
+
begin_time = date[0]
|
166
|
+
end_time = date[1]
|
167
|
+
end
|
168
|
+
end
|
169
|
+
common = Common.find_by(clazz: 'staff_type', name: '销售')
|
170
|
+
staff_names = Staff.joins(:user).where(job_type: common.id).map { |d| d.user.real_name}
|
171
|
+
staff_ids = Staff.joins(:user).where(job_type: common.id).pluck(:id)
|
172
|
+
if params[:customer_count_type] == 'money' || params[:customer_count_type].blank?
|
173
|
+
@customer_data = {
|
174
|
+
labels: staff_names,
|
175
|
+
datasets:[
|
176
|
+
{
|
177
|
+
label: "跟进客户数",
|
178
|
+
data: staff_ids.map{|staff_id|
|
179
|
+
(EducodeSales::CustomerFollow.where(staff_id: staff_id).where("created_at >= ? AND created_at <= ?", begin_time, end_time).pluck(:school_id) + EducodeSales::Business.where(id: EducodeSales::FollowUp.where(staff_id: staff_id).where("created_at >= ? AND created_at <= ?", begin_time, end_time).pluck(:business_id).uniq).pluck(:school_id)).uniq.size
|
180
|
+
},
|
181
|
+
backgroundColor: colors[0],
|
182
|
+
borderColor: colors[0],
|
183
|
+
borderWidth: 1
|
184
|
+
}
|
185
|
+
]
|
186
|
+
}
|
187
|
+
else
|
188
|
+
@customer_data = {
|
189
|
+
labels: staff_names,
|
190
|
+
datasets:[
|
191
|
+
{
|
192
|
+
label: "跟进客户次数",
|
193
|
+
data: staff_ids.map{|staff_id|
|
194
|
+
EducodeSales::CustomerFollow.where(staff_id: staff_id).where("created_at >= ? AND created_at <= ?", begin_time, end_time).size + EducodeSales::FollowUp.where(staff_id: staff_id).where("created_at >= ? AND created_at <= ?", begin_time, end_time).size
|
195
|
+
},
|
196
|
+
backgroundColor: colors[0],
|
197
|
+
borderColor: colors[0],
|
198
|
+
borderWidth: 1
|
199
|
+
}
|
200
|
+
]
|
201
|
+
}
|
202
|
+
end
|
203
|
+
|
89
204
|
|
90
205
|
|
91
206
|
# 已中标图表
|
@@ -67,14 +67,13 @@ module EducodeSales
|
|
67
67
|
|
68
68
|
def follow_up_schools
|
69
69
|
staff = Staff.find(params[:id])
|
70
|
-
|
71
|
-
@
|
72
|
-
@count = EducodeSales::Business.joins(:last_follow_up, :department).where("educode_sales_follow_ups.staff_id = #{staff.id}").group("departments.school_id").count
|
70
|
+
@schools = EducodeSales::Teacher.joins(:follow_up, :department).where("educode_sales_teacher_follows.staff_id = #{staff.id}").group("departments.school_id").select("departments.school_id, max(educode_sales_teacher_follows.updated_at) AS updated_at") + EducodeSales::Business.joins(:follow_ups, :department).where("educode_sales_follow_ups.staff_id = #{staff.id}").group("departments.school_id").select("departments.school_id, max(educode_sales_follow_ups.updated_at) AS updated_at")
|
71
|
+
@count = EducodeSales::Business.joins(:follow_ups, :department).where("educode_sales_follow_ups.staff_id = #{staff.id}").group("departments.school_id").count
|
73
72
|
end
|
74
73
|
|
75
74
|
def follow_up_departments
|
76
75
|
staff = Staff.find(params[:id])
|
77
|
-
@schools = EducodeSales::Business.joins(:
|
76
|
+
@schools = (EducodeSales::Business.joins(:follow_ups, [department: :school]).where("educode_sales_follow_ups.staff_id = #{staff.id}").select("departments.id, departments.name, schools.name AS school, educode_sales_follow_ups.updated_at") + EducodeSales::Teacher.joins(:follow_up, [department: :school]).where("educode_sales_teacher_follows.staff_id = #{staff.id}").select("departments.id, departments.name, schools.name AS school, educode_sales_teacher_follows.updated_at")).uniq{|s| s.id}
|
78
77
|
end
|
79
78
|
|
80
79
|
|