educode_sales 0.9.57 → 0.9.58
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 +325 -8
- data/app/controllers/educode_sales/follow_ups_controller.rb +3 -0
- data/app/controllers/educode_sales/teacher_follows_controller.rb +4 -0
- data/app/controllers/educode_sales/teachers_controller.rb +3 -0
- data/app/models/educode_sales/business.rb +1 -1
- data/app/views/educode_sales/assessments/edit.html.erb +59 -59
- data/app/views/educode_sales/assessments/new.html.erb +31 -19
- data/app/views/educode_sales/businesses/contract.html.erb +1005 -0
- data/app/views/educode_sales/businesses/contract.json.jbuilder +71 -0
- data/app/views/educode_sales/businesses/index.html.erb +161 -120
- data/app/views/educode_sales/businesses/index.json.jbuilder +3 -0
- data/app/views/educode_sales/recycles/_business.html.erb +18 -0
- data/app/views/educode_sales/recycles/business.json.jbuilder +4 -0
- data/app/views/educode_sales/teachers/_follows.html.erb +8 -2
- data/app/views/educode_sales/teachers/_index.html.erb +6 -0
- data/app/views/layouts/educode_sales/application.html.erb +4 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20230314122536_add_delet_reason_to_business.rb +7 -0
- data/lib/educode_sales/version.rb +1 -1
- metadata +9 -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: c6655d618fcde94017c9a83078d6dd9600cb78cdc6bac13ecc4a7d75b8276edb
|
4
|
+
data.tar.gz: cf339c058e8f173855bacea9e9e8c81c641e2a616fc0633831b0277eeab30a4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc5367e14159d73312f6dbc144297cd6c3c9c91bb2b409e8aa02056b0473cd85b8c2a34f7ba15535c7073ac2d019e2a055448fe43336768276fd19b2ec71f4c0
|
7
|
+
data.tar.gz: b0204185249ada0fa4242f330dc0815a77e50e28d0221d28382660b1623b07b503f57c879200c5d1ce96cfc68d6987a016fbad3a54d15d6c315e0b24d3736ed7
|
@@ -55,11 +55,11 @@ module EducodeSales
|
|
55
55
|
{value: d.id, name: d.name, selected: bussiness_type.include?(d.extras)}
|
56
56
|
end
|
57
57
|
|
58
|
-
gon.business_step = Common.where(clazz: 'business_step', name: ['已中标', '已签单', '已验收', '回款中', '服务中', '已结束']).order("position").map do |d|
|
59
|
-
|
60
|
-
end
|
58
|
+
# gon.business_step = Common.where(clazz: 'business_step', name: ['已中标', '已签单', '已验收', '回款中', '服务中', '已结束']).order("position").map do |d|
|
59
|
+
# {value: d.id, name: d.name, selected: business_step.include?(d.name)}
|
60
|
+
# end
|
61
61
|
|
62
|
-
gon.
|
62
|
+
gon.business_step = Common.where(clazz: 'business_step').order("position").map do |d|
|
63
63
|
{value: d.id, name: d.name, selected: business_step.include?(d.name)}
|
64
64
|
end
|
65
65
|
|
@@ -115,7 +115,7 @@ module EducodeSales
|
|
115
115
|
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
|
116
116
|
@businesses = Business.joins("JOIN departments AS dp ON educode_sales_businesses.department_id = dp.id").where("dp.school_id in (?)", school_ids)
|
117
117
|
elsif params[:q][:clazz] == 'delete_list'
|
118
|
-
@businesses = Business.unscoped.where
|
118
|
+
@businesses = Business.unscoped.where(state_id: [1, 3])
|
119
119
|
end
|
120
120
|
else
|
121
121
|
if @current_admin.is_admin?
|
@@ -187,7 +187,7 @@ module EducodeSales
|
|
187
187
|
").where("educode_sales_follow_ups.staff_id = ?", params[:q][:staff_id]).ids
|
188
188
|
business_ids = part_a_ids + part_b_ids
|
189
189
|
if params[:q][:clazz] == 'delete_list'
|
190
|
-
@businesses = EducodeSales::Business.unscoped.where(id:business_ids)
|
190
|
+
@businesses = EducodeSales::Business.unscoped.where(id:business_ids).where(state_id: [1,3])
|
191
191
|
else
|
192
192
|
@businesses = EducodeSales::Business.where(id:business_ids)
|
193
193
|
end
|
@@ -400,12 +400,48 @@ module EducodeSales
|
|
400
400
|
|
401
401
|
def destroy
|
402
402
|
business = Business.find(params[:id])
|
403
|
-
|
404
|
-
|
403
|
+
if ['a_class', 'b_class'].include?(business.clazz&.extras)
|
404
|
+
if params[:content].present?
|
405
|
+
business.update(deleted_at: Time.now, state_id: 1, delete_reason: params[:content])
|
406
|
+
business.sale_plans.update_all(deleted_at: Time.now)
|
407
|
+
business.follow_ups.update_all(deleted_at: Time.now)
|
408
|
+
else
|
409
|
+
render_failure '请输入删除商机原因'
|
410
|
+
end
|
411
|
+
else
|
412
|
+
business.soft_destroy(@current_admin.id)
|
413
|
+
render_success
|
414
|
+
end
|
415
|
+
|
405
416
|
rescue ActiveRecord::DeleteRestrictionError => e
|
406
417
|
render_failure '该商机已其它关联数据产生,暂不能删除'
|
407
418
|
end
|
408
419
|
|
420
|
+
def audit
|
421
|
+
business = Business.unscoped.find(params[:id])
|
422
|
+
if params[:clazz] == 'destroy'
|
423
|
+
if params[:op] == 'pass'
|
424
|
+
business.update(state_id: 2)
|
425
|
+
business.sale_plans.each do |d|
|
426
|
+
EducodeSales::Recycle.create(source: d, deleter_id: @current_admin.id)
|
427
|
+
end
|
428
|
+
EducodeSales::Recycle.create(source: business, deleter_id: @current_admin.id)
|
429
|
+
else
|
430
|
+
business.update(state_id: 0, delete_reason: '', deleted_at: nil)
|
431
|
+
SalePlan.unscoped.where(business_id: business.id).update_all(deleted_at: nil)
|
432
|
+
FollowUp.unscoped.where(business_id: business.id).update_all(deleted_at: nil)
|
433
|
+
end
|
434
|
+
else
|
435
|
+
if params[:op] == 'pass'
|
436
|
+
business.update(state_id: 0)
|
437
|
+
else
|
438
|
+
business.clazz_id = EducodeSales::Common.find_by(extras: 'a_class').id
|
439
|
+
business.update(state_id: 0)
|
440
|
+
end
|
441
|
+
end
|
442
|
+
render_success
|
443
|
+
end
|
444
|
+
|
409
445
|
def show_keys
|
410
446
|
render layout: false
|
411
447
|
end
|
@@ -763,6 +799,287 @@ module EducodeSales
|
|
763
799
|
@business = @business.where("educode_sales_businesses.name like ?", "%#{params[:q]}%").limit(30) if params[:q].present?
|
764
800
|
end
|
765
801
|
|
802
|
+
def contract
|
803
|
+
authorize! :contract_business, Business
|
804
|
+
respond_to do |format|
|
805
|
+
format.html do
|
806
|
+
common = Common.find_by(clazz: 'staff_type', name: '销售')
|
807
|
+
@staffs = Staff.joins(:user).where(job_type: common.id).where.not(role_id: 11).map { |d| [d.user.real_name, d.id]}
|
808
|
+
gon.staffs = Staff.joins(:user).where(job_type: common.id).where.not(role_id: 11).map { |d| {name: d.user.real_name, value: d.id } }
|
809
|
+
@more = true
|
810
|
+
gon.menus = []
|
811
|
+
gon.export_menus = []
|
812
|
+
gon.place = params[:place_id].present? ? [{ value: params[:place_id], name: EducodeSales::Place.find(params[:place_id]).name }] : []
|
813
|
+
|
814
|
+
bussiness_type = []
|
815
|
+
if params[:type]
|
816
|
+
# 项目类型
|
817
|
+
bussiness_type = EducodeSales::Business.include_types(params[:type]) || []
|
818
|
+
end
|
819
|
+
|
820
|
+
business_step = []
|
821
|
+
if params[:step]
|
822
|
+
# 项目阶段
|
823
|
+
business_step = EducodeSales::Business.include_steps(params[:step]) || []
|
824
|
+
end
|
825
|
+
|
826
|
+
if params[:business_year].present? && params[:business_year] != '全部'
|
827
|
+
gon.business_year = params[:business_year]
|
828
|
+
end
|
829
|
+
|
830
|
+
if params[:bidded_date_year].present? && params[:bidded_date_year] != '全部'
|
831
|
+
if params[:step] == '应收款'
|
832
|
+
gon.bidded_date = "2015-01-01" + " - " + Time.new(params[:bidded_date_year]).end_of_year.strftime("%Y-%m-%d")
|
833
|
+
else
|
834
|
+
gon.bidded_date = Time.new(params[:bidded_date_year]).strftime("%Y-%m-%d") + " - " + Time.new(params[:bidded_date_year]).end_of_year.strftime("%Y-%m-%d")
|
835
|
+
end
|
836
|
+
end
|
837
|
+
|
838
|
+
if params[:signed_date_year].present? && params[:signed_date_year] != '全部'
|
839
|
+
gon.signed_date = Time.new(params[:signed_date_year]).strftime("%Y-%m-%d") + " - " + Time.new(params[:signed_date_year]).end_of_year.strftime("%Y-%m-%d")
|
840
|
+
end
|
841
|
+
|
842
|
+
if params[:date_at].present? && params[:date_at] != '全部'
|
843
|
+
# 回款时间
|
844
|
+
gon.date_at = Time.new(params[:date_at]).strftime("%Y-%m-%d") + " - " + Time.new(params[:date_at]).end_of_year.strftime("%Y-%m-%d")
|
845
|
+
end
|
846
|
+
|
847
|
+
gon.business_type = Common.where(clazz: 'business_type').map do |d|
|
848
|
+
{value: d.id, name: d.name, selected: bussiness_type.include?(d.extras)}
|
849
|
+
end
|
850
|
+
|
851
|
+
gon.business_step = Common.where(clazz: 'business_step', name: ['已中标', '已签单', '已验收', '回款中', '服务中', '已结束']).order("position").map do |d|
|
852
|
+
{value: d.id, name: d.name, selected: business_step.include?(d.name)}
|
853
|
+
end
|
854
|
+
|
855
|
+
filter = Filter.find_or_create_by(staff_id: @current_admin.id, clazz: "businesses_list")
|
856
|
+
if filter.extras.present?
|
857
|
+
if filter.extras['area'].nil?
|
858
|
+
filter.extras['area'] = 1
|
859
|
+
filter.extras['property'] = 1
|
860
|
+
filter.extras['sale_way'] = 1
|
861
|
+
end
|
862
|
+
filter.save
|
863
|
+
gon.filter = filter.extras
|
864
|
+
else
|
865
|
+
gon.filter = {'area': 1, 'property': 1, 'sale_way': 1}
|
866
|
+
end
|
867
|
+
end
|
868
|
+
format.json do
|
869
|
+
if @current_admin.is_admin?
|
870
|
+
@businesses = Business
|
871
|
+
else
|
872
|
+
level = @current_admin.role.role_areas.find_by(clazz: '商机管理').level
|
873
|
+
case level
|
874
|
+
when '自己'
|
875
|
+
business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
|
876
|
+
@businesses = Business.where("educode_sales_businesses.staff_id = ? OR educode_sales_businesses.id in (?)", @current_admin.id, business_ids)
|
877
|
+
when '区域'
|
878
|
+
# 查看区域商机,需要排除掉其它人员手上的监管学校
|
879
|
+
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
|
880
|
+
|
881
|
+
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
|
882
|
+
if can?(:special, EducodeSales::Business)
|
883
|
+
# 专项商机
|
884
|
+
school_tag_ids = @current_admin.staff_school_tags.pluck(:school_tag_id)
|
885
|
+
tag_school_ids = SchoolTagMiddle.where(school_tag_id: school_tag_ids).pluck(:school_id)
|
886
|
+
school_ids += tag_school_ids
|
887
|
+
end
|
888
|
+
business_ids = Business.joins(last_follow_up: :assign_follow_ups).where("educode_sales_assign_follow_ups.staff_id = ?", @current_admin.id).pluck(:id)
|
889
|
+
@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)
|
890
|
+
else
|
891
|
+
@businesses = Business
|
892
|
+
end
|
893
|
+
end
|
894
|
+
if params[:q].present? && params[:q][:name].present?
|
895
|
+
@year = params[:q][:name].split("-")[1].present? ? params[:q][:name].split("-")[1] : ''
|
896
|
+
end
|
897
|
+
|
898
|
+
# @budget_stage_ids = Common.where(clazz: '商机阶段', name: ['初步接洽', '准备方案','已交方案', '已立项']).pluck(:id)
|
899
|
+
if params[:q] && params[:q][:signed_date].present?
|
900
|
+
date = params[:q][:signed_date].split(" - ")
|
901
|
+
@businesses = @businesses.joins("
|
902
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
903
|
+
").where("educode_sales_follow_ups.signed_date >= ? AND educode_sales_follow_ups.signed_date <= ?", date[0], date[1])
|
904
|
+
end
|
905
|
+
|
906
|
+
if params[:q]&& params[:q][:date_at].present?
|
907
|
+
date = params[:q][:date_at].split(" - ")
|
908
|
+
x_id = Common.find_by(extras: EducodeSales::Common::XTYPE)&.id
|
909
|
+
@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
|
910
|
+
end
|
911
|
+
|
912
|
+
if params[:q] && params[:q][:bidded_date].present?
|
913
|
+
date = params[:q][:bidded_date].split(" - ")
|
914
|
+
@businesses = @businesses.joins("
|
915
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
916
|
+
").where("educode_sales_follow_ups.bidded_date >= ? AND educode_sales_follow_ups.bidded_date <= ?", date[0], date[1])
|
917
|
+
end
|
918
|
+
|
919
|
+
if params[:q].present? && params[:q][:all].present?
|
920
|
+
@businesses = @businesses
|
921
|
+
end
|
922
|
+
|
923
|
+
if params[:q].present? && params[:q][:name].present?
|
924
|
+
@businesses = @businesses.where("educode_sales_businesses.name like ?", "%#{params[:q][:name]}%")
|
925
|
+
end
|
926
|
+
if params[:q].present? && params[:q][:department].present?
|
927
|
+
departments_ids = Department.joins(:school).where("schools.name like ?", "%#{params[:q][:department]}%").pluck(:id)
|
928
|
+
@businesses = @businesses.joins(:department).where("departments.id in (?)", departments_ids)
|
929
|
+
end
|
930
|
+
if params[:q].present? && params[:q][:staff_id].present?
|
931
|
+
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
|
932
|
+
part_b_ids = @businesses.where("educode_sales_businesses.last_follow_up_id is not null").joins("
|
933
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
934
|
+
").where("educode_sales_follow_ups.staff_id = ?", params[:q][:staff_id]).ids
|
935
|
+
business_ids = part_a_ids + part_b_ids
|
936
|
+
if params[:q][:clazz] == 'delete_list'
|
937
|
+
@businesses = EducodeSales::Business.unscoped.where(id:business_ids)
|
938
|
+
else
|
939
|
+
@businesses = EducodeSales::Business.where(id:business_ids)
|
940
|
+
end
|
941
|
+
end
|
942
|
+
if params[:q].present? && params[:q][:business_type].present?
|
943
|
+
@businesses = @businesses.where("educode_sales_businesses.clazz_id in (?)", params[:q][:business_type].split(",").map(&:to_i))
|
944
|
+
end
|
945
|
+
if params[:q].present? && params[:q][:contract].present?
|
946
|
+
contract_ids = Common.where(clazz: '商机阶段', name: ['已中标', '已签单', '已验收', '回款中', '服务中', '已结束']).pluck(:id)
|
947
|
+
@businesses = @businesses.joins("
|
948
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
949
|
+
").where("educode_sales_follow_ups.stage_id in (?)", contract_ids)
|
950
|
+
end
|
951
|
+
if params[:q].present? && params[:q][:business_step].present?
|
952
|
+
@businesses = @businesses.joins("
|
953
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
954
|
+
").where("educode_sales_follow_ups.stage_id in (?)", params[:q][:business_step].split(",").map(&:to_i))
|
955
|
+
end
|
956
|
+
if params[:q].present? && params[:q][:place_id].present?
|
957
|
+
@businesses = @businesses.joins("
|
958
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
959
|
+
").where("educode_sales_follow_ups.place_id = ?", params[:q][:place_id])
|
960
|
+
end
|
961
|
+
if params[:q].present? && params[:q][:business_year].present?
|
962
|
+
@businesses = @businesses.joins("
|
963
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
964
|
+
").where("educode_sales_follow_ups.year = ?", params[:q][:business_year])
|
965
|
+
end
|
966
|
+
|
967
|
+
if params[:q].present? && params[:q][:year].present?
|
968
|
+
@businesses = @businesses.joins("
|
969
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
970
|
+
").where("educode_sales_follow_ups.year <= ?", params[:q][:year])
|
971
|
+
end
|
972
|
+
|
973
|
+
if params[:q].present? && params[:q][:o_business_deployment].present?
|
974
|
+
@businesses = @businesses.joins("
|
975
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
976
|
+
").where("educode_sales_follow_ups.o_business_deployment = ?", params[:q][:o_business_deployment])
|
977
|
+
end
|
978
|
+
|
979
|
+
if params[:q].present? && params[:q][:area].present?
|
980
|
+
p = EducodeSales::Common.find(params[:q][:area]).name
|
981
|
+
if @current_admin.is_admin?
|
982
|
+
@businesses = @businesses.joins("
|
983
|
+
JOIN departments ON educode_sales_businesses.department_id = departments.id
|
984
|
+
JOIN schools ON departments.school_id = schools.id
|
985
|
+
").where("province = ?", p)
|
986
|
+
else
|
987
|
+
level = @current_admin.role.role_areas.find_by(clazz: '商机管理').level
|
988
|
+
if level == "区域"
|
989
|
+
@businesses = @businesses.joins("
|
990
|
+
JOIN schools ON departments.school_id = schools.id
|
991
|
+
").where("province = ?", p)
|
992
|
+
else
|
993
|
+
@businesses = @businesses.joins("
|
994
|
+
JOIN departments ON educode_sales_businesses.department_id = departments.id
|
995
|
+
JOIN schools ON departments.school_id = schools.id
|
996
|
+
").where("province = ?", p)
|
997
|
+
end
|
998
|
+
end
|
999
|
+
end
|
1000
|
+
|
1001
|
+
if params[:q].present? && params[:q][:date].present?
|
1002
|
+
date = params[:q][:date].split(" - ")
|
1003
|
+
@businesses = @businesses.where("educode_sales_businesses.created_at > ? AND educode_sales_businesses.created_at < ?", date[0], date[1] + '23:59:59')
|
1004
|
+
end
|
1005
|
+
|
1006
|
+
if params[:q].present? && params[:q][:invitation_at].present?
|
1007
|
+
date = params[:q][:invitation_at].split(" - ")
|
1008
|
+
@businesses = @businesses.joins("
|
1009
|
+
JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
|
1010
|
+
").where("educode_sales_follow_ups.invitation_at > ? AND educode_sales_follow_ups.invitation_at < ?", date[0] + '00:00:00', date[1] + '23:59:59')
|
1011
|
+
end
|
1012
|
+
|
1013
|
+
# 根据编号获取商机
|
1014
|
+
if params[:q].present? && params[:q][:number].present?
|
1015
|
+
@businesses = @businesses.where("number like :data", data: "%#{params[:q][:number].strip}%")
|
1016
|
+
end
|
1017
|
+
|
1018
|
+
if params[:q].present? && params[:q][:clazz].present?
|
1019
|
+
# 我的关注
|
1020
|
+
if params[:q][:clazz] == 'followes'
|
1021
|
+
my_ids = BusinessRelationShip.where(user_id:@current_admin.user_id).pluck(:business_id)
|
1022
|
+
@businesses = @businesses.where(id: my_ids)
|
1023
|
+
elsif params[:q][:clazz] == 'me'
|
1024
|
+
ids = AssignFollowUp.joins("JOIN educode_sales_follow_ups ON educode_sales_follow_ups.id = educode_sales_assign_follow_ups.follow_up_id").where(staff_id: @current_admin.id).pluck(:business_id)
|
1025
|
+
@businesses = @businesses.where("educode_sales_businesses.id in (?) or educode_sales_businesses.staff_id = ?", ids, @current_admin.id)
|
1026
|
+
end
|
1027
|
+
end
|
1028
|
+
|
1029
|
+
# 商机变化
|
1030
|
+
if params[:q][:clazz_changes].present?
|
1031
|
+
clazz_changes = EducodeSales::BusinessClazzChange.clazz_changes_value[params[:q][:clazz_changes].to_s]
|
1032
|
+
@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)
|
1033
|
+
end
|
1034
|
+
|
1035
|
+
if params[:sort].present? && params[:sort][:field]
|
1036
|
+
if params[:sort][:field] == "service_end_time"
|
1037
|
+
@businesses = @businesses.order("service_time_long #{params[:sort][:order]}")
|
1038
|
+
else
|
1039
|
+
@businesses = @businesses.order("#{params[:sort][:field]} #{params[:sort][:order]}")
|
1040
|
+
end
|
1041
|
+
else
|
1042
|
+
@businesses = @businesses.order("educode_sales_businesses.created_at desc")
|
1043
|
+
end
|
1044
|
+
|
1045
|
+
@business_count = @businesses.distinct.count
|
1046
|
+
# mysql -select
|
1047
|
+
@businesses = @businesses.select("
|
1048
|
+
distinct
|
1049
|
+
educode_sales_businesses.*,
|
1050
|
+
last_follow.invitation_at,
|
1051
|
+
last_follow.budget_amount,
|
1052
|
+
last_follow.o_business_deployment,
|
1053
|
+
last_follow.service_time_long,
|
1054
|
+
last_follow.service_end_time,
|
1055
|
+
last_follow.service_start_time,
|
1056
|
+
last_follow.reception_at,
|
1057
|
+
last_follow.bidded_date,
|
1058
|
+
last_follow.signed_date,
|
1059
|
+
last_follow.year,
|
1060
|
+
last_follow.created_at as latest_time,
|
1061
|
+
last_follow.actual_amount,
|
1062
|
+
last_follow.divide_rate,
|
1063
|
+
last_follow.divide_amount,
|
1064
|
+
(last_follow.total_amount - last_follow.actual_amount) as divide_money,
|
1065
|
+
(last_follow.actual_amount - educode_sales_businesses.return_money) as wait_return_money,
|
1066
|
+
last_follow.total_amount,
|
1067
|
+
total_follow_ups.follow_ups_counts
|
1068
|
+
").joins("
|
1069
|
+
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
|
1070
|
+
LEFT JOIN (
|
1071
|
+
SELECT COUNT(*) AS follow_ups_counts, educode_sales_follow_ups.business_id
|
1072
|
+
FROM educode_sales_follow_ups
|
1073
|
+
WHERE educode_sales_follow_ups.deleted_at IS NULL
|
1074
|
+
GROUP BY educode_sales_follow_ups.business_id
|
1075
|
+
) AS total_follow_ups ON educode_sales_businesses.id = total_follow_ups.business_id
|
1076
|
+
").includes(:users, last_follow_up: [:clazz, :assign_follow_ups]).page(params[:page]).per(params[:limit])
|
1077
|
+
|
1078
|
+
end
|
1079
|
+
|
1080
|
+
end
|
1081
|
+
end
|
1082
|
+
|
766
1083
|
private
|
767
1084
|
|
768
1085
|
def load_business
|
@@ -87,6 +87,9 @@ module EducodeSales
|
|
87
87
|
if @business.clazz.present?
|
88
88
|
follow_up.clazz_changed = @business.clazz_id != follow_up.clazz_id
|
89
89
|
if follow_up.clazz_changed
|
90
|
+
if @business.clazz.extras == 'a_class'
|
91
|
+
@business.state_id = 3
|
92
|
+
end
|
90
93
|
clazz_changes = "#{@business.clazz.extras.split('_')[0]}-#{follow_up.clazz.extras.split('_')[0]}"
|
91
94
|
business_clazz_change = EducodeSales::BusinessClazzChange.find_or_initialize_by(business_id: @business.id, clazz_changed: clazz_changes)
|
92
95
|
business_clazz_change.save unless business_clazz_change.persisted?
|
@@ -103,6 +103,10 @@ module EducodeSales
|
|
103
103
|
# end
|
104
104
|
end
|
105
105
|
|
106
|
+
if params[:q].present? && params[:q][:attitude_id].present?
|
107
|
+
@follow_ups = @follow_ups.where("educode_sales_teacher_follows.attitude_id = ?", "#{params[:q][:attitude_id]}")
|
108
|
+
end
|
109
|
+
|
106
110
|
if params[:q].present? && params[:q][:description].present?
|
107
111
|
@follow_ups = @follow_ups.where("educode_sales_teacher_follows.description LIKE ?" ,"%#{params[:q][:description]}%")
|
108
112
|
end
|
@@ -96,6 +96,9 @@ module EducodeSales
|
|
96
96
|
@teachers = @teachers.where("educode_sales_teachers.user_id is null")
|
97
97
|
end
|
98
98
|
end
|
99
|
+
if params[:q].present? && params[:q][:mobile].present?
|
100
|
+
@teachers = @teachers.joins(:user).where("users.phone like ?", "%#{params[:q][:mobile]}%")
|
101
|
+
end
|
99
102
|
if params[:q].present? && params[:q][:attitude].present?
|
100
103
|
# @teachers = @teachers.where("educode_sales_teachers.attitude_id = ?", "#{params[:q][:attitude]}")
|
101
104
|
@teachers = @teachers.joins("
|