educode_sales 0.9.73 → 0.9.74

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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/educode_sales/contracts_controller.rb +309 -0
  3. data/app/controllers/educode_sales/follow_ups_controller.rb +1 -1
  4. data/app/controllers/educode_sales/home_controller.rb +7 -0
  5. data/app/controllers/educode_sales/ideas_controller.rb +146 -76
  6. data/app/controllers/educode_sales/roles_controller.rb +2 -1
  7. data/app/controllers/educode_sales/upload_files_controller.rb +3 -0
  8. data/app/models/educode_sales/assign_staff.rb +6 -0
  9. data/app/models/educode_sales/contract_date_list.rb +6 -0
  10. data/app/models/educode_sales/follow_up.rb +6 -0
  11. data/app/models/educode_sales/idea.rb +16 -5
  12. data/app/models/educode_sales/idea_follow.rb +11 -0
  13. data/app/models/educode_sales/permission.rb +2 -1
  14. data/app/models/educode_sales/role_area.rb +2 -1
  15. data/app/views/educode_sales/businesses/_contract_list.html.erb +160 -0
  16. data/app/views/educode_sales/contracts/_follows.html.erb +323 -0
  17. data/app/views/educode_sales/contracts/_list.html.erb +596 -0
  18. data/app/views/educode_sales/contracts/follow_ups.json.jbuilder +23 -0
  19. data/app/views/educode_sales/contracts/index.html.erb +50 -0
  20. data/app/views/educode_sales/contracts/index.json.jbuilder +74 -0
  21. data/app/views/educode_sales/contracts/list.js.erb +1 -0
  22. data/app/views/educode_sales/contracts/new_follow_up.html.erb +671 -0
  23. data/app/views/educode_sales/home/staff_business.json.jbuilder +9 -0
  24. data/app/views/educode_sales/idea_recycles/detail.html.erb +4 -4
  25. data/app/views/educode_sales/idea_recycles/index.html.erb +5 -5
  26. data/app/views/educode_sales/ideas/_follows.html.erb +258 -0
  27. data/app/views/educode_sales/ideas/_index.html.erb +544 -0
  28. data/app/views/educode_sales/ideas/detail.html.erb +7 -7
  29. data/app/views/educode_sales/ideas/edit.html.erb +77 -15
  30. data/app/views/educode_sales/ideas/files.html.erb +157 -0
  31. data/app/views/educode_sales/ideas/files.json.jbuilder +13 -0
  32. data/app/views/educode_sales/ideas/follow_ups.json.jbuilder +14 -0
  33. data/app/views/educode_sales/ideas/index.html.erb +12 -353
  34. data/app/views/educode_sales/ideas/index.json.jbuilder +7 -1
  35. data/app/views/educode_sales/ideas/new.html.erb +81 -25
  36. data/app/views/educode_sales/ideas/new_follow_up.html.erb +105 -0
  37. data/app/views/educode_sales/ideas/search_new.html.erb +1 -1
  38. data/app/views/educode_sales/ideas/show_schools.html.erb +84 -0
  39. data/app/views/educode_sales/ideas/show_schools.json.jbuilder +12 -0
  40. data/app/views/educode_sales/ideas/show_teachers.html.erb +372 -0
  41. data/app/views/educode_sales/ideas/upload_file.html.erb +43 -0
  42. data/app/views/educode_sales/projects/detail.html.erb +1 -1
  43. data/app/views/educode_sales/projects/edit.html.erb +1 -1
  44. data/app/views/educode_sales/roles/edit.html.erb +16 -0
  45. data/app/views/layouts/educode_sales/application.html.erb +5 -5
  46. data/config/routes.rb +19 -0
  47. data/db/migrate/20230227061043_create_educode_sales_ideas.rb +2 -2
  48. data/db/migrate/20230430023424_add_plan_signed_date_to_follow_ups.rb +21 -0
  49. data/db/migrate/20230430040332_create_educode_sales_contract_date_lists.rb +15 -0
  50. data/db/migrate/20230430104708_create_idea_follows.rb +25 -0
  51. data/db/migrate/20230430121335_add_permissions_for_ideas.rb +16 -0
  52. data/db/migrate/20230430134710_create_educode_sales_assign_staffs.rb +11 -0
  53. data/lib/educode_sales/version.rb +1 -1
  54. metadata +30 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd2b28526eb6deff3149781638110e6f86c717287996bf7740437727adfd2ee3
4
- data.tar.gz: cd3c64540eed97347f0f5b640136cc2fab13d74635246d54d5ca1e95dc1b4a43
3
+ metadata.gz: 49bce310f13d0fc4f79490b47fb3dd691cb80447e2095e8a120746f012dc5f7a
4
+ data.tar.gz: eb98ae1ee690e78c4cc71f7b61256d8b82de70137aeca24ee267f44863d8854a
5
5
  SHA512:
