educode_sales 0.6.0 → 0.6.4
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/businesses_controller.rb +7 -4
- data/app/controllers/educode_sales/customers_controller.rb +45 -34
- data/app/controllers/educode_sales/follow_ups_controller.rb +1 -1
- data/app/controllers/educode_sales/money_plans_controller.rb +64 -0
- data/app/controllers/educode_sales/places_controller.rb +5 -1
- data/app/controllers/educode_sales/roles_controller.rb +4 -1
- data/app/controllers/educode_sales/sale_trends_controller.rb +44 -1
- data/app/controllers/educode_sales/staffs_controller.rb +3 -4
- data/app/controllers/educode_sales/teachers_controller.rb +13 -2
- data/app/models/educode_sales/permission.rb +3 -2
- data/app/models/educode_sales/role_area.rb +1 -0
- data/app/views/educode_sales/businesses/_follows.html.erb +18 -15
- data/app/views/educode_sales/businesses/edit.html.erb +3 -0
- data/app/views/educode_sales/businesses/index.html.erb +28 -18
- data/app/views/educode_sales/businesses/index.json.jbuilder +1 -0
- data/app/views/educode_sales/businesses/show_follow.html.erb +2 -1
- data/app/views/educode_sales/businesses/time_line.html.erb +1 -1
- data/app/views/educode_sales/customers/edit.html.erb +732 -22
- data/app/views/educode_sales/customers/index.html.erb +19 -19
- data/app/views/educode_sales/customers/index.json.jbuilder +3 -3
- data/app/views/educode_sales/customers/new.html.erb +710 -27
- data/app/views/educode_sales/customers/new_department.html.erb +1 -0
- data/app/views/educode_sales/customers/show_follow.html.erb +5 -2
- data/app/views/educode_sales/customers/show_follow_record.html.erb +5 -4
- data/app/views/educode_sales/follow_ups/index.json.jbuilder +1 -0
- data/app/views/educode_sales/money_plans/index.html.erb +183 -0
- data/app/views/educode_sales/money_plans/index.json.jbuilder +20 -0
- data/app/views/educode_sales/places/index.html.erb +64 -0
- 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/roles/edit.html.erb +9 -1
- data/app/views/educode_sales/sale_trends/trends.html.erb +93 -13
- data/app/views/educode_sales/sale_trends/trends.json.jbuilder +3 -14
- data/app/views/educode_sales/sales/index.html.erb +25 -17
- data/app/views/educode_sales/sales/index.json.jbuilder +20 -2
- data/app/views/educode_sales/sales/operations.json.jbuilder +2 -2
- data/app/views/educode_sales/teachers/index.html.erb +4 -11
- data/app/views/educode_sales/teachers/index.json.jbuilder +1 -1
- data/app/views/layouts/educode_sales/application.html.erb +13 -2
- data/config/routes.rb +2 -0
- data/db/migrate/20210902064109_create_educode_sales_role_permissions.rb +3 -0
- data/db/migrate/20211220102720_add_position_to_commons.rb +12 -0
- data/db/migrate/20211221075146_add_school_id_to_educode_sales_businesses.rb +8 -0
- data/lib/educode_sales/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cd066340676e40c41aa18730eacf453f8bf228ceb4416179f0e916581525999
|
4
|
+
data.tar.gz: a30becf3c8cc2c925c21b66948d429a241d3750289f5e921ab3c0cde5aeea3f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adabc609d925eb080964dc566815134c5384f258fde90b7008296ceacf178a1435be37c553f49291844ce7043f6dfc4745f7713da687f40da40871acc67a6f8e
|
7
|
+
data.tar.gz: 042b06433756725fad2b2bd4bb612bca89616f3e18e6055e5c2df4a89d8ece4810f9fe80899047a52c86d60c6e263b14bdb92ee9107efe63bb662ee51dd73041
|
Binary file
|
@@ -76,7 +76,9 @@ module EducodeSales
|
|
76
76
|
b_id = Common.find_by(extras: EducodeSales::Common::BTYPE)&.id
|
77
77
|
c_id = Common.find_by(extras: EducodeSales::Common::CTYPE)&.id
|
78
78
|
d_id = Common.find_by(extras: EducodeSales::Common::DTYPE)&.id
|
79
|
-
|
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]
|
80
82
|
@businesses = @businesses.joins("
|
81
83
|
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
82
84
|
").where("educode_sales_follow_ups.clazz_id in (?)",ids)
|
@@ -172,7 +174,7 @@ module EducodeSales
|
|
172
174
|
|
173
175
|
if params[:q].present? && params[:q][:date].present?
|
174
176
|
date = params[:q][:date].split(" - ")
|
175
|
-
@businesses = @businesses.where("educode_sales_businesses.created_at > ? AND educode_sales_businesses.created_at < ?", date[0], date[1])
|
177
|
+
@businesses = @businesses.where("educode_sales_businesses.created_at > ? AND educode_sales_businesses.created_at < ?", date[0], date[1] + '23:59:59')
|
176
178
|
end
|
177
179
|
|
178
180
|
if params[:sort].present? && params[:sort][:field]
|
@@ -191,6 +193,7 @@ module EducodeSales
|
|
191
193
|
last_follow.reception_at,
|
192
194
|
last_follow.bidded_date,
|
193
195
|
last_follow.signed_date,
|
196
|
+
last_follow.created_at as latest_time,
|
194
197
|
last_follow.actual_amount,
|
195
198
|
last_follow.total_amount").joins("
|
196
199
|
LEFT JOIN educode_sales_follow_ups AS last_follow ON educode_sales_businesses.last_follow_up_id = last_follow.id
|
@@ -201,7 +204,7 @@ module EducodeSales
|
|
201
204
|
|
202
205
|
def create
|
203
206
|
department = Department.find(params[:department_id])
|
204
|
-
business = @current_admin.businesses.build(name: params[:name], department_id: department.id, source: params[:source])
|
207
|
+
business = @current_admin.businesses.build(name: params[:name], department_id: department.id, source: params[:source], school_id: department.school_id)
|
205
208
|
if business.save
|
206
209
|
render_success
|
207
210
|
else
|
@@ -223,7 +226,7 @@ module EducodeSales
|
|
223
226
|
def update
|
224
227
|
business = Business.find(params[:id])
|
225
228
|
department = Department.find(params[:department_id])
|
226
|
-
if business.update(name: params[:name], department_id: department.id, source: params[:source])
|
229
|
+
if business.update(name: params[:name], department_id: department.id, source: params[:source], school_id: department.school_id)
|
227
230
|
render_success
|
228
231
|
else
|
229
232
|
render_failure business
|
@@ -2,8 +2,6 @@ require_dependency "educode_sales/application_controller"
|
|
2
2
|
|
3
3
|
module EducodeSales
|
4
4
|
class CustomersController < ApplicationController
|
5
|
-
# before_action :find_school, only: [:edit, :update]
|
6
|
-
# before_action :must_admin!, only: [:destroy]
|
7
5
|
|
8
6
|
def new_department
|
9
7
|
render layout: false
|
@@ -43,7 +41,7 @@ module EducodeSales
|
|
43
41
|
end
|
44
42
|
format.json do
|
45
43
|
if @current_admin.is_admin?
|
46
|
-
@customers = School
|
44
|
+
@customers = School.all
|
47
45
|
else
|
48
46
|
level = @current_admin.role.role_areas.find_by(clazz: '客户管理').level
|
49
47
|
case level
|
@@ -56,7 +54,7 @@ module EducodeSales
|
|
56
54
|
school_ids = a_school_ids + b_school_ids
|
57
55
|
@customers = School.where(id: school_ids)
|
58
56
|
else
|
59
|
-
@customers = School
|
57
|
+
@customers = School.all
|
60
58
|
end
|
61
59
|
end
|
62
60
|
|
@@ -71,21 +69,29 @@ module EducodeSales
|
|
71
69
|
@customers = @customers.where(id: school_ids)
|
72
70
|
end
|
73
71
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
72
|
+
if params[:q].present? && params[:q][:date].present?
|
73
|
+
ids = EducodeSales::CustomerFollow.all.pluck(:school_id)
|
74
|
+
@customers = @customers.where(id: ids)
|
75
|
+
school_ids =[]
|
76
|
+
date = params[:q][:date].split(" - ")
|
77
|
+
@customers.each do |d|
|
78
|
+
business_ids = EducodeSales::Business.where(school_id: d.id).ids
|
79
|
+
follow_ups = EducodeSales::FollowUp.where(business_id: business_ids)
|
80
|
+
customer_follows = EducodeSales::CustomerFollow.where(school_id: d.id)
|
81
|
+
next if follow_ups.blank? && customer_follows.blank?
|
82
|
+
a_last_follow_time = follow_ups.last&.created_at&.to_s
|
83
|
+
b_last_follow_time = customer_follows.last&.created_at&.to_s
|
84
|
+
if a_last_follow_time.present? && b_last_follow_time.present?
|
85
|
+
last_follow_time = ((a_last_follow_time < b_last_follow_time) ? b_last_follow_time : a_last_follow_time)
|
86
|
+
else
|
87
|
+
last_follow_time = (a_last_follow_time || b_last_follow_time)
|
88
|
+
end
|
89
|
+
if last_follow_time.present? && last_follow_time > date[0] && last_follow_time < date[1]
|
90
|
+
school_ids << d.id
|
91
|
+
end
|
92
|
+
end
|
93
|
+
@customers = @customers.where(id: school_ids)
|
94
|
+
end
|
89
95
|
|
90
96
|
@customers = @customers.order(id: :desc).page(params[:page]).per(params[:limit])
|
91
97
|
end
|
@@ -109,11 +115,6 @@ module EducodeSales
|
|
109
115
|
format.json do
|
110
116
|
@follow_ups = EducodeSales::CustomerFollow.where(school_id: params[:id])
|
111
117
|
@latest = @follow_ups.order(created_at: :desc).first
|
112
|
-
# if params[:field]
|
113
|
-
# @follow_ups = @follow_ups.order("#{params[:field]} #{params[:order]}")
|
114
|
-
# else
|
115
|
-
# @follow_ups = @follow_ups.order("created_at desc")
|
116
|
-
# end
|
117
118
|
@follow_ups = @follow_ups.order("created_at desc")
|
118
119
|
@follow_ups = @follow_ups.page(params[:page]).per(params[:limit])
|
119
120
|
end
|
@@ -122,11 +123,6 @@ module EducodeSales
|
|
122
123
|
|
123
124
|
def show_department
|
124
125
|
@departments = School.find(params[:id]).departments
|
125
|
-
# if params[:field]
|
126
|
-
# @follow_ups = @follow_ups.order("#{params[:field]} #{params[:order]}")
|
127
|
-
# else
|
128
|
-
# @follow_ups = @follow_ups.order("created_at desc")
|
129
|
-
# end
|
130
126
|
@departments = @departments.order("created_at desc")
|
131
127
|
@departments = @departments.page(params[:page]).per(params[:limit])
|
132
128
|
end
|
@@ -154,40 +150,55 @@ module EducodeSales
|
|
154
150
|
end
|
155
151
|
|
156
152
|
def create
|
157
|
-
@school = School.find(params[:id])
|
158
153
|
ActiveRecord::Base.transaction do
|
159
|
-
property = SchoolProperty.find_or_create_by!(
|
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)
|
160
161
|
@school = School.new
|
161
162
|
@school.attributes = school_params
|
162
163
|
@school.school_property = property
|
163
164
|
@school.save!
|
165
|
+
EducodeSales::CustomerExtension.create(customer_staff_id: @current_admin.id, school_id: @school.id)
|
164
166
|
end
|
167
|
+
render_success
|
165
168
|
end
|
166
169
|
|
167
170
|
def edit
|
168
171
|
@school = School.find(params[:id])
|
172
|
+
@school_property = @school.school_property
|
169
173
|
render layout: false
|
170
174
|
end
|
171
175
|
|
172
176
|
def update
|
173
177
|
@school = School.find(params[:id])
|
174
178
|
ActiveRecord::Base.transaction do
|
175
|
-
property = SchoolProperty.find_or_create_by!(
|
179
|
+
property = SchoolProperty.find_or_create_by!(project_985: params[:project_985].present? ? 1 : 0,
|
180
|
+
project_211: params[:project_211].present? ? 1 : 0,
|
181
|
+
regular_college: params[:regular_college].present? ? 1 : 0,
|
182
|
+
junior_college: params[:junior_college].present? ? 1 : 0,
|
183
|
+
secondary_school: params[:secondary_school].present? ? 1 : 0,
|
184
|
+
military_school: params[:military_school].present? ? 1 : 0,
|
185
|
+
enterprise: params[:enterprise].present? ? 1 : 0)
|
176
186
|
@school.attributes = school_params
|
177
187
|
@school.school_property = property
|
178
188
|
@school.save!
|
179
189
|
end
|
190
|
+
render_success
|
180
191
|
end
|
181
192
|
|
182
193
|
private
|
183
194
|
|
184
195
|
|
185
196
|
def school_property_params
|
186
|
-
params.
|
197
|
+
params.permit(:project_985, :project_211, :regular_college, :junior_college, :secondary_school, :military_school, :enterprise)
|
187
198
|
end
|
188
199
|
|
189
200
|
def school_params
|
190
|
-
params.
|
201
|
+
params.permit(:name, :province, :city, :address)
|
191
202
|
end
|
192
203
|
|
193
204
|
end
|
@@ -34,7 +34,7 @@ module EducodeSales
|
|
34
34
|
end
|
35
35
|
if params[:q].present? && params[:q][:follows_date].present?
|
36
36
|
date = params[:q][:follows_date].split(" - ")
|
37
|
-
@follow_ups = @follow_ups.where("educode_sales_follow_ups.created_at > ? AND educode_sales_follow_ups.created_at < ?", date[0], date[1])
|
37
|
+
@follow_ups = @follow_ups.where("educode_sales_follow_ups.created_at > ? AND educode_sales_follow_ups.created_at < ?", date[0], date[1] + '23:59:59')
|
38
38
|
end
|
39
39
|
if params[:q].present? && params[:q][:staff_id].present?
|
40
40
|
@follow_ups = @follow_ups.where(staff_id: params[:q][:staff_id])
|
@@ -0,0 +1,64 @@
|
|
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
|
+
if @current_admin.is_admin?
|
16
|
+
@money_plans = MoneyPlan.where(follow_up_id: follow_up_ids)
|
17
|
+
else
|
18
|
+
level = @current_admin.role.role_areas.find_by(clazz: '回款管理').level
|
19
|
+
case level
|
20
|
+
when '自己'
|
21
|
+
@money_plans = MoneyPlan.where(follow_up_id: follow_up_ids).where(staff_id: @current_admin.staff_id)
|
22
|
+
when '区域'
|
23
|
+
a_ids = MoneyPlan.where(follow_up_id: follow_up_ids).where(staff_id: @current_admin.staff_id).ids
|
24
|
+
school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id)
|
25
|
+
b_ids = Business.where(school_id: school_ids).pluck(:last_follow_up_id)
|
26
|
+
ids = a_ids + b_ids
|
27
|
+
@money_plans = MoneyPlan.where(id: ids)
|
28
|
+
else
|
29
|
+
@money_plans = MoneyPlan.where(follow_up_id: follow_up_ids)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
if params[:q].present? && params[:q][:business].present?
|
34
|
+
follow_up_ids = Business.where("name like ?", "%#{params[:q][:business]}%").pluck(:last_follow_up_id)
|
35
|
+
@money_plans = @money_plans.where(follow_up_id: follow_up_ids)
|
36
|
+
end
|
37
|
+
if params[:q].present? && params[:q][:school].present?
|
38
|
+
school_ids = School.where("name like ?", "%#{params[:q][:school]}%").pluck(:id)
|
39
|
+
follow_up_ids = Business.where(school_id: school_ids).pluck(:last_follow_up_id)
|
40
|
+
@money_plans = @money_plans.where(follow_up_id: follow_up_ids)
|
41
|
+
end
|
42
|
+
if params[:q].present? && params[:q][:staff_id].present?
|
43
|
+
@money_plans = @money_plans.where(staff_id: params[:q][:staff_id])
|
44
|
+
end
|
45
|
+
if params[:q].present? && params[:q][:clazz].present?
|
46
|
+
@money_plans = @money_plans.where(clazz: params[:q][:clazz])
|
47
|
+
end
|
48
|
+
if params[:q].present? && params[:q][:date].present?
|
49
|
+
date = params[:q][:date].split(" - ")
|
50
|
+
@money_plans = @money_plans.where("educode_sales_money_plans.created_at > ? AND educode_sales_money_plans.created_at < ?", date[0], date[1] + '23:59:59')
|
51
|
+
end
|
52
|
+
|
53
|
+
if params[:sort].present? && params[:sort][:field]
|
54
|
+
@money_plans = @money_plans.order("#{params[:sort][:field]} #{params[:sort][:order]}")
|
55
|
+
else
|
56
|
+
@money_plans = @money_plans.order(created_at: :desc)
|
57
|
+
end
|
58
|
+
@total_amount = @money_plans.sum(:amount)
|
59
|
+
@money_plans = @money_plans.page(params[:page]).per(params[:limit])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -8,7 +8,11 @@ module EducodeSales
|
|
8
8
|
format.html do
|
9
9
|
end
|
10
10
|
format.json do
|
11
|
-
@places = Place.
|
11
|
+
@places = EducodeSales::Place.all
|
12
|
+
if params[:q].present? && params[:q][:name].present?
|
13
|
+
@places = @places.where("name like ?", "%#{params[:q][:name]}%")
|
14
|
+
end
|
15
|
+
@places = @places.page(params[:page]).per(params[:limit])
|
12
16
|
@x = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
|
13
17
|
@stage_ids = Common.where(clazz: '商机阶段', name: ['已中标','已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
|
14
18
|
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
|
|
@@ -13,7 +13,7 @@ module EducodeSales
|
|
13
13
|
x = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
|
14
14
|
o = Common.find_by(extras: EducodeSales::Common::OTYPE)&.id
|
15
15
|
@sale_trend = SaleTrend.find_or_create_by(year: @year)
|
16
|
-
@business_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?
|
16
|
+
@business_amount = Business.joins(:last_follow_up).where("educode_sales_follow_ups.clazz_id != ?", x).sum(:total_amount).round(2)
|
17
17
|
stage_ids = Common.where(clazz: '商机阶段', name: ['已中标','已签单','已验收','回款中', '服务中','已结束']).pluck(:id)
|
18
18
|
@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)
|
19
19
|
@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)
|
@@ -72,6 +72,49 @@ module EducodeSales
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
#商机区域分布图表
|
76
|
+
provinces = EducodeSales::Common.where(clazz: 'area').pluck(:name)
|
77
|
+
if params[:business_count_type] == 'money' || params[:business_count_type].blank?
|
78
|
+
@business_data = {
|
79
|
+
labels: provinces,
|
80
|
+
datasets:[
|
81
|
+
{
|
82
|
+
label: "商机总额",
|
83
|
+
data: provinces.map{|province|
|
84
|
+
if params[:business_type].blank?
|
85
|
+
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)
|
86
|
+
else
|
87
|
+
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)
|
88
|
+
end
|
89
|
+
},
|
90
|
+
backgroundColor: colors[0],
|
91
|
+
borderColor: colors[0],
|
92
|
+
borderWidth: 1
|
93
|
+
}
|
94
|
+
]
|
95
|
+
}
|
96
|
+
else
|
97
|
+
@business_data = {
|
98
|
+
labels: provinces,
|
99
|
+
datasets:[
|
100
|
+
{
|
101
|
+
label: "商机数量",
|
102
|
+
data: provinces.map{|province|
|
103
|
+
if params[:business_type].blank?
|
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 != ?", x).count
|
105
|
+
else
|
106
|
+
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
|
107
|
+
end
|
108
|
+
},
|
109
|
+
backgroundColor: colors[0],
|
110
|
+
borderColor: colors[0],
|
111
|
+
borderWidth: 1
|
112
|
+
}
|
113
|
+
]
|
114
|
+
}
|
115
|
+
end
|
116
|
+
|
117
|
+
|
75
118
|
|
76
119
|
# 已中标图表
|
77
120
|
goal_default_dates = ("#{Time.now.year}-01".."#{Time.now.year}-#{Time.now.month}").to_a
|
@@ -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("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
|
|
@@ -113,10 +113,21 @@ module EducodeSales
|
|
113
113
|
@teachers = @teachers.where("educode_sales_teachers.created_at > ? AND educode_sales_teachers.created_at < ?", date[0], date[1])
|
114
114
|
end
|
115
115
|
|
116
|
-
@teachers = @teachers.
|
116
|
+
@teachers = @teachers.select("
|
117
|
+
educode_sales_teachers.*,
|
118
|
+
users.created_on,
|
119
|
+
users.last_login_on").joins("
|
120
|
+
LEFT JOIN users ON educode_sales_teachers.user_id = users.id
|
121
|
+
")
|
122
|
+
if params[:sort].present? && params[:sort][:field]
|
123
|
+
@teachers = @teachers.order("#{params[:sort][:field]} #{params[:sort][:order]}")
|
124
|
+
else
|
125
|
+
@teachers = @teachers.order("educode_sales_teachers.created_at desc")
|
126
|
+
end
|
127
|
+
@teachers = @teachers.page(params[:page]).per(params[:limit])
|
128
|
+
end
|
117
129
|
|
118
130
|
end
|
119
|
-
end
|
120
131
|
end
|
121
132
|
|
122
133
|
def import
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module EducodeSales
|
2
2
|
class Permission < ApplicationRecord
|
3
3
|
enum clazz: {
|
4
|
-
'
|
4
|
+
'销售态势': 'market',
|
5
5
|
'销售分工': 'sale_job',
|
6
6
|
'商机管理': 'business',
|
7
7
|
'渠道管理': 'place',
|
@@ -11,7 +11,8 @@ module EducodeSales
|
|
11
11
|
'教师运营': 'teacher',
|
12
12
|
'活动运营': 'activity',
|
13
13
|
'运营计划': 'operation_plan',
|
14
|
-
'客户管理': 'customer'
|
14
|
+
'客户管理': 'customer',
|
15
|
+
'回款管理': 'money_plan'
|
15
16
|
}
|
16
17
|
end
|
17
18
|
end
|
@@ -55,6 +55,9 @@
|
|
55
55
|
<script type="text/html" id="business">
|
56
56
|
<a href="javascript:void(0);" lay-event="business" class="layui-table-link">{{ d.business }}</a>
|
57
57
|
</script>
|
58
|
+
<script type="text/html" id="school">
|
59
|
+
<a href="<%= base_url%>/colleges/{{d.school_id}}/statistics" class="layui-table-link" target="_blank">{{ d.school }}</a>
|
60
|
+
</script>
|
58
61
|
|
59
62
|
|
60
63
|
<script>
|
@@ -97,10 +100,16 @@
|
|
97
100
|
templet:'<div><span title="{{d.description}}">{{d.description}}</span></div>'
|
98
101
|
},
|
99
102
|
{
|
100
|
-
field: '
|
103
|
+
field: 'business',
|
101
104
|
width: 120,
|
102
|
-
title: '
|
103
|
-
templet:'
|
105
|
+
title: '所属商机',
|
106
|
+
templet:'#business'
|
107
|
+
},
|
108
|
+
{
|
109
|
+
field: 'school',
|
110
|
+
width: 120,
|
111
|
+
title: '单位',
|
112
|
+
templet:'#school'
|
104
113
|
},
|
105
114
|
{
|
106
115
|
field: 'clazz',
|
@@ -114,24 +123,18 @@
|
|
114
123
|
width: 90,
|
115
124
|
templet:'<div><span title="{{d.stage}}">{{d.stage}}</span></div>'
|
116
125
|
},
|
126
|
+
{
|
127
|
+
field: 'advise',
|
128
|
+
width: 120,
|
129
|
+
title: '团队建议',
|
130
|
+
templet:'<div><span title="{{d.advise}}">{{d.advise}}</span></div>'
|
131
|
+
},
|
117
132
|
{
|
118
133
|
field: 'key_people',
|
119
134
|
width: 90,
|
120
135
|
title: '关键人',
|
121
136
|
templet:'<div><span title="{{d.key_people}}">{{d.key_people}}</span></div>'
|
122
137
|
},
|
123
|
-
{
|
124
|
-
field: 'business',
|
125
|
-
width: 120,
|
126
|
-
title: '所属商机',
|
127
|
-
templet:'#business'
|
128
|
-
},
|
129
|
-
{
|
130
|
-
field: 'school',
|
131
|
-
width: 120,
|
132
|
-
title: '单位',
|
133
|
-
templet:'<div><span title="{{d.school}}">{{d.school}}</span></div>'
|
134
|
-
},
|
135
138
|
{
|
136
139
|
field: 'staff',
|
137
140
|
width: 90,
|
@@ -11,6 +11,9 @@
|
|
11
11
|
<label class="layui-form-label required">单位部门</label>
|
12
12
|
<div class="layui-input-block" id="department" style="width: 300px;"></div>
|
13
13
|
</div>
|
14
|
+
<div class="layui-inline" >
|
15
|
+
<a href="/missions/customers" style=" color: #0000FF">添加单位/部门</a>
|
16
|
+
</div>
|
14
17
|
<br>
|
15
18
|
<div class="layui-inline" style="padding-top: 20px">
|
16
19
|
<label class="layui-form-label ">商机来源</label>
|
@@ -18,6 +18,7 @@
|
|
18
18
|
<label class="layui-form-label">商机名称</label>
|
19
19
|
<div class="layui-input-inline">
|
20
20
|
<input type="text" name="name" autocomplete="off" class="layui-input" value="<%=params[:name] %>">
|
21
|
+
<input type="text" style="display: none" name="place_id" autocomplete="off" class="layui-input" value="<%=params[:place_id] %>">
|
21
22
|
</div>
|
22
23
|
</div>
|
23
24
|
<div class="layui-inline">
|
@@ -27,7 +28,7 @@
|
|
27
28
|
</div>
|
28
29
|
</div>
|
29
30
|
<div class="layui-inline">
|
30
|
-
<label class="layui-form-label"
|
31
|
+
<label class="layui-form-label">最新跟进人</label>
|
31
32
|
<div class="layui-input-inline">
|
32
33
|
<%= select_tag "staff_id", options_for_select(@staffs, params[:staff_id]), { 'lay-filter': 'staff_id', include_blank: true } %>
|
33
34
|
</div>
|
@@ -57,7 +58,7 @@
|
|
57
58
|
</div>
|
58
59
|
</div>
|
59
60
|
<div class="layui-inline">
|
60
|
-
<label class="layui-form-label"
|
61
|
+
<label class="layui-form-label">创建时间</label>
|
61
62
|
<div class="layui-input-inline">
|
62
63
|
<input type="text" class="layui-input" id="date" name="date" placeholder=" - ">
|
63
64
|
</div>
|
@@ -107,6 +108,9 @@
|
|
107
108
|
<script type="text/html" id="show_follow">
|
108
109
|
<a href="javascript:void(0);" lay-event="show_follow" class="layui-table-link">{{ d.follow_ups_count }}</a>
|
109
110
|
</script>
|
111
|
+
<script type="text/html" id="school_name">
|
112
|
+
<a href="<%= base_url%>/colleges/{{d.school_id}}/statistics" class="layui-table-link" target="_blank">{{ d.school }}</a>
|
113
|
+
</script>
|
110
114
|
|
111
115
|
|
112
116
|
<script>
|
@@ -185,6 +189,10 @@
|
|
185
189
|
defaultToolbar: ['filter'],
|
186
190
|
toolbar: '#bussinessBar',
|
187
191
|
totalRow: true,//开启合并行
|
192
|
+
initSort: {
|
193
|
+
field: 'latest_time' //排序字段,对应 cols 设定的各字段名
|
194
|
+
,type: 'desc' //排序方式 asc: 升序、desc: 降序、null: 默认排序
|
195
|
+
},
|
188
196
|
cols: [
|
189
197
|
[
|
190
198
|
{
|
@@ -203,7 +211,7 @@
|
|
203
211
|
field: 'school',
|
204
212
|
width: 150,
|
205
213
|
title: '单位',
|
206
|
-
templet:'
|
214
|
+
templet:'#school_name'
|
207
215
|
},
|
208
216
|
{
|
209
217
|
field: 'department',
|
@@ -235,6 +243,22 @@
|
|
235
243
|
width: 90,
|
236
244
|
title: '阶段'
|
237
245
|
},
|
246
|
+
{
|
247
|
+
field: 'source',
|
248
|
+
width: 90,
|
249
|
+
title: '商机来源'
|
250
|
+
},
|
251
|
+
{
|
252
|
+
field: 'last_follow_person',
|
253
|
+
width: 100,
|
254
|
+
title: '最新跟进人'
|
255
|
+
},
|
256
|
+
{
|
257
|
+
field: 'latest_time',
|
258
|
+
width: 200,
|
259
|
+
title: '最新跟进时间',
|
260
|
+
sort: true
|
261
|
+
},
|
238
262
|
{
|
239
263
|
field: 'invitation_at',
|
240
264
|
width: 105,
|
@@ -285,21 +309,6 @@
|
|
285
309
|
width: 160,
|
286
310
|
title: '渠道',
|
287
311
|
},
|
288
|
-
{
|
289
|
-
field: 'source',
|
290
|
-
width: 90,
|
291
|
-
title: '商机来源'
|
292
|
-
},
|
293
|
-
{
|
294
|
-
field: 'last_follow_person',
|
295
|
-
width: 100,
|
296
|
-
title: '最新跟进人'
|
297
|
-
},
|
298
|
-
{
|
299
|
-
field: 'latest_time',
|
300
|
-
width: 200,
|
301
|
-
title: '最新跟进时间'
|
302
|
-
},
|
303
312
|
{
|
304
313
|
title: '操作',
|
305
314
|
minWidth: 170,
|
@@ -390,6 +399,7 @@
|
|
390
399
|
});
|
391
400
|
}
|
392
401
|
function time_line(id,name) {
|
402
|
+
business_id = id
|
393
403
|
var content = miniPage.getHrefContent('/missions/businesses/time_line?business_id=' + id);
|
394
404
|
var openWH = miniPage.getOpenWidthHeight();
|
395
405
|
sindex = layer.open({
|
@@ -5,6 +5,7 @@ json.data do
|
|
5
5
|
json.name d.name
|
6
6
|
json.department d.department.name
|
7
7
|
json.school d.department.school.name
|
8
|
+
json.school_id d.department.school.id
|
8
9
|
json.follow_ups_count d.follow_ups_count
|
9
10
|
follow_ups_count += d.follow_ups_count
|
10
11
|
json.follow_up_id d.last_follow_up_id
|