educode_sales 0.6.1 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/educode_sales/money_plans.png +0 -0
  3. data/app/controllers/educode_sales/businesses_controller.rb +29 -8
  4. data/app/controllers/educode_sales/customers_controller.rb +45 -34
  5. data/app/controllers/educode_sales/follow_ups_controller.rb +1 -1
  6. data/app/controllers/educode_sales/money_plans_controller.rb +65 -0
  7. data/app/controllers/educode_sales/places_controller.rb +5 -1
  8. data/app/controllers/educode_sales/roles_controller.rb +4 -1
  9. data/app/controllers/educode_sales/sale_trends_controller.rb +44 -1
  10. data/app/controllers/educode_sales/staffs_controller.rb +3 -4
  11. data/app/controllers/educode_sales/teachers_controller.rb +13 -2
  12. data/app/models/educode_sales/permission.rb +3 -2
  13. data/app/models/educode_sales/role_area.rb +1 -0
  14. data/app/views/educode_sales/businesses/_follows.html.erb +18 -15
  15. data/app/views/educode_sales/businesses/edit.html.erb +3 -0
  16. data/app/views/educode_sales/businesses/edit_follow_record.html.erb +11 -2
  17. data/app/views/educode_sales/businesses/file.html.erb +8 -4
  18. data/app/views/educode_sales/businesses/index.html.erb +117 -26
  19. data/app/views/educode_sales/businesses/index.json.jbuilder +4 -2
  20. data/app/views/educode_sales/businesses/new_follow_record.html.erb +7 -2
  21. data/app/views/educode_sales/businesses/show_follow.html.erb +2 -1
  22. data/app/views/educode_sales/businesses/time_line.html.erb +1 -1
  23. data/app/views/educode_sales/customers/edit.html.erb +735 -22
  24. data/app/views/educode_sales/customers/edit_follow_record.html.erb +1 -1
  25. data/app/views/educode_sales/customers/index.html.erb +17 -18
  26. data/app/views/educode_sales/customers/index.json.jbuilder +3 -3
  27. data/app/views/educode_sales/customers/new.html.erb +713 -27
  28. data/app/views/educode_sales/customers/new_follow_record.html.erb +1 -1
  29. data/app/views/educode_sales/customers/show_follow.html.erb +1 -1
  30. data/app/views/educode_sales/customers/show_follow_record.html.erb +3 -3
  31. data/app/views/educode_sales/follow_ups/index.json.jbuilder +1 -0
  32. data/app/views/educode_sales/money_plans/index.html.erb +222 -0
  33. data/app/views/educode_sales/money_plans/index.json.jbuilder +21 -0
  34. data/app/views/educode_sales/places/index.html.erb +80 -2
  35. data/app/views/educode_sales/places/index.json.jbuilder +3 -1
  36. data/app/views/educode_sales/plans/_monthPlan.html.erb +2 -1
  37. data/app/views/educode_sales/plans/_weekPlan.html.erb +2 -1
  38. data/app/views/educode_sales/recycles/business.json.jbuilder +2 -2
  39. data/app/views/educode_sales/roles/edit.html.erb +9 -1
  40. data/app/views/educode_sales/sale_trends/trends.html.erb +93 -13
  41. data/app/views/educode_sales/sale_trends/trends.json.jbuilder +3 -14
  42. data/app/views/educode_sales/sales/index.html.erb +25 -17
  43. data/app/views/educode_sales/sales/index.json.jbuilder +17 -7
  44. data/app/views/educode_sales/sales/operations.json.jbuilder +2 -2
  45. data/app/views/educode_sales/teachers/index.html.erb +19 -18
  46. data/app/views/educode_sales/teachers/index.json.jbuilder +1 -1
  47. data/app/views/layouts/educode_sales/application.html.erb +13 -2
  48. data/config/routes.rb +2 -0
  49. data/db/migrate/20210902064109_create_educode_sales_role_permissions.rb +8 -0
  50. data/db/migrate/20211220102720_add_position_to_commons.rb +12 -0
  51. data/db/migrate/20211221075146_add_school_id_to_educode_sales_businesses.rb +8 -0
  52. data/lib/educode_sales/version.rb +1 -1
  53. metadata +8 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88c76bb62d36b9922c99d80e365218b4dbde3bfe9632773d71ba40bdda28ef2f
