Class: EducodeSales::SalesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/educode_sales/sales_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_admin, #authenticate_request, #current_user, #render_failure, #render_success

Instance Method Details

#indexObject

load_and_authorize_resource authorize_resource class: false



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/educode_sales/sales_controller.rb', line 8

def index
  authorize! :sales, Staff
  respond_to do |format|
    format.html do
    end
    format.json do
      common = Common.find_by(clazz: 'staff_type', name: '销售')
      @a_clazz = Common.find_by(clazz: 'business_type', name: 'A类')
      @b_clazz = Common.find_by(clazz: 'business_type', name: 'B类')
      @x = Common.find_by(clazz: 'business_type', name: 'X类')
      @step_ids = Common.where(name: %w(已中标 已签单 已验收 回款中 服务中 已结束), clazz: 'business_step').pluck(:id)
      
      @staffs = Staff.where(job_type: common.id).page(params[:page]).per(params[:limit])
    end
  end
end

#operationsObject



41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/educode_sales/sales_controller.rb', line 41

def operations
  authorize! :operations, Staff
  respond_to do |format|
    format.html do
    end
    format.json do
      common_id = Common.where(clazz: 'staff_type', name: ['销售', '运营']).pluck(:id)
      @staffs = Staff.where(job_type: common_id).page(params[:page]).per(params[:limit])
    end
  end
end


31
32
33
34
35
36
37
38
39
# File 'app/controllers/educode_sales/sales_controller.rb', line 31

def sale_trends
  authorize! :sale_trends, SaleTrend
  sale_trend = SaleTrend.find_by(year: params[:year])
  if sale_trend.update(sale_trend_params)
    render_success
  else
    render_failure sale_trend
  end
end

#schoolObject



53
54
55
# File 'app/controllers/educode_sales/sales_controller.rb', line 53

def school
  render layout: false
end


25
26
27
28
29
# File 'app/controllers/educode_sales/sales_controller.rb', line 25

def trends
  authorize! :trends, SaleTrend
  @year = params[:year] ? params[:year] : Time.now.year
  @sale_trend = SaleTrend.find_or_create_by(year: @year)
end

#xschoolObject



57
58
59
# File 'app/controllers/educode_sales/sales_controller.rb', line 57

def xschool
  render layout: false
end