6
- metadata.gz: f07f190aa90d48f53aa734204c86c77f7caa7fd3a374b71bd4b6a8080428542354d67b9eefd4037490da5b3784b3219fcc3286d1cba6dd1279489e6a3edabb3f
7
- data.tar.gz: 27b899f64fe009157232ccaf573e83f4562a5496fbb69bdb5650105df89ca8599b26715c22e70af9aeff1bf355f75fcaab5ff8ef6768371ddf48ec35d85efab5
6
+ metadata.gz: 236e971030f94a6b56eb815808bcdbc2095e2ac098c4058f201fe5460c0489017a93d76e414de6516648e8d4e20916f7fc72c97911ef43b8393950b4e7cd8041
7
+ data.tar.gz: ad2389705947bba8ed007bf0a077bfd445f88d19bece5f09b94fa8662eb354b4989fb91137735c4d76a1640f4094cb369b1eff5e99df5b652eea06931a594c3e
@@ -0,0 +1,309 @@
1
+ require_dependency "educode_sales/application_controller"
2
+
3
+ module EducodeSales
4
+ class ContractsController < ApplicationController
5
+ def index
6
+ authorize! :read_contract, Business
7
+ respond_to do |format|
8
+ format.html do
9
+ common = Common.find_by(clazz: 'staff_type', name: '销售')
10
+ staffs = Staff.joins(:user).where(job_type: common.id).where.not(role_id: 11)
11
+ @staffs = staffs.map { |d| [d.user.real_name, d.id]}
12
+ gon.staffs = staffs.map { |d| {name: d.user.real_name, value: d.id } }
13
+ gon.place = params[:place_id].present? ? [{ value: params[:place_id], name: EducodeSales::Place.find(params[:place_id]).name }] : []
14
+ gon.staffs = staffs.map { |d| {name: d.user.real_name, value: d.id } }
15
+
16
+ bussiness_type = []
17
+ if params[:type]
18
+ # 项目类型
19
+ bussiness_type = EducodeSales::Business.include_types(params[:type]) || []
20
+ end
21
+
22
+ business_step = []
23
+ if params[:step]
24
+ # 项目阶段
25
+ business_step = EducodeSales::Business.include_steps(params[:step]) || []
26
+ end
27
+
28
+
29
+ gon.business_type = Common.where(clazz: 'business_type').map do |d|
30
+ {value: d.id, name: d.name, selected: bussiness_type.include?(d.extras)}
31
+ end
32
+
33
+ gon.business_step = Common.where(clazz: 'business_step', name: ['已中标', '已签单', '已验收', '回款中', '服务中', '已结束']).order("position").map do |d|
34
+ {value: d.id, name: d.name, selected: business_step.include?(d.name)}
35
+ end
36
+ end
37
+ format.json do
38
+ @businesses = Business
39
+ contract_ids = Common.where(clazz: '商机阶段', name: ['已中标', '已签单', '已验收', '回款中', '服务中', '已结束']).pluck(:id)
40
+ @businesses = @businesses.joins("
41
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
42
+ ").where("educode_sales_follow_ups.stage_id in (?)", contract_ids)
43
+
44
+ if @current_admin.is_admin?
45
+ @businesses = @businesses
46
+ else
47
+ level = @current_admin.role.role_areas.find_by(clazz: '合同管理').level
48
+ case level
49
+ when '自己'
50
+ @businesses = @businesses.where("educode_sales_businesses.staff_id = ?", @current_admin.id)
51
+ when '区域'
52
+ school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id) + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
53
+ business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
54
+ @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)
55
+ business_ids = @businesses.pluck(:id)
56
+ @businesses = @businesses.where(business_id: business_ids)
57
+ end
58
+ end
59
+
60
+
61
+ if params[:q] && params[:q][:signed_date].present?
62
+ date = params[:q][:signed_date].split(" - ")
63
+ @businesses = @businesses.joins("
64
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
65
+ ").where("educode_sales_follow_ups.signed_date >= ? AND educode_sales_follow_ups.signed_date <= ?", date[0], date[1])
66
+ end
67
+
68
+ if params[:q]&& params[:q][:date_at].present?
69
+ date = params[:q][:date_at].split(" - ")
70
+ x_id = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
71
+ @businesses = @businesses.joins(follow_ups: :money_plans).where("educode_sales_follow_ups.clazz_id != ?", x_id).where.not("educode_sales_money_plans.clazz!= 1").where("educode_sales_money_plans.date_at >= ? AND educode_sales_money_plans.date_at <= ? ", date[0] + " 00:00:00", date[1] + " 23:59:59").distinct
72
+ end
73
+
74
+ if params[:q] && params[:q][:bidded_date].present?
75
+ date = params[:q][:bidded_date].split(" - ")
76
+ @businesses = @businesses.joins("
77
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
78
+ ").where("educode_sales_follow_ups.bidded_date >= ? AND educode_sales_follow_ups.bidded_date <= ?", date[0], date[1])
79
+ end
80
+
81
+
82
+ if params[:q].present? && params[:q][:name].present?
83
+ @businesses = @businesses.where("educode_sales_businesses.name like ?", "%#{params[:q][:name]}%")
84
+ end
85
+ if params[:q].present? && params[:q][:department].present?
86
+ departments_ids = Department.joins(:school).where("schools.name like ?", "%#{params[:q][:department]}%").pluck(:id)
87
+ @businesses = @businesses.joins(:department).where("departments.id in (?)", departments_ids)
88
+ end
89
+ if params[:q].present? && params[:q][:staff_id].present?
90
+ 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
91
+ part_b_ids = @businesses.where("educode_sales_businesses.last_follow_up_id is not null").joins("
92
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
93
+ ").where("educode_sales_follow_ups.staff_id = ?", params[:q][:staff_id]).ids
94
+ business_ids = part_a_ids + part_b_ids
95
+ @businesses = EducodeSales::Business.where(id:business_ids)
96
+ end
97
+ if params[:q].present? && params[:q][:business_type].present?
98
+ @businesses = @businesses.where("educode_sales_businesses.clazz_id in (?)", params[:q][:business_type].split(",").map(&:to_i))
99
+ end
100
+
101
+ if params[:q].present? && params[:q][:business_step].present?
102
+ @businesses = @businesses.joins("
103
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
104
+ ").where("educode_sales_follow_ups.stage_id in (?)", params[:q][:business_step].split(",").map(&:to_i))
105
+ end
106
+ if params[:q].present? && params[:q][:place_id].present?
107
+ @businesses = @businesses.joins("
108
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
109
+ ").where("educode_sales_follow_ups.place_id = ?", params[:q][:place_id])
110
+ end
111
+ if params[:q].present? && params[:q][:business_year].present?
112
+ @businesses = @businesses.joins("
113
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
114
+ ").where("educode_sales_follow_ups.year = ?", params[:q][:business_year])
115
+ end
116
+
117
+ if params[:q].present? && params[:q][:year].present?
118
+ @businesses = @businesses.joins("
119
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
120
+ ").where("educode_sales_follow_ups.year <= ?", params[:q][:year])
121
+ end
122
+
123
+ if params[:q].present? && params[:q][:o_business_deployment].present?
124
+ @businesses = @businesses.joins("
125
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
126
+ ").where("educode_sales_follow_ups.o_business_deployment = ?", params[:q][:o_business_deployment])
127
+ end
128
+
129
+ if params[:q].present? && params[:q][:area].present?
130
+ area = EducodeSales::Common.find(params[:q][:area]).name
131
+ if @current_admin.is_admin?
132
+ @businesses = @businesses.joins("
133
+ JOIN departments ON educode_sales_businesses.department_id = departments.id
134
+ JOIN schools ON departments.school_id = schools.id
135
+ ").where("province = ?", area)
136
+ else
137
+ level = @current_admin.role.role_areas.find_by(clazz: '商机管理').level
138
+ if level == "区域"
139
+ @businesses = @businesses.joins("
140
+ JOIN schools ON departments.school_id = schools.id
141
+ ").where("province = ?", area)
142
+ else
143
+ @businesses = @businesses.joins("
144
+ JOIN departments ON educode_sales_businesses.department_id = departments.id
145
+ JOIN schools ON departments.school_id = schools.id
146
+ ").where("province = ?", area)
147
+ end
148
+ end
149
+ end
150
+
151
+ if params[:q].present? && params[:q][:date].present?
152
+ date = params[:q][:date].split(" - ")
153
+ @businesses = @businesses.where("educode_sales_businesses.created_at > ? AND educode_sales_businesses.created_at < ?", date[0], date[1] + '23:59:59')
154
+ end
155
+
156
+ if params[:q].present? && params[:q][:sales_staff_id].present?
157
+ # 销售经理
158
+ @businesses = @businesses.joins("LEFT JOIN educode_sales_assign_follow_ups ON educode_sales_assign_follow_ups.follow_up_id = educode_sales_businesses.last_follow_up_id").
159
+ 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][:sales_staff_id], params[:q][:sales_staff_id])
160
+
161
+ end
162
+
163
+ if params[:q].present? && params[:q][:after_sales_staff_id].present?
164
+ # 售后工程师
165
+ @businesses = @businesses.joins("LEFT JOIN educode_sales_assign_staffs ON educode_sales_assign_staffs.sourcable_type = 'EducodeSales::FollowUp' AND educode_sales_assign_staffs.sourcable_id = educode_sales_businesses.last_follow_up_id").
166
+ where("educode_sales_assign_staffs.staff_id = ?", params[:q][:after_sales_staff_id])
167
+
168
+ end
169
+
170
+ # 商机变化
171
+ if params[:q][:clazz_changes].present?
172
+ clazz_changes = EducodeSales::BusinessClazzChange.clazz_changes_value[params[:q][:clazz_changes].to_s]
173
+ @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)
174
+ end
175
+
176
+ if params[:sort].present? && params[:sort][:field]
177
+ if params[:sort][:field] == "service_end_time"
178
+ @businesses = @businesses.order("service_time_long #{params[:sort][:order]}")
179
+ else
180
+ @businesses = @businesses.order("#{params[:sort][:field]} #{params[:sort][:order]}")
181
+ end
182
+ else
183
+ @businesses = @businesses.order("educode_sales_businesses.created_at desc")
184
+ end
185
+
186
+
187
+ @businesses = @businesses.select("
188
+ distinct
189
+ educode_sales_businesses.*,
190
+ last_follow.invitation_at,
191
+ last_follow.budget_amount,
192
+ last_follow.o_business_deployment,
193
+ last_follow.service_time_long,
194
+ last_follow.service_end_time,
195
+ last_follow.service_start_time,
196
+ last_follow.reception_at,
197
+ last_follow.bidded_date,
198
+ last_follow.signed_date,
199
+ last_follow.year,
200
+ last_follow.created_at as latest_time,
201
+ last_follow.actual_amount,
202
+ last_follow.divide_rate,
203
+ last_follow.divide_amount,
204
+ (last_follow.total_amount - last_follow.actual_amount) as divide_money,
205
+ (last_follow.actual_amount - educode_sales_businesses.return_money) as wait_return_money,
206
+ last_follow.total_amount,
207
+ total_follow_ups.follow_ups_counts
208
+ ").joins("
209
+ 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
210
+ LEFT JOIN (
211
+ SELECT COUNT(*) AS follow_ups_counts, educode_sales_follow_ups.business_id
212
+ FROM educode_sales_follow_ups
213
+ WHERE educode_sales_follow_ups.deleted_at IS NULL
214
+ GROUP BY educode_sales_follow_ups.business_id
215
+ ) AS total_follow_ups ON educode_sales_businesses.id = total_follow_ups.business_id
216
+ ").includes(:users, last_follow_up: [:clazz, :assign_follow_ups]).page(params[:page]).per(params[:limit])
217
+
218
+
219
+ end
220
+ end
221
+ end
222
+
223
+ def list
224
+ common = Common.find_by(clazz: 'staff_type', name: '销售')
225
+ staffs = Staff.joins(:user).where(job_type: common.id).where.not(role_id: 11)
226
+ @staffs = staffs.map { |d| [d.user.real_name, d.id]}
227
+ end
228
+
229
+ def new_follow_up
230
+ @business = Business.find(params[:id])
231
+ @last_follow_up = @business.last_follow_up
232
+ @deployment_type = EducodeSales::FollowUp::BUSINESS_DEPLOYMENT
233
+ render layout: false
234
+ end
235
+
236
+
237
+ def follow_ups
238
+ authorize! :read_contract, Business
239
+ contract_ids = Common.where(clazz: '商机阶段', name: ['已中标', '已签单', '已验收', '回款中', '服务中', '已结束']).pluck(:id)
240
+ @follow_ups = FollowUp.joins("
241
+ JOIN educode_sales_businesses ON educode_sales_follow_ups.business_id = educode_sales_businesses.id
242
+ ").where("educode_sales_follow_ups.stage_id in (?)", contract_ids)
243
+
244
+ if @current_admin.is_admin?
245
+ @follow_ups = @follow_ups
246
+ else
247
+ level = @current_admin.role.role_areas.find_by(clazz: '合同管理').level
248
+ case level
249
+ when '自己'
250
+ @follow_ups = @follow_ups.where("educode_sales_follow_ups.staff_id = ?", @current_admin.id)
251
+ when '区域'
252
+ school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id) + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
253
+ business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
254
+ @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)
255
+ business_ids = @businesses.pluck(:id)
256
+ @follow_ups = @follow_ups.where(business_id: business_ids)
257
+ end
258
+ end
259
+ if params[:q].present? && params[:q][:name].present?
260
+ @follow_ups = @follow_ups.joins(:business).where("educode_sales_businesses.name LIKE ?", "%#{params[:q][:name]}%")
261
+ end
262
+ if params[:q].present? && params[:q][:follows_date].present?
263
+ date = params[:q][:follows_date].split(" - ")
264
+ @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')
265
+ end
266
+ if params[:q].present? && params[:q][:staff_id].present?
267
+ @follow_ups = @follow_ups.where(staff_id: params[:q][:staff_id])
268
+ end
269
+ if params[:q].present? && params[:q][:department].present?
270
+ departments_ids = Department.joins(:school).where("schools.name like ?", "%#{params[:q][:department]}%").pluck(:id)
271
+ @follow_ups = @follow_ups.joins(business: :department).where("departments.id in (?)", departments_ids)
272
+ end
273
+ if params[:q].present? && params[:q][:area].present?
274
+ p = EducodeSales::Common.find(params[:q][:area]).name
275
+ @follow_ups = @follow_ups.joins(business: :department).joins("
276
+ JOIN schools ON departments.school_id = schools.id
277
+ ").where("province = ?", p)
278
+ end
279
+
280
+ if params[:q].present? && params[:q][:description].present?
281
+ @follow_ups = @follow_ups.joins(:business).joins("JOIN educode_sales_businesses ON educode_sales_businesses.id = educode_sales_follow_ups.business_id
282
+ ").where("educode_sales_follow_ups.description LIKE ?" ,"%#{params[:q][:description]}%")
283
+
284
+ end
285
+
286
+ @follow_ups = @follow_ups.includes(:staff, :clazz, :stage, key_person: :teacher, business: [department: :school])
287
+
288
+ if params[:sort].present? && params[:sort][:field]
289
+ @follow_ups = @follow_ups.order("#{params[:sort][:field]} #{params[:sort][:order]}")
290
+ else
291
+ @follow_ups = @follow_ups.order("educode_sales_follow_ups.created_at desc")
292
+ end
293
+ @follow_ups = @follow_ups.page(params[:page]).per(params[:limit])
294
+ end
295
+
296
+ def add_follow_ups
297
+ p params["1_promise_date"]
298
+ p params["1_promise_date"].keys
299
+ params["1_promise_date"].each do |d, v|
300
+ p '-----22-'
301
+ p d
302
+ p v
303
+ end
304
+
305
+ render_success
306
+ end
307
+
308
+ end
309
+ end
@@ -16,7 +16,7 @@ module EducodeSales
16
16
  area_business_ids = []
17
17
  if permissions.include?("专项管理商机")
18
18
  # 按客户类型查看商机下跟进记录
19
- school_tag_ids = EducodeSales::StaffSchoolTag.where(staff_id: 10009).pluck :school_tag_id
19
+ school_tag_ids = EducodeSales::StaffSchoolTag.where(staff_id: @current_admin.id).pluck :school_tag_id
20
20
  school_ids = SchoolTagMiddle.where(school_tag_id: school_tag_ids).pluck :school_id
21
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
22
  end
@@ -70,6 +70,13 @@ module EducodeSales
70
70
  end
71
71
  end
72
72
 
73
+ def staff_business
74
+ @schools = Business.all
75
+ if params[:q].present?
76
+ @schools = @schools.where("name like :q ", q: "%#{params[:q]}%").page(params[:page]).per(10)
77
+ end
78
+ end
79
+
73
80
  def staff_departments
74
81
  @departments = Department.where(school_id: params[:school_id])
75
82
  if params[:q].present?
@@ -10,12 +10,37 @@ module EducodeSales
10
10
  format.html do
11
11
  staff_ids = EducodeSales::Idea.all.pluck(:staff_id)
12
12
  creator_ids = EducodeSales::Idea.all.pluck(:creator_id)
13
+ sale_staff_ids = EducodeSales::Idea.all.pluck(:sale_staff_id)
13
14
  @creator_arr = EducodeSales::Staff.joins(:user).where(id: creator_ids).pluck("concat(users.lastname,users.firstname)", :id)
14
15
  @staff_arr = EducodeSales::Staff.joins(:user).where(id: staff_ids).pluck("concat(users.lastname,users.firstname)", :id)
16
+ @sale_staff_arr = EducodeSales::Staff.joins(:user).where(id: sale_staff_ids).pluck("concat(users.lastname,users.firstname)", :id)
15
17
  end
16
18
  format.json do
17
- @ideas = Idea.not_deleted
19
+ @ideas = params[:is_deleted].to_s == "true" ? Idea.deleted : Idea.not_deleted
18
20
 
21
+ if @current_admin.is_admin?
22
+ @ideas = @ideas
23
+ else
24
+ level = @current_admin.role.role_areas.find_by(clazz: '方案管理').try(:level)
25
+ case level
26
+ when '自己'
27
+ # business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
28
+ # @businesses = Business.where("educode_sales_businesses.staff_id = ? OR educode_sales_businesses.id in (?)", @current_admin.id, business_ids)
29
+ idea_ids = Idea.all.pluck(:other_staff_ids).flatten.uniq
30
+ @ideas = Idea.where("educode_sales_ideas.staff_id = ? OR educode_sales_ideas.id in (?)", @current_admin.id, idea_ids)
31
+ when '区域'
32
+ # 查看区域商机,需要排除掉其它人员手上的监管学校
33
+ other_staff_school_id = EducodeSales::StaffSchool.where.not(staff_id: @current_admin.id).where("school_id IN (SELECT school_id FROM educode_sales_staff_schools WHERE staff_id = #{@current_admin.id}) IS NOT TRUE").distinct.pluck :school_id
34
+
35
+ school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id) + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id) - other_staff_school_id
36
+ idea_ids = Idea.all.pluck(:other_staff_ids).flatten.uniq
37
+ @ideas = @ideas.joins(department: :school).where("schools.id in (?) OR educode_sales_ideas.staff_id = ? OR educode_sales_ideas.id in (?)", school_ids, @current_admin.id, idea_ids)
38
+ else
39
+ @ideas = @ideas
40
+ end
41
+ end
42
+
43
+ @is_deleted = params[:is_deleted].to_s == "true"
19
44
  if params[:q] && params[:q][:created_at].present?
20
45
  date = params[:q][:created_at].split(" - ")
21
46
  @ideas = @ideas.where("educode_sales_ideas.created_at >= ? AND educode_sales_ideas.created_at <= ?", date[0] + " 00:00:00", date[1] + " 23:59:59")
@@ -32,6 +57,10 @@ module EducodeSales
32
57
  if params[:q].present? && params[:q][:staff_id].present?
33
58
  @ideas = @ideas.where("educode_sales_ideas.staff_id = ?", params[:q][:staff_id].to_i)
34
59
  end
60
+ if params[:q].present? && params[:q][:search_sale_staff_id].present?
61
+ @ideas = @ideas.where("educode_sales_ideas.sale_staff_id = ?", params[:q][:search_sale_staff_id].to_i)
62
+ end
63
+
35
64
  if params[:q].present? && params[:q][:status].present?
36
65
  @ideas = @ideas.where(status: params[:q][:status])
37
66
  end
@@ -66,14 +95,29 @@ module EducodeSales
66
95
  render layout: false
67
96
  end
68
97
 
98
+ def update_advise
99
+ # followup = FollowUp.find(params[:id])
100
+ # followup.update(advise: params[:content])
101
+ # render_success
102
+ idea = Idea.find(params[:id])
103
+ idea.update(advise: params[:content])
104
+ render_success
105
+ end
106
+
69
107
  def create
70
108
  idea = Idea.new(idea_params)
71
109
  # idea.school_id = Department.find_by_id(idea.department_id)&.school_id
72
110
  idea.creator = current_user
73
111
  assist_staff_ids = Array(params[:assist_staff_ids].to_s.split(","))
74
112
  attachment_ids = Array(params[:attachment_ids].to_s.split(","))
113
+ other_staff_ids = Array(params[:other_staff_ids].to_s.split(","))
114
+ if idea.business_id.present?
115
+ idea.school_id = idea.business&.department&.school_id
116
+ idea.department_id = idea.business&.department_id
117
+ end
75
118
  idea.attachment_ids = attachment_ids
76
119
  idea.assist_staff_ids = assist_staff_ids
120
+ idea.other_staff_ids = other_staff_ids
77
121
  idea.save
78
122
  render_success
79
123
  end
@@ -93,6 +137,12 @@ module EducodeSales
93
137
  @idea.assist_staff_ids = assist_staff_ids
94
138
  attachment_ids = Array(params[:attachment_ids].to_s.split(","))
95
139
  @idea.attachment_ids = attachment_ids
140
+ other_staff_ids = Array(params[:other_staff_ids].to_s.split(","))
141
+ @idea.other_staff_ids = other_staff_ids
142
+ if @idea.business_id.present?
143
+ @idea.school_id = @idea.business&.department&.school_id
144
+ @idea.department_id = @idea.business&.department_id
145
+ end
96
146
  check_changes
97
147
  @idea.save
98
148
  render_success
@@ -114,16 +164,110 @@ module EducodeSales
114
164
  gon.value = @idea.department_id
115
165
  gon.department_list = @idea.department.present? ? [{ name: @idea.department.name, value: @idea.department_id }] : []
116
166
  gon.school_list = @idea.school.present? ? [{ name: @idea.school.name, value: @idea.school_id }] : []
167
+ gon.business_list = @idea.business.present? ? [{ name: @idea.business.name, value: @idea.business_id }] : []
168
+ gon.other_staff_value = @idea.other_staffs.map { |d| { name: d&.user&.real_name, value: d.id } }
169
+ render layout: false
170
+ end
171
+
172
+ def show_teachers
173
+ render layout: false
174
+ end
175
+
176
+ def upload_file
117
177
  render layout: false
118
178
  end
119
179
 
180
+ def show_schools
181
+ respond_to do |format|
182
+ format.html do
183
+ render layout: false
184
+ end
185
+ format.json do
186
+ @data = EducodeSales::ActivityTeacher.joins(teacher: [department: :school]).where(idea_id: params[:id]).select("count(teacher_id) AS teachers_count, departments.name AS department, schools.name AS school, school_id").group("school_id")
187
+ @data = @data.distinct.page(params[:page]).per(params[:limit])
188
+ end
189
+ end
190
+ end
191
+
192
+ def new_follow_up
193
+ @idea = Idea.find(params[:id])
194
+ gon.staffs = Staff.where.not(role_id: 11).includes(:user).map { |d| { name: d.user.real_name, value: d.id } }
195
+ render layout: false
196
+ end
197
+
198
+ def follow_up
199
+ idea = Idea.find(params[:id])
200
+ follow_up = IdeaFollow.new(idea_id: idea.id, staff_id: @current_admin.id, money: params[:money], content: params[:content], status: params[:status], advise: params[:advise], sale_staff_id: params[:sale_staff_id], idea_staff_id: params[:idea_staff_id])
201
+ if follow_up.save
202
+ idea.last_idea_follow_id = follow_up.id
203
+ idea.save
204
+ render_success
205
+ else
206
+ render_failure follow_up
207
+ end
208
+
209
+ end
210
+
211
+ def follow_ups
212
+ @data = IdeaFollow
213
+ if params[:q] && params[:q][:search_name].present?
214
+ @data = @data.left_joins(idea: :business).where("educode_sales_businesses.name like ?", "%#{params[:q][:search_name]}%")
215
+ .or(@data.left_joins(idea: :business).where("educode_sales_ideas.name like ?", "%#{params[:q][:search_name]}%"))
216
+ end
217
+ if params[:q] && params[:q][:search_school].present?
218
+ @data = @data.joins(idea: [department: :school]).where("schools.name like ?", "%#{params[:q][:search_school]}%")
219
+ end
220
+ if params[:q] && params[:q][:search_sale_staff_id].present?
221
+ @data = @data.where(sale_staff_id: params[:q][:search_sale_staff_id])
222
+ end
223
+ if params[:q] && params[:q][:search_idea_staff].present?
224
+ @data = @data.where(idea_staff_id: params[:q][:search_idea_staff])
225
+ end
226
+ if params[:q] && params[:q][:search_created_at].present?
227
+ @data = @data.where("educode_sales_idea_follows.created_at >= ? and educode_sales_idea_follows.created_at <= ?", params[:q][:search_created_at].split(" - ")[0], params[:q][:search_created_at].split(" - ")[1])
228
+ end
229
+ if params[:q] && params[:q][:search_content].present?
230
+ @data = @data.where("educode_sales_idea_follows.content like ?", "%#{params[:q][:search_content]}%")
231
+ end
232
+ # if params[:sort].present? && params[:sort][:field]
233
+ # @data = @data.order("#{params[:sort][:field]} #{params[:sort][:order]}")
234
+ # else
235
+ # @data = @data.order("educode_sales_idea_follows.created_at desc")
236
+ # end
237
+ @data = @data.distinct.page(params[:page]).per(params[:limit])
238
+ end
239
+
240
+ def add_advise
241
+ followup = IdeaFollow.find(params[:id])
242
+ followup.update(advise: params[:content])
243
+ render_success
244
+ end
245
+
246
+ def files
247
+ respond_to do |format|
248
+ format.html do
249
+ render layout: false
250
+ end
251
+ format.json do
252
+ idea = Idea.find(params[:id])
253
+ @files = idea.files
254
+ if params[:sort].present? && params[:sort][:field]
255
+ @files = @files.order("#{params[:sort][:field]} #{params[:sort][:order]}")
256
+ else
257
+ @files = @files.order("created_on desc")
258
+ end
259
+ @files = @files.page(params[:page]).per(params[:limit])
260
+ end
261
+ end
262
+ end
263
+
120
264
  private
121
265
 
122
266
  def idea_params
123
267
  params.permit(:name, :level, :staff_id,
124
268
  :status, :types, :model, :hardware, :project,
125
269
  :money, :end_time, :content, :department_id, :school_id,
126
- :manager_name, :manager_phone, :school_name, :department_name, :sale_staff_id, :attachment_id)
270
+ :manager_name, :manager_phone, :school_name, :department_name, :sale_staff_id, :attachment_id, :idea_type, :business_id)
127
271
  end
128
272
 
129
273
  def find_idea
@@ -145,79 +289,5 @@ module EducodeSales
145
289
  end
146
290
  end
147
291
 
148
- # def upload_file(file)
149
- # folder = File.join(Rails.root, "public", "files", 'educode_sales')
150
- # upload_file = file
151
- # raise "未上传文件" unless upload_file
152
- # save_path = File.join(folder)
153
- # ext = file_ext(upload_file.original_filename)
154
- # local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext)
155
- # content_type = upload_file.content_type.presence || 'application/octet-stream'
156
- # disk_filename = local_path[save_path.size + 1, local_path.size]
157
- # @attachment = Attachment.where(disk_filename: disk_filename,
158
- # author_id: current_user.id).first
159
- # if @attachment.blank?
160
- # @attachment = Attachment.new
161
- # @attachment.filename = upload_file.original_filename
162
- # @attachment.description = "popup_windows"
163
- # @attachment.disk_filename = local_path[save_path.size + 1, local_path.size]
164
- # @attachment.filesize = upload_file.tempfile.size
165
- # @attachment.content_type = content_type
166
- # @attachment.digest = digest
167
- # @attachment.author_id = current_user.id
168
- # @attachment.container_id = current_user.id
169
- # @attachment.save!
170
- # else
171
- # logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}"
172
- # end
173
- # @attachment.id
174
- # # render_ok
175
- # end
176
- # def edu_setting name
177
- # EduSetting.get(name)
178
- # end
179
- #
180
- #
181
- # def file_ext(file_name)
182
- # ext = ''
183
- # exts = file_name.split(".")
184
- # if exts.size > 1
185
- # ext = ".#{exts.last}"
186
- # end
187
- # ext
188
- # end
189
- #
190
- # def file_save_to_local(save_path, temp_file, ext)
191
- # unless Dir.exists?(save_path)
192
- # FileUtils.mkdir_p(save_path) ##不成功这里会抛异常
193
- # end
194
- #
195
- # digest = md5_file(temp_file)
196
- # digest = "#{digest}_#{(Time.now.to_f * 1000).to_i}"
197
- # local_file_path = File.join(save_path, digest) + ext
198
- # save_temp_file(temp_file, local_file_path)
199
- #
200
- # [local_file_path, digest]
201
- # end
202
- #
203
- #
204
- # def md5_file(temp_file)
205
- # md5 = Digest::MD5.new
206
- # temp_file.rewind
207
- # while (buffer = temp_file.read(8192))
208
- # md5.update(buffer)
209
- # end
210
- # md5.hexdigest
211
- # end
212
- #
213
- # def save_temp_file(temp_file, save_file_path)
214
- # File.open(save_file_path, 'wb') do |f|
215
- # temp_file.rewind
216
- # while (buffer = temp_file.read(8192))
217
- # f.write(buffer)
218
- # end
219
- # end
220
- # end
221
-
222
292
  end
223
293
  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' }, { clazz: 'MoneyPlan' }, { clazz: 'AssessmentsSetting' }, { clazz: 'Idea' }, { clazz: 'Project' }])
19
+ role.role_areas.build([{ clazz: 'Business' }, { clazz: 'Contract' }, { clazz: 'SalePlan' }, { clazz: 'Teacher' }, { clazz: 'Operation' }, { clazz: 'Customer' }, { clazz: 'MoneyPlan' }, { clazz: 'AssessmentsSetting' }, { clazz: 'Idea' }, { clazz: 'Project' }])
20
20
  if role.save
21
21
  render_success
22
22
  else
@@ -75,6 +75,7 @@ module EducodeSales
75
75
  def view
76
76
  role = Role.find(params[:id])
77
77
  role.role_areas.find_by(clazz: 'Business').update(level: params[:business])
78
+ role.role_areas.find_by(clazz: 'Contract').update(level: params[:contract])
78
79
  role.role_areas.find_by(clazz: 'Operation').update(level: params[:operation])
79
80
  role.role_areas.find_by(clazz: 'SalePlan').update(level: params[:sale_plan])
80
81
  role.role_areas.find_by(clazz: 'Teacher').update(level: params[:teacher])
@@ -36,6 +36,9 @@ module EducodeSales
36
36
  if params[:activity_id].present?
37
37
  @attachment.container_id = params[:activity_id]
38
38
  @attachment.container_type = 'EducodeSales::Activity'
39
+ elsif params[:idea_id].present?
40
+ @attachment.container_id = params[:idea_id]
41
+ @attachment.container_type = 'EducodeSales::Idea'
39
42
  else
40
43
  @attachment.description = "business"
41
44
  @attachment.container_id = params[:business_id]
@@ -0,0 +1,6 @@
1
+ module EducodeSales
2
+ class AssignStaff < ApplicationRecord
3
+ belongs_to :staff
4
+ belongs_to :sourcable, :polymorphic => true
5
+ end
6
+ end