4
- data.tar.gz: 4ba6723ac69f19bb92c57a876b1e7c7299fc15bf1d213eede7ce215e12a932bc
3
+ metadata.gz: abfb5bbc3cbbe65b1c987c9e1b77bca81d06086e2db8b6c788163fdba557f2ef
4
+ data.tar.gz: 7e2a1aabfab1f07c614a76d65f33560f6da3e7d05200a819c4d7b905c5d976c3
5
5
  SHA512:
6
- metadata.gz: 608ee9cf6238d241410cb879004c9d18d5ee4e2fa346f285a6f81e3391b3438b905997dbc03c5b37c83c1c9dbd5f2cda1c7f11c3c831c3f986ceda2b443fe925
7
- data.tar.gz: 0f5c04324244916fe4a6fd75625076b8ae56bf6398f04676d168b41af251dd66b0db586f53881bbb68ddfaebef7d0ef95d0b47f790b64ed34729c57b5533d856
6
+ metadata.gz: 30bac077609756d5eb7ab205d40f2c3f2b7db4f88797c636038051316c1917af74a88f4cf390878c6b8adc83f4bf4e417d723ef349ecdbfc375a8176e5a3a6a8
7
+ data.tar.gz: 3b4b074197ba779c5b8f8134e97b1633f6173f8ba7a46232d761b132b123b1ffa1ac39fa1b47d484ce82197d060b02dbde8bf8d07fb9c1c5bff1e783d3b485e6
@@ -33,15 +33,25 @@ module EducodeSales
33
33
  format.html do
34
34
  common = Common.find_by(clazz: 'staff_type', name: '销售')
35
35
  @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)
36
+ # @more = can?(:create, EducodeSales::SalePlan) || can?(:update, EducodeSales::Business) || can?(:destroy, EducodeSales::Business) || can?(:show_file, EducodeSales::Business)
37
+ @more = true
37
38
  gon.menus = []
38
39
  gon.place = params[:place_id].present? ? [{ value: params[:place_id], name: EducodeSales::Place.find(params[:place_id]).name }] : []
40
+ gon.business_type = Common.where(clazz: 'business_type').map do |d|
41
+ {value: d.id, name: d.name}
42
+ end
43
+ gon.type = params[:clazz_id].present? ? [{ value: params[:clazz_id], name: Common.find(params[:clazz_id]).name }] : []
44
+ gon.business_step = Common.where(clazz: 'business_step').map do |d|
45
+ {value: d.id, name: d.name}
46
+ end
39
47
  if can?(:create, EducodeSales::SalePlan)
40
48
  gon.menus << { title: '添加周计划', event: 'week' }
41
49
  gon.menus << { title: '添加月计划', event: 'month' }
42
50
  end
43
51
  gon.menus << { title: '跟进时间线', event: 'time_line' }
44
- gon.menus << { title: '附件管理', event: 'file' }
52
+ if can?(:show_file, EducodeSales::Business)
53
+ gon.menus << { title: '附件管理', event: 'file' }
54
+ end
45
55
  if can?(:update, EducodeSales::Business)
46
56
  gon.menus << { title: '编辑', event: 'edit' }
47
57
  end
@@ -76,7 +86,9 @@ module EducodeSales
76
86
  b_id = Common.find_by(extras: EducodeSales::Common::BTYPE)&.id
77
87
  c_id = Common.find_by(extras: EducodeSales::Common::CTYPE)&.id
78
88
  d_id = Common.find_by(extras: EducodeSales::Common::DTYPE)&.id
