Class: EducodeSales::OperationsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

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

Instance Method Details

#operationsObject



28
29
30
# File 'app/controllers/educode_sales/operations_controller.rb', line 28

def operations

end


19
20
21
22
23
24
25
26
# File 'app/controllers/educode_sales/operations_controller.rb', line 19

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


6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/educode_sales/operations_controller.rb', line 6

def trends
  @years = (1..(Time.now.year - 2014)).reverse_each.map { |d| 2014 + d }
  @year = params[:year] ? params[:year] : Time.now.year
  @operation_trend = OperationTrend.find_or_create_by(year: @year)
  @inc_users_count = User.where("created_on > ? AND created_on <= ?", "#{@year}-01-01 00:00:00", "#{@year}-12-31 23:59:59").count
  @inc_teachers_count = User.joins(:user_extension).where(user_extensions: {identity: 'teacher'}).where("created_on > ? AND created_on <= ?", "#{@year}-01-01 00:00:00", "#{@year}-12-31 23:59:59").count
  @courses_count = Course.where("created_at > ? AND created_at <= ?", "#{@year}-01-01 00:00:00", "#{@year}-12-31 23:59:59").count
  @teachers_count = User.joins(user_extension: [school: :school_property]).
  where("school_properties.project_985 = true OR school_properties.project_211 = true").
  where(user_extensions: {identity: 'teacher'}).
  where("created_on > ? AND created_on <= ?", "#{@year}-01-01 00:00:00", "#{@year}-12-31 23:59:59").count
end