Class: EducodeSales::MoneyPlansController
Instance Method Summary
collapse
#authenticate_admin, #authenticate_request, #current_user, #filter, #render_failure, #render_success
Instance Method Details
#add ⇒ Object
55
56
57
|
# File 'app/controllers/educode_sales/money_plans_controller.rb', line 55
def add
render layout: false
end
|
#create ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'app/controllers/educode_sales/money_plans_controller.rb', line 59
def create
business = Business.find(params[:business_id])
data = []
(params[:num].to_i+1).times do |i|
business.money_plans.create(category: params["category[#{i}]"], amount: params["amount[#{i}]"], payment_clause: params["payment_clause[#{i}]"], date_at: params["date_at[#{i}]"], follow_up_id: business.last_follow_up_id, staff_id: @current_admin.id )
end
render_success
end
|
#index ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'app/controllers/educode_sales/money_plans_controller.rb', line 6
def index
authorize! :read, MoneyPlan
respond_to do |format|
format.html do
end
format.json do
@money_plans = MoneyPlan.joins(:business).left_joins(:money_plan_claims).group("educode_sales_money_plans.id").select("educode_sales_money_plans.*, COUNT(educode_sales_money_plan_claims.id) AS claim_num")
if @current_admin.is_admin?
else
level = @current_admin.role.role_areas.find_by(clazz: '回款管理').level
case level
when '自己'
@money_plans = @money_plans.where(staff_id: @current_admin.id)
when '区域'
school_ids = School.where(province: @current_admin.areas.pluck(:name)).pluck(:id) + StaffSchool.where(staff_id: @current_admin.id).pluck(:school_id)
b_ids = Business.where(school_id: school_ids).pluck(:id)
@money_plans = @money_plans.where("educode_sales_businesses.id in (?) OR educode_sales_money_plans.staff_id = ?", b_ids, @current_admin.id)
end
end
if params[:q].present? && params[:q][:business].present?
@money_plans = @money_plans.where("educode_sales_businesses.name like ?", "%#{params[:q][:business]}%")
end
if params[:q].present? && params[:q][:school].present?
@money_plans = @money_plans.joins(business: :school).where("schools.name like ?", "%#{params[:q][:school]}%")
end
if params[:sort].present? && params[:sort][:field]
@money_plans = @money_plans.order("#{params[:sort][:field]} #{params[:sort][:order]}")
else
@money_plans = @money_plans.order(date_at: :desc)
end
@money_plans = @money_plans.page(params[:page]).per(params[:limit])
end
end
end
|
#list ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
|
# File 'app/controllers/educode_sales/money_plans_controller.rb', line 43
def list
follow_up_ids = Business.pluck(:last_follow_up_id)
authorize! :read, MoneyPlan
respond_to do |format|
format.html do
common = Common.find_by(clazz: 'staff_type', name: '销售')
@staffs = Staff.joins(:user).where(job_type: common.id).map { |d| [d.user.real_name, d.id]}
end
end
end
|