79
- ids = [a_id ,b_id ,c_id ,d_id]
89
+ e_id = Common.find_by(extras: EducodeSales::Common::ETYPE)&.id
90
+ o_id = Common.find_by(extras: EducodeSales::Common::OTYPE)&.id
91
+ ids = [a_id ,b_id ,c_id ,d_id ,e_id ,o_id]
80
92
  @businesses = @businesses.joins("
81
93
  JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
82
94
  ").where("educode_sales_follow_ups.clazz_id in (?)",ids)
@@ -135,12 +147,12 @@ module EducodeSales
135
147
  if params[:q].present? && params[:q][:business_type].present?
136
148
  @businesses = @businesses.joins("
137
149
  JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
138
- ").where("educode_sales_follow_ups.clazz_id = ?", params[:q][:business_type])
150
+ ").where("educode_sales_follow_ups.clazz_id in (?)", params[:q][:business_type].split(",").map(&:to_i))
139
151
  end
140
152
  if params[:q].present? && params[:q][:business_step].present?
141
153
  @businesses = @businesses.joins("
142
154
  JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
143
- ").where("educode_sales_follow_ups.stage_id = ?", params[:q][:business_step])
155
+ ").where("educode_sales_follow_ups.stage_id in (?)", params[:q][:business_step].split(",").map(&:to_i))
144
156
  end
145
157
  if params[:q].present? && params[:q][:place_id].present?
146
158
  @businesses = @businesses.joins("
@@ -172,7 +184,14 @@ module EducodeSales
172
184
 
173
185
  if params[:q].present? && params[:q][:date].present?
174
186
  date = params[:q][:date].split(" - ")
175
- @businesses = @businesses.where("educode_sales_businesses.created_at > ? AND educode_sales_businesses.created_at < ?", date[0], date[1])
187
+ @businesses = @businesses.where("educode_sales_businesses.created_at > ? AND educode_sales_businesses.created_at < ?", date[0], date[1] + '23:59:59')
188
+ end
189
+
190
+ if params[:q].present? && params[:q][:invitation_at].present?
191
+ date = params[:q][:invitation_at].split(" - ")
192
+ @businesses = @businesses.joins("
193
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
194
+ ").where("educode_sales_follow_ups.invitation_at > ? AND educode_sales_follow_ups.invitation_at < ?", date[0] + '00:00:00', date[1] + '23:59:59')
176
195
  end
177
196
 
178
197
  if params[:sort].present? && params[:sort][:field]
@@ -191,7 +210,9 @@ module EducodeSales
191
210
  last_follow.reception_at,
192
211
  last_follow.bidded_date,
193
212
  last_follow.signed_date,
213
+ last_follow.created_at as latest_time,
194
214
  last_follow.actual_amount,
215
+ (last_follow.actual_amount - educode_sales_businesses.return_money) as wait_return_money,
195
216
  last_follow.total_amount").joins("
196
217
  LEFT JOIN educode_sales_follow_ups AS last_follow ON educode_sales_businesses.last_follow_up_id = last_follow.id
197
218
  ").page(params[:page]).per(params[:limit])
@@ -201,7 +222,7 @@ module EducodeSales
201
222
 
202
223
  def create
203
224
  department = Department.find(params[:department_id])
204
- business = @current_admin.businesses.build(name: params[:name], department_id: department.id, source: params[:source])
225
+ business = @current_admin.businesses.build(name: params[:name], department_id: department.id, source: params[:source], school_id: department.school_id)
205
226
  if business.save
206
227
  render_success
207
228
  else
@@ -223,7 +244,7 @@ module EducodeSales
223
244
  def update
224
245
  business = Business.find(params[:id])
225
246
  department = Department.find(params[:department_id])
226
- if business.update(name: params[:name], department_id: department.id, source: params[:source])
247
+ if business.update(name: params[:name], department_id: department.id, source: params[:source], school_id: department.school_id)
227
248
  render_success
228
249
  else
229
250
  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
- # if params[:q].present? && params[:q][:date].present?
75
- # department_ids =
76
- # business_ids = EducodeSales::Business.where(department_id: department_ids).ids
77
- # follow_ups = EducodeSales::FollowUp.where(business_id: business_ids)
78
- # customer_follows = EducodeSales::CustomerFollow.where(school_id: d.id)
79
- # a_last_follow_time = follow_ups.last&.created_at&.to_s(:date)
80
- # b_last_follow_time = customer_follows.last&.created_at&.to_s(:date)
81
- # if a_last_follow_time.present? && b_last_follow_time.present?
82
- # json.last_follow_time a_last_follow_time < b_last_follow_time ? b_last_follow_time : a_last_follow_time
83
- # else
84
- # json.last_follow_time a_last_follow_time || b_last_follow_time
85
- # end
86
- # date = params[:q][:date].split(" - ")
87
- # @customers = @customers.where("educode_sales_businesses.created_at > ? AND educode_sales_businesses.created_at < ?", date[0], date[1])
88
- # end
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!(school_property_params)
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!(school_property_params)
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.require(:school).permit(:project_985, :project_211, :regular_college, :junior_college, :secondary_school, :military_school, :enterprise)
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.require(:school).permit(:name, :province, :city, :address)
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,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.staff_id)
23
+ when '区域'
24
+ a_ids = MoneyPlan.where(follow_up_id: follow_up_ids).where(staff_id: @current_admin.staff_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
@@ -8,7 +8,11 @@ module EducodeSales
8
8
  format.html do
9
9
  end
10
10
  format.json do
11
- @places = Place.page(params[:page]).per(params[:limit])
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 != ? AND educode_sales_follow_ups.clazz_id != ?", x, o).sum(:total_amount).round(2)
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
- # @schools = EducodeSales::Business.joins(:last_follow_up, :department).where("educode_sales_follow_ups.staff_id = #{staff.id}").group("school_id").select("school_id, max(educode_sales_follow_ups.updated_at) AS updated_at").page(params[:page]).per(params[:limit])
71
- @schools = EducodeSales::Teacher.joins(:follow_up, :department).where("educode_sales_teacher_follows.staff_id = #{staff.id}").group("school_id").select("school_id, max(educode_sales_teacher_follows.updated_at) AS updated_at")+EducodeSales::Business.joins(:last_follow_up, :department).where("educode_sales_follow_ups.staff_id = #{staff.id}").group("school_id").select("school_id, max(educode_sales_follow_ups.updated_at) AS updated_at")
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(:last_follow_up, [department: :school]).where("educode_sales_follow_ups.staff_id = #{staff.id}").select("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.name, schools.name AS school, educode_sales_teacher_follows.updated_at")
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.order("educode_sales_teachers.created_at desc").page(params[:page]).per(params[:limit])
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
- '市场态势': 'market',
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
@@ -9,6 +9,7 @@ module EducodeSales
9
9
  '教师运营': 'Teacher',
10
10
  '运营计划': 'Operation',
11
11
  '客户管理': 'Customer',
12
+ '回款管理': 'MoneyPlan'
12
13
  }
13
14
  end
14
15
  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: 'advise',
103
+ field: 'business',
101
104
  width: 120,
102
- title: '团队建议',
103
- templet:'<div><span title="{{d.advise}}">{{d.advise}}</span></div>'
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>
@@ -69,12 +69,14 @@
69
69
  <div class="layui-input-inline">
70
70
  <input name="total_amount" type="number" class="layui-input" value="<%= @follow_up.total_amount %>">
71
71
  </div>
72
- </div>
72
+ 客户采购支出的费用。总额的生命历程:1.在最初阶段,是商机的预算总额;2.在挂网阶段,是项目的挂网预算总额;3.在中标阶段,是项目的中标总额。 </div>
73
+ <br>
73
74
  <div class="layui-inline">
74
75
  <label class="layui-form-label">合同额(万)</label>
75
76
  <div class="layui-input-inline">
76
77
  <input name="actual_amount" type="number" class="layui-input" placeholder="本单位的签单金额" value="<%= @follow_up.actual_amount %>">
77
78
  </div>
79
+ 客户签给头歌的费用。合同额的生命历程:1.在中标之前,合同额都是0;2.在中标之后,实际与头歌签合同的金额。
78
80
  </div>
79
81
  <br>
80
82
  <div class="layui-inline place_select">
@@ -82,7 +84,9 @@
82
84
  <div class="layui-input-inline" style="z-index: 101">
83
85
  <div id="edit_place" style="width: 190px;"></div>
84
86
  </div>
87
+ 总额里,渠道拿到的部分。
85
88
  </div>
89
+ <br>
86
90
  <div class="layui-inline">
87
91
  <label class="layui-form-label">渠道分成(万)</label>
88
92
  <div class="layui-input-inline">
@@ -95,7 +99,8 @@
95
99
  <div class="layui-input-inline">
96
100
  <input type="text" class="layui-input" name="year" lay-verify="required" autocomplete="off" id="edit_year"
97
101
  value="<%= @follow_up&.year%>"
98
- placeholder="请选择年度"> </div>
102
+ placeholder="请选择年度">
103
+ </div>
99
104
  </div>
100
105
  </div>
101
106
  <div class="layui-form-item">
@@ -103,6 +108,10 @@
103
108
  <div class="layui-input-inline">
104
109
  <div id="edit_assign_follow" style="width: 512px;"></div>
105
110
  </div>
111
+ <div class="layui-inline" style="padding: 9px 15px">
112
+ <label class="layui-form-label" style="padding-left: 220px"></label>
113
+ 指定跟进人和商机创建者,同时拥有对该商机的管理权限
114
+ </div>
106
115
  </div>
107
116
  <div class="layui-form-item layui-form-text">
108
117
  <label class="layui-form-label required">最新进展</label>