educode_sales 0.9.70 → 0.9.72
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/businesses_controller.rb +43 -2
- data/app/controllers/educode_sales/customers_controller.rb +45 -13
- data/app/controllers/educode_sales/follow_ups_controller.rb +20 -5
- data/app/controllers/educode_sales/plans_controller.rb +69 -19
- data/app/controllers/educode_sales/staffs_controller.rb +35 -0
- data/app/controllers/educode_sales/teachers_controller.rb +7 -0
- data/app/models/educode_sales/customer_follow.rb +1 -0
- data/app/models/educode_sales/sale_plan.rb +2 -0
- data/app/views/educode_sales/businesses/_follows.html.erb +11 -1
- data/app/views/educode_sales/businesses/edit_follow_record.html.erb +19 -0
- data/app/views/educode_sales/businesses/index.html.erb +77 -20
- data/app/views/educode_sales/businesses/index.json.jbuilder +3 -0
- data/app/views/educode_sales/businesses/key_person.html.erb +56 -0
- data/app/views/educode_sales/businesses/key_person.json.jbuilder +17 -0
- data/app/views/educode_sales/businesses/new_follow_record.html.erb +23 -9
- data/app/views/educode_sales/customers/list.html.erb +67 -23
- data/app/views/educode_sales/customers/list.json.jbuilder +22 -10
- data/app/views/educode_sales/customers/show_customer_follow.html.erb +175 -0
- data/app/views/educode_sales/customers/show_customer_follow.json.jbuilder +13 -0
- data/app/views/educode_sales/customers/show_majors.html.erb +146 -0
- data/app/views/educode_sales/follow_ups/index.json.jbuilder +2 -0
- data/app/views/educode_sales/plans/_yearPlan.html.erb +6 -3
- data/app/views/educode_sales/plans/business_infos.json.jbuilder +10 -4
- data/app/views/educode_sales/plans/edit_bussiness_info.html.erb +13 -8
- data/app/views/educode_sales/plans/edit_bussiness_info_extra.html.erb +16 -73
- data/app/views/educode_sales/plans/edit_year_plan.html.erb +64 -5
- data/app/views/educode_sales/plans/new_year.html.erb +51 -3
- data/app/views/educode_sales/plans/plan_business_infos.json.jbuilder +7 -0
- data/app/views/educode_sales/plans/years_plan.json.jbuilder +43 -3
- data/app/views/educode_sales/staffs/edit.html.erb +1 -1
- data/app/views/educode_sales/staffs/index.html.erb +20 -1
- data/app/views/educode_sales/staffs/list.html.erb +39 -0
- data/app/views/educode_sales/teachers/_index.html.erb +15 -5
- data/app/views/educode_sales/teachers/index.json.jbuilder +7 -0
- data/config/routes.rb +6 -0
- data/db/migrate/20230428015007_add_deploy_time_follow_ups.rb +6 -0
- data/lib/educode_sales/version.rb +1 -1
- metadata +13 -7
- data/app/assets/images/educode_sales/indexlogo.png +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3ce2eed15225b67592420332087c3ca7284c2908a17643d6199ac829859196f
|
4
|
+
data.tar.gz: eec810ee5dd968d2c0b6af7053138a1ea8649fe57986dd054a91c15aa1f9afc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dfefa8e8e30235cdbd3ff7c0e17044788cf76d3d62698455da06d77fe0007571a16ff0dd39cc2e4b60faccede54df20da14dd1cbce40eecc6ebf48c4a87c7b2
|
7
|
+
data.tar.gz: b6765899a3cbeda621f0fa85940e1fec3702b74c88685a90bacff2ac57fdd6b9701fb5f89aaab13e577b5b2bb764ac4050a5a681b56ccf2d1006f381f8e5cb30
|
@@ -67,6 +67,7 @@ module EducodeSales
|
|
67
67
|
# gon.menus << { title: '添加团队建议', event: 'suggest' }
|
68
68
|
gon.menus << { title: '添加周计划', event: 'week' }
|
69
69
|
gon.menus << { title: '添加月计划', event: 'month' }
|
70
|
+
gon.menus << { title: '添加年计划', event: 'year' }
|
70
71
|
end
|
71
72
|
|
72
73
|
gon.menus << { title: '关注', event: 'following' }
|
@@ -177,8 +178,21 @@ module EducodeSales
|
|
177
178
|
@businesses = @businesses.where("educode_sales_businesses.name like ?", "%#{params[:q][:name]}%")
|
178
179
|
end
|
179
180
|
if params[:q].present? && params[:q][:department].present?
|
180
|
-
|
181
|
-
|
181
|
+
if params[:q][:department].include?("---")
|
182
|
+
# 从客户管理进来按部门显示商机
|
183
|
+
school_name, department = params[:q][:department].split("---")
|
184
|
+
if department
|
185
|
+
departments_ids = Department.joins(:school).where("schools.name = ? AND departments.name = ?", school_name, department).pluck(:id)
|
186
|
+
@businesses = @businesses.joins(:department).where("departments.id in (?)", departments_ids)
|
187
|
+
else
|
188
|
+
school = School.find_by(name: school_name)
|
189
|
+
@businesses = @businesses.where("educode_sales_businesses.school_id = ?", school&.id)
|
190
|
+
end
|
191
|
+
else
|
192
|
+
departments_ids = Department.joins(:school).where("schools.name like ?", "%#{params[:q][:department]}%").pluck(:id)
|
193
|
+
@businesses = @businesses.joins(:department).where("departments.id in (?)", departments_ids)
|
194
|
+
end
|
195
|
+
|
182
196
|
end
|
183
197
|
if params[:q].present? && params[:q][:staff_id].present?
|
184
198
|
part_a_ids = @businesses.where("educode_sales_businesses.last_follow_up_id is null AND educode_sales_businesses.staff_id = ?",params[:q][:staff_id]).ids
|
@@ -285,6 +299,22 @@ module EducodeSales
|
|
285
299
|
@businesses = @businesses.joins("JOIN educode_sales_business_clazz_changes ON educode_sales_business_clazz_changes.business_id = educode_sales_businesses.id").where("educode_sales_business_clazz_changes.clazz_changed in (?)", clazz_changes)
|
286
300
|
end
|
287
301
|
|
302
|
+
if params[:q].present? && params[:q][:property].present?
|
303
|
+
# 客户类型
|
304
|
+
@businesses = @businesses.joins(department: [school: :school_tags]).where("school_tags.id = ?", params[:q][:property])
|
305
|
+
# @businesses = @businesses.joins("JOIN departments ON educode_sales_businesses.department_id = departments.id
|
306
|
+
# JOIN schools ON departments.school_id = schools.id").where("schools.school_property_id = ?", params[:q][:property])
|
307
|
+
end
|
308
|
+
|
309
|
+
if params[:q].present? && params[:q][:staff_manages].present?
|
310
|
+
# 销售经理
|
311
|
+
@businesses = @businesses.joins("LEFT JOIN educode_sales_follow_ups AS last_follow_up ON educode_sales_businesses.last_follow_up_id = last_follow_up.id AND last_follow_up.deleted_at IS NULL
|
312
|
+
LEFT JOIN educode_sales_assign_follow_ups ON educode_sales_assign_follow_ups.follow_up_id = last_follow_up.id").
|
313
|
+
where("(educode_sales_assign_follow_ups.id IS NOT NULL AND educode_sales_assign_follow_ups.staff_id = ?) OR (educode_sales_assign_follow_ups.id IS NULL AND educode_sales_businesses.staff_id = ?)", params[:q][:staff_manages], params[:q][:staff_manages])
|
314
|
+
|
315
|
+
|
316
|
+
end
|
317
|
+
|
288
318
|
if params[:sort].present? && params[:sort][:field]
|
289
319
|
if params[:sort][:field] == "service_end_time"
|
290
320
|
@businesses = @businesses.order("service_time_long #{params[:sort][:order]}")
|
@@ -1174,6 +1204,17 @@ module EducodeSales
|
|
1174
1204
|
end
|
1175
1205
|
end
|
1176
1206
|
|
1207
|
+
def key_person
|
1208
|
+
respond_to do |format|
|
1209
|
+
format.html do
|
1210
|
+
render layout: false
|
1211
|
+
end
|
1212
|
+
format.json do
|
1213
|
+
@teachers = EducodeSales::KeyPerson.where(follow_up_id: params[:follow_up_id]).page(params[:page]).per(params[:limit])
|
1214
|
+
end
|
1215
|
+
end
|
1216
|
+
end
|
1217
|
+
|
1177
1218
|
private
|
1178
1219
|
|
1179
1220
|
def load_business
|
@@ -27,6 +27,11 @@ module EducodeSales
|
|
27
27
|
render layout: false
|
28
28
|
end
|
29
29
|
|
30
|
+
def show_majors
|
31
|
+
@department = Department.find(params[:id])
|
32
|
+
render layout: false
|
33
|
+
end
|
34
|
+
|
30
35
|
def update_department
|
31
36
|
department = Department.find(params[:id])
|
32
37
|
department.update(name: params[:department_name])
|
@@ -165,36 +170,41 @@ module EducodeSales
|
|
165
170
|
gon.school_tags = SchoolTag.where(for_missions: true).map { |d| {value: d.id, name: d.name } }
|
166
171
|
end
|
167
172
|
format.json do
|
173
|
+
@customers = School.from("(
|
174
|
+
SELECT schools.id, departments.id AS department_id, COUNT(department_majors.id) AS major_count
|
175
|
+
FROM schools
|
176
|
+
LEFT JOIN departments ON schools.id = departments.school_id
|
177
|
+
LEFT JOIN department_majors ON department_majors.department_id = departments.id
|
178
|
+
GROUP BY schools.id, departments.id
|
179
|
+
) AS s")
|
168
180
|
if @current_admin.is_admin?
|
169
|
-
@customers = School.all
|
181
|
+
# @customers = School.all
|
170
182
|
else
|
171
183
|
level = @current_admin.role.role_areas.find_by(clazz: '客户管理').level
|
172
184
|
case level
|
173
185
|
when '自己'
|
174
186
|
school_ids = CustomerExtension.where(customer_staff_id: @current_admin.id).pluck(:school_id)
|
175
|
-
@customers =
|
187
|
+
@customers = @customers.where(id: school_ids)
|
176
188
|
when '区域'
|
177
189
|
a_school_ids = School.where(province: @current_admin.areas.pluck(:name)).ids
|
178
190
|
b_school_ids = CustomerExtension.where(customer_staff_id: @current_admin.id).pluck(:school_id)
|
179
191
|
school_ids = a_school_ids + b_school_ids + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
|
180
|
-
@customers =
|
192
|
+
@customers = @customers.where(id: school_ids)
|
181
193
|
else
|
182
|
-
@customers = School.all
|
194
|
+
# @customers = School.all
|
183
195
|
end
|
184
196
|
end
|
185
197
|
|
186
198
|
@customers = @customers.select("
|
187
199
|
schools.*,
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
@customers = @customers.joins("
|
195
|
-
LEFT JOIN departments ON schools.id = departments.school_id
|
196
|
-
LEFT JOIN department_majors ON department_majors.department_id = departments.id
|
200
|
+
s.major_count,
|
201
|
+
s.department_id,
|
202
|
+
departments.name AS department_name
|
203
|
+
").joins("
|
204
|
+
JOIN schools ON s.id = schools.id
|
205
|
+
LEFT JOIN departments ON s.department_id = departments.id
|
197
206
|
")
|
207
|
+
|
198
208
|
part_a_ids = CustomerFollow.all.pluck(:school_id)
|
199
209
|
part_b_ids = Business.where(id: EducodeSales::FollowUp.pluck(:business_id)).pluck(:school_id)
|
200
210
|
ids = part_a_ids + part_b_ids + CustomerAdd.all.pluck(:school_id)
|
@@ -290,6 +300,28 @@ module EducodeSales
|
|
290
300
|
end
|
291
301
|
end
|
292
302
|
|
303
|
+
def show_customer_follow
|
304
|
+
respond_to do |format|
|
305
|
+
format.html do
|
306
|
+
@school_name = School.find(params[:id]).name
|
307
|
+
@area = School.find(params[:id]).province
|
308
|
+
@staff = EducodeSales::CustomerExtension.where(school_id: params[:id]).map { |d| d.customer_staff&.user&.real_name}.join("、")
|
309
|
+
render layout: false
|
310
|
+
end
|
311
|
+
format.json do
|
312
|
+
if params[:department_id].present?
|
313
|
+
@follow_ups = EducodeSales::CustomerFollow.where(department_id: params[:department_id])
|
314
|
+
else
|
315
|
+
@follow_ups = EducodeSales::CustomerFollow.where(school_id: params[:id])
|
316
|
+
end
|
317
|
+
|
318
|
+
@latest = @follow_ups.order(created_at: :desc).first
|
319
|
+
@follow_ups = @follow_ups.order("created_at desc")
|
320
|
+
@follow_ups = @follow_ups.page(params[:page]).per(params[:limit])
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
293
325
|
def show_department
|
294
326
|
@departments = School.find(params[:id]).departments
|
295
327
|
@departments = @departments.order("created_at desc")
|
@@ -12,19 +12,34 @@ module EducodeSales
|
|
12
12
|
if @current_admin.is_admin?
|
13
13
|
@follow_ups = FollowUp.all
|
14
14
|
else
|
15
|
+
permissions = @current_admin.permissions.pluck(:name)
|
16
|
+
area_business_ids = []
|
17
|
+
if permissions.include?("专项管理商机")
|
18
|
+
# 按客户类型查看商机下跟进记录
|
19
|
+
school_tag_ids = EducodeSales::StaffSchoolTag.where(staff_id: 10009).pluck :school_tag_id
|
20
|
+
school_ids = SchoolTagMiddle.where(school_tag_id: school_tag_ids).pluck :school_id
|
21
|
+
area_business_ids = Business.joins("JOIN departments ON educode_sales_businesses.department_id = departments.id").where("departments.school_id in (?)", school_ids).pluck(:id)
|
22
|
+
end
|
23
|
+
|
15
24
|
level = @current_admin.role.role_areas.find_by(clazz: '商机管理').level
|
16
25
|
case level
|
17
26
|
when '自己'
|
27
|
+
if permissions.include?("区域管理商机")
|
28
|
+
# 按负责区域查看商机下跟进记录
|
29
|
+
school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id)
|
30
|
+
area_business_ids += Business.joins("JOIN departments ON educode_sales_businesses.department_id = departments.id").where("departments.school_id in (?)", school_ids).pluck(:id)
|
31
|
+
end
|
32
|
+
|
18
33
|
business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
|
19
34
|
@businesses = Business.where("educode_sales_businesses.staff_id = ? OR educode_sales_businesses.id in (?)", @current_admin.id, business_ids)
|
20
35
|
business_ids = @businesses.pluck(:id)
|
21
|
-
@follow_ups = FollowUp.where(business_id: business_ids)
|
36
|
+
@follow_ups = FollowUp.where(business_id: business_ids + area_business_ids)
|
22
37
|
when '区域'
|
23
38
|
school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id) + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
|
24
39
|
business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
|
25
40
|
@businesses = Business.joins("JOIN departments ON educode_sales_businesses.department_id = departments.id").where("departments.school_id in (?) OR educode_sales_businesses.staff_id = #{@current_admin.id} OR educode_sales_businesses.id in (?)", school_ids, business_ids)
|
26
41
|
business_ids = @businesses.pluck(:id)
|
27
|
-
@follow_ups = FollowUp.where(business_id: business_ids)
|
42
|
+
@follow_ups = FollowUp.where(business_id: business_ids + area_business_ids)
|
28
43
|
else
|
29
44
|
@follow_ups = FollowUp.all
|
30
45
|
end
|
@@ -110,7 +125,7 @@ module EducodeSales
|
|
110
125
|
end
|
111
126
|
|
112
127
|
end
|
113
|
-
@business.update(last_follow_up_id: follow_up.id, clazz_id: follow_up.clazz_id)
|
128
|
+
@business.update(last_follow_up_id: follow_up.id, clazz_id: follow_up.clazz_id, p_deploy_time: params[:deploy_time])
|
114
129
|
# 增加o商机编号
|
115
130
|
add_business_number
|
116
131
|
update_department
|
@@ -154,7 +169,7 @@ module EducodeSales
|
|
154
169
|
if follow_up.save
|
155
170
|
# 增加o类商机
|
156
171
|
@business = follow_up.business
|
157
|
-
@business.update(clazz_id: follow_up.clazz_id)
|
172
|
+
@business.update(clazz_id: follow_up.clazz_id, p_deploy_time: params[:deploy_time])
|
158
173
|
add_business_number
|
159
174
|
update_department
|
160
175
|
render_success
|
@@ -284,7 +299,7 @@ module EducodeSales
|
|
284
299
|
end
|
285
300
|
|
286
301
|
def follow_up_params
|
287
|
-
params.permit(:clazz_id, :stage_id, :invitation_at, :reception_at, :total_amount, :actual_amount, :divide_amount, :divide_rate, :budget_amount, :description, :advise, :place_id, :bidded_date, :signed_date, :year, :o_business_deployment)
|
302
|
+
params.permit(:clazz_id, :stage_id, :invitation_at, :reception_at, :total_amount, :actual_amount, :divide_amount, :divide_rate, :budget_amount, :description, :advise, :place_id, :bidded_date, :signed_date, :year, :o_business_deployment, :deploy_time, :rival)
|
288
303
|
end
|
289
304
|
|
290
305
|
# 更新部门和部门下老师用户的状态
|
@@ -82,7 +82,7 @@ module EducodeSales
|
|
82
82
|
|
83
83
|
def create_business_info
|
84
84
|
business = Business.find_by(id: params[:business_id])
|
85
|
-
info = @current_admin.business_infos.
|
85
|
+
info = @current_admin.business_infos.find_or_initialize_by(year: params[:year], business_id: business.id, clazz: params[:clazz])
|
86
86
|
if info.save
|
87
87
|
render_success
|
88
88
|
else
|
@@ -104,7 +104,7 @@ module EducodeSales
|
|
104
104
|
end
|
105
105
|
business_ids = EducodeSales::AssignFollowUp.joins(:follow_up).where(staff_id: @current_admin.id).pluck :business_id
|
106
106
|
@businesses = Business.includes(:department, :last_follow_up).where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", business_ids, @current_admin.id).order(created_at: :desc)
|
107
|
-
@businesses = @businesses.map { |b| [b.name + "(
|
107
|
+
@businesses = @businesses.map { |b| [b.name + "(#{b.department&.school&.name} #{b.department&.name})" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : b.created_at.to_s), b.id] }
|
108
108
|
render layout: false
|
109
109
|
end
|
110
110
|
|
@@ -132,18 +132,36 @@ module EducodeSales
|
|
132
132
|
@business = Business.find_by(id: params[:business_id])
|
133
133
|
business_ids = EducodeSales::AssignFollowUp.joins(:follow_up).where(staff_id: @current_admin.id).pluck :business_id
|
134
134
|
@businesses =Business.includes(:department, :last_follow_up).where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", business_ids, @current_admin.id).order(created_at: :desc)
|
135
|
-
@businesses = @businesses.map { |b| [b.name + "(
|
135
|
+
@businesses = @businesses.map { |b| [b.name + "(#{b.department&.school&.name} #{b.department&.name})" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : b.created_at.to_s), b.id] }
|
136
136
|
render layout: false
|
137
137
|
end
|
138
138
|
|
139
139
|
def new_year
|
140
|
+
@business = Business.find_by(id: params[:business_id])
|
140
141
|
business_ids = EducodeSales::AssignFollowUp.joins(:follow_up).where(staff_id: @current_admin.id).pluck :business_id
|
141
142
|
@businesses =Business.includes(:department, :last_follow_up).where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", business_ids, @current_admin.id).order(created_at: :desc)
|
142
|
-
@businesses = @businesses.map { |b| [b.name + "(
|
143
|
+
@businesses = @businesses.map { |b| [ b.name + "(#{b.department&.school&.name} #{b.department&.name})" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : b.created_at.to_s), b.id] }
|
143
144
|
@clazz = EducodeSales::SalePlan::CLAZZ_NAME
|
144
145
|
render layout: false
|
145
146
|
end
|
146
147
|
|
148
|
+
# 暂时不用
|
149
|
+
def staff_businesses
|
150
|
+
if params[:q].present?
|
151
|
+
business_ids = EducodeSales::AssignFollowUp.joins(:follow_up).where(staff_id: @current_admin.id).pluck :business_id
|
152
|
+
@businesses = Business.includes(:department, :last_follow_up).where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", business_ids, @current_admin.id)
|
153
|
+
if params[:q].present?
|
154
|
+
@businesses = @businesses.where("educode_sales_businesses.name like ?", "%#{params[:q]}%")
|
155
|
+
else
|
156
|
+
@businesses = @businesses.limit(10)
|
157
|
+
end
|
158
|
+
@businesses = @businesses.order(created_at: :desc)
|
159
|
+
|
160
|
+
@businesses = @businesses.map { |b| {name: b.name + "(#{b.department&.school&.name} #{b.department&.name})" + "---" + "最新跟进:" + (b.last_follow_up.present? ? b.last_follow_up.created_at.to_s : b.created_at.to_s), value: b.id} }
|
161
|
+
render json: { data: @businesses, code: 0, msg: "success" }
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
147
165
|
def new_monthly
|
148
166
|
d = @current_admin
|
149
167
|
area_ids = EducodeSales::Common.where(clazz: 'area').ids.sort.to_s
|
@@ -232,6 +250,7 @@ module EducodeSales
|
|
232
250
|
EducodeSales::Recycle.create(source: d, deleter_id: @current_admin.id)
|
233
251
|
end
|
234
252
|
sale_plans.update_all(deleted_at: Time.now)
|
253
|
+
sale_plans.business_infos.delete_all
|
235
254
|
render_success
|
236
255
|
else
|
237
256
|
sale_plan = SalePlan.find(params[:id])
|
@@ -282,30 +301,46 @@ module EducodeSales
|
|
282
301
|
end
|
283
302
|
|
284
303
|
def years_plan
|
304
|
+
@sale_plans = SalePlan.from("(
|
305
|
+
SELECT SUM(last_follow.budget_amount) AS budget_amounts, educode_sales_sale_plans.*, ss.annual,
|
306
|
+
SUM(IF(educode_sales_sale_plans.clazz = 1 AND educode_sales_business_infos.plan_sign_on IS NOT NULL, last_follow.budget_amount, 0)) AS clazz_1,
|
307
|
+
SUM(IF(educode_sales_sale_plans.clazz = 18 and plan_bid_on IS NOT NULL, last_follow.budget_amount, 0)) AS clazz_18,
|
308
|
+
|
309
|
+
(SUM(IF(educode_sales_sale_plans.clazz = 2 AND prepayment_plan_on IS NOT NULL AND check_fee_plan_on IS NOT NULL AND qa_plan_on IS NOT NULL, prepayment_amount, 0)) +
|
310
|
+
SUM(IF(educode_sales_sale_plans.clazz = 2 AND prepayment_plan_on IS NOT NULL AND check_fee_plan_on IS NOT NULL AND qa_plan_on IS NOT NULL, check_fee, 0)) +
|
311
|
+
SUM(IF(educode_sales_sale_plans.clazz = 2 AND prepayment_plan_on IS NOT NULL AND check_fee_plan_on IS NOT NULL AND qa_plan_on IS NOT NULL, qa_amount, 0)) ) AS clazz_2,
|
312
|
+
SUM(IF(educode_sales_sale_plans.clazz = 7, last_follow.budget_amount, 0)) AS clazz_7,
|
313
|
+
|
314
|
+
SUM(IF(last_follow.bidded_date IS NOT NULL, last_follow.actual_amount, 0)) AS finish_bid,
|
315
|
+
SUM(IF(last_follow.signed_date IS NOT NULL, last_follow.actual_amount, 0)) AS finish_sign,
|
316
|
+
SUM(educode_sales_businesses.return_money) AS finish_return_money
|
317
|
+
|
318
|
+
FROM educode_sales_sale_plans
|
319
|
+
JOIN educode_sales_businesses ON educode_sales_businesses.id = educode_sales_sale_plans.business_id
|
320
|
+
LEFT JOIN educode_sales_business_infos ON educode_sales_business_infos.sale_plan_id = educode_sales_sale_plans.id
|
321
|
+
LEFT JOIN educode_sales_follow_ups AS last_follow ON educode_sales_businesses.last_follow_up_id = last_follow.id AND last_follow.deleted_at IS NULL
|
322
|
+
LEFT JOIN educode_sales_assessments_settings AS ss ON ss.staff_id = educode_sales_sale_plans.staff_id
|
323
|
+
AND YEAR(ss.assessment_year) = educode_sales_sale_plans.year AND ss.assessment = educode_sales_sale_plans.clazz
|
324
|
+
WHERE educode_sales_sale_plans.deleted_at IS NULL
|
325
|
+
GROUP BY educode_sales_sale_plans.staff_id, educode_sales_sale_plans.clazz, educode_sales_sale_plans.year
|
326
|
+
) AS educode_sales_sale_plans
|
327
|
+
")
|
285
328
|
if @current_admin.is_admin?
|
286
|
-
@sale_plans = SalePlan
|
329
|
+
# @sale_plans = SalePlan
|
287
330
|
else
|
288
331
|
level = @current_admin.role.role_areas.find_by(clazz: '销售计划').level
|
289
332
|
case level
|
290
333
|
when '自己'
|
291
|
-
@sale_plans =
|
334
|
+
@sale_plans = @sale_plans.where(staff_id: @current_admin.id)
|
292
335
|
when '区域'
|
293
336
|
staff_ids = Staff.joins(user: [user_extension: [department: :school]]).where("schools.province in (?)", @current_admin.areas.pluck(:name)).pluck(:id)
|
294
337
|
business_ids = Business.where(school_id: StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)).pluck(:id)
|
295
|
-
@sale_plans =
|
338
|
+
@sale_plans = @sale_plans.where("educode_sales_sale_plans.staff_id in (?) OR educode_sales_sale_plans.staff_id = ? OR educode_sales_sale_plans.business_id in (?)", staff_ids, @current_admin.id,business_ids)
|
296
339
|
else
|
297
|
-
@sale_plans = SalePlan
|
340
|
+
# @sale_plans = SalePlan
|
298
341
|
end
|
299
342
|
end
|
300
343
|
@sale_plans = @sale_plans.where.not(year: nil)
|
301
|
-
@sale_plans = @sale_plans.select("SUM(last_follow.budget_amount) AS budget_amounts, educode_sales_sale_plans.*, ss.annual")
|
302
|
-
@sale_plans = @sale_plans.joins("
|
303
|
-
JOIN educode_sales_businesses ON educode_sales_businesses.id = educode_sales_sale_plans.business_id
|
304
|
-
LEFT JOIN educode_sales_follow_ups AS last_follow ON educode_sales_businesses.last_follow_up_id = last_follow.id AND last_follow.deleted_at IS NULL
|
305
|
-
LEFT JOIN educode_sales_assessments_settings AS ss ON ss.staff_id = educode_sales_sale_plans.staff_id
|
306
|
-
AND YEAR(ss.assessment_year) = educode_sales_sale_plans.year AND ss.assessment = educode_sales_sale_plans.clazz")
|
307
|
-
|
308
|
-
@sale_plans = @sale_plans.group("educode_sales_sale_plans.staff_id, clazz, year")
|
309
344
|
|
310
345
|
@sale_plans = @sale_plans.where(deleted_at: nil)
|
311
346
|
|
@@ -345,12 +380,26 @@ module EducodeSales
|
|
345
380
|
end
|
346
381
|
|
347
382
|
def edit_bussiness_info_extra
|
348
|
-
@business_info =
|
383
|
+
@business_info = EducodeSales::BusinessInfo.find(params[:id])
|
349
384
|
render layout: false
|
350
385
|
end
|
351
386
|
|
352
387
|
def plan_business_infos
|
353
|
-
|
388
|
+
if params[:q] && params[:q][:year_search].present?
|
389
|
+
@data = EducodeSales::BusinessInfo.where(year: params[:q][:year_search], staff_id: params[:staff_id])
|
390
|
+
else
|
391
|
+
@data = EducodeSales::BusinessInfo.where(year: params[:year], staff_id: params[:staff_id])
|
392
|
+
end
|
393
|
+
|
394
|
+
@data = @data.where.not(sale_plan_id: nil)
|
395
|
+
|
396
|
+
if params[:q] && params[:q][:clazz].present?
|
397
|
+
@data = @data.where(clazz: params[:q][:clazz])
|
398
|
+
end
|
399
|
+
|
400
|
+
if params[:q] && params[:q][:department].present?
|
401
|
+
@data = @data.joins(business: [department: :school]).where("schools.name like ?", "%#{params[:q][:department]}%")
|
402
|
+
end
|
354
403
|
|
355
404
|
if params[:sort].present? && params[:sort][:field]
|
356
405
|
@data = @data.order("#{params[:sort][:field]} #{params[:sort][:order]}")
|
@@ -370,7 +419,7 @@ module EducodeSales
|
|
370
419
|
end
|
371
420
|
|
372
421
|
def update_business_info_extra
|
373
|
-
business_info =
|
422
|
+
business_info = EducodeSales::BusinessInfo.find(params[:id])
|
374
423
|
if business_info.update(update_business_info_extra_params)
|
375
424
|
render_success
|
376
425
|
else
|
@@ -392,6 +441,7 @@ module EducodeSales
|
|
392
441
|
end
|
393
442
|
|
394
443
|
def edit_year_plan
|
444
|
+
@clazz = EducodeSales::SalePlan::CLAZZ_NAME
|
395
445
|
render layout: false
|
396
446
|
end
|
397
447
|
|
@@ -137,5 +137,40 @@ module EducodeSales
|
|
137
137
|
@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 }
|
138
138
|
end
|
139
139
|
|
140
|
+
def list
|
141
|
+
@staffs = EducodeSales::Staff.where.not(id: params[:id]).map { |d| [d.user.real_name, d.id ]}
|
142
|
+
gon.trans_staffs = @staffs.to_h.invert
|
143
|
+
render layout: false
|
144
|
+
end
|
145
|
+
|
146
|
+
def transfer
|
147
|
+
if @current_admin.is_admin?
|
148
|
+
staff = Staff.find(params[:id])
|
149
|
+
to = Staff.find(params[:to_id])
|
150
|
+
staff.businesses.update_all(staff_id: to.id)
|
151
|
+
# 商机
|
152
|
+
staff.follow_ups.update_all(staff_id: to.id)
|
153
|
+
# 销售动态
|
154
|
+
staff.sale_plans.update_all(staff_id: to.id)
|
155
|
+
# 销售计划
|
156
|
+
staff.places.update_all(staff_id: to.id)
|
157
|
+
# 渠道
|
158
|
+
staff.activities.update_all(staff_id: to.id)
|
159
|
+
# 活动
|
160
|
+
staff.teachers.update_all(staff_id: to.id)
|
161
|
+
# 教师
|
162
|
+
staff.teacher_follows.update_all(staff_id: to.id)
|
163
|
+
# 教师动态
|
164
|
+
staff.operation_plans.update_all(staff_id: to.id)
|
165
|
+
# 活动计划
|
166
|
+
|
167
|
+
EducodeSales::Activity.where(sales_id: staff.id).update_all(sales_id: to.id)
|
168
|
+
CustomerExtension.where(staff_id: staff.id).update_all(staff_id: to.id)
|
169
|
+
# 回款计划
|
170
|
+
MoneyPlan.where(staff_id: staff.id).update_all(staff_id: to.id)
|
171
|
+
# 客户
|
172
|
+
end
|
173
|
+
render_success
|
174
|
+
end
|
140
175
|
end
|
141
176
|
end
|
@@ -28,6 +28,7 @@ module EducodeSales
|
|
28
28
|
else
|
29
29
|
@staff_manage = Staff.none
|
30
30
|
end
|
31
|
+
|
31
32
|
@follow_upers = Staff.includes(:user).map { |d| [d.user.real_name, d.id]}
|
32
33
|
@staffs = Staff.includes(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id]}
|
33
34
|
@more = can?(:create, EducodeSales::OperationPlan) || can?(:update, EducodeSales::Teacher) || can?(:destroy, EducodeSales::Teacher)
|
@@ -45,10 +46,16 @@ module EducodeSales
|
|
45
46
|
end
|
46
47
|
format.json do
|
47
48
|
@staff_manages = {}
|
49
|
+
@sales_manages = {}
|
48
50
|
role = EducodeSales::Role.find_by(name: '生态经理')
|
49
51
|
EducodeSales::Common.joins(market_areas: :staff).includes(market_areas: :staff).where(clazz: '区域').where("educode_sales_staffs.role_id = #{role.id}").each do |d|
|
50
52
|
@staff_manages[d.name] = d.market_areas.map { |d| d.staff&.user&.real_name }.uniq.compact
|
51
53
|
end if role
|
54
|
+
|
55
|
+
sales_common = EducodeSales::Common.find_by(clazz: 'staff_type', name: '销售')
|
56
|
+
EducodeSales::Common.joins(market_areas: :staff).includes(market_areas: :staff).where(clazz: '区域').where("educode_sales_staffs.job_type = ?", sales_common.id).each do |d|
|
57
|
+
@sales_manages[d.name] = d.market_areas.map { |d| d.staff&.user&.real_name }.uniq.compact
|
58
|
+
end
|
52
59
|
|
53
60
|
if @current_admin.is_admin?
|
54
61
|
@teachers = Teacher
|
@@ -141,10 +141,20 @@
|
|
141
141
|
},
|
142
142
|
{
|
143
143
|
field: 'key_people',
|
144
|
-
width:
|
144
|
+
width: 100,
|
145
145
|
title: '关键人',
|
146
146
|
templet:'<div><span title="{{d.key_people}}">{{d.key_people}}</span></div>'
|
147
147
|
},
|
148
|
+
{
|
149
|
+
field: 'rival',
|
150
|
+
width: 100,
|
151
|
+
title: '竞争对手',
|
152
|
+
},
|
153
|
+
{
|
154
|
+
field: 'staff_manages',
|
155
|
+
width: 120,
|
156
|
+
title: '销售经理',
|
157
|
+
},
|
148
158
|
{
|
149
159
|
field: 'tel',
|
150
160
|
width: 90,
|
@@ -63,6 +63,14 @@
|
|
63
63
|
id="reception_at_edit" placeholder="请选择日期">
|
64
64
|
</div>
|
65
65
|
</div>
|
66
|
+
<div class="layui-inline">
|
67
|
+
<label class="layui-form-label">部署时间</label>
|
68
|
+
<div class="layui-input-inline">
|
69
|
+
<input type="text" class="layui-input" value="<%= @follow_up.business.p_deploy_time %>" name="deploy_time"
|
70
|
+
id="p_deploy_time" placeholder="请选择日期">
|
71
|
+
</div>
|
72
|
+
</div>
|
73
|
+
|
66
74
|
<br>
|
67
75
|
<div class="layui-inline service_show layui-hide">
|
68
76
|
<label class="layui-form-label required">服务期</label>
|
@@ -133,6 +141,14 @@
|
|
133
141
|
</div>
|
134
142
|
</div>
|
135
143
|
</div>
|
144
|
+
<div class="layui-form-item">
|
145
|
+
<div class="layui-inline">
|
146
|
+
<label class="layui-form-label">竞争对手</label>
|
147
|
+
<div class="layui-input-inline">
|
148
|
+
<input type="text" class="layui-input" name="rival" autocomplete="off" value="<%= @follow_up&.rival%>">
|
149
|
+
</div>
|
150
|
+
</div>
|
151
|
+
</div>
|
136
152
|
<div class="layui-form-item">
|
137
153
|
<label class="layui-form-label">指定跟进人</label>
|
138
154
|
<div class="layui-input-inline" style="">
|
@@ -209,6 +225,9 @@
|
|
209
225
|
laydate.render({
|
210
226
|
elem: '#invitation_at_edit'
|
211
227
|
})
|
228
|
+
laydate.render({
|
229
|
+
elem: '#p_deploy_time'
|
230
|
+
})
|
212
231
|
laydate.render({
|
213
232
|
elem: '#service_time',
|
214
233
|
range: true
|