Sha256: f8d36fd5a2105d61d32995e792ec043148af581fd46650a309dd689ada6a1ef5

Contents?: true

Size: 1.53 KB

Versions: 191

Compression:

Stored size: 1.53 KB

Contents

require_dependency "educode_sales/application_controller"

module EducodeSales
  class OperationsController < ApplicationController

    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

    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

    def operations

    end

    private

    def sale_trend_params
      params.permit(:users_count, :teachers_count, :courses_count, :top_teachers_count)
    end
  end
end

Version data entries

191 entries across 191 versions & 1 rubygems

Version Path
educode_sales-1.10.74 app/controllers/educode_sales/operations_controller.rb
educode_sales-1.10.73 app/controllers/educode_sales/operations_controller.rb
educode_sales-1.10.72 app/controllers/educode_sales/operations_controller.rb
educode_sales-1.10.71 app/controllers/educode_sales/operations_controller.rb
educode_sales-1.10.70 app/controllers/educode_sales/operations_controller.rb
educode_sales-1.10.59 app/controllers/educode_sales/operations_controller.rb
educode_sales-1.10.58 app/controllers/educode_sales/operations_controller.rb
educode_sales-1.10.49 app/controllers/educode_sales/operations_controller.rb
educode_sales-1.10.48 app/controllers/educode_sales/operations_controller.rb
educode_sales-1.10.46 app/controllers/educode_sales/operations_controller.rb
educode_sales-1.10.41 app/controllers/educode_sales/operations_controller.rb
educode_sales-1.10.37 app/controllers/educode_sales/operations_controller.rb
educode_sales-1.10.36 app/controllers/educode_sales/operations_controller.rb
educode_sales-1.10.35 app/controllers/educode_sales/operations_controller.rb
educode_sales-1.10.34 app/controllers/educode_sales/operations_controller.rb
educode_sales-1.10.33 app/controllers/educode_sales/operations_controller.rb
educode_sales-1.10.31 app/controllers/educode_sales/operations_controller.rb
educode_sales-1.10.30 app/controllers/educode_sales/operations_controller.rb
educode_sales-1.10.29 app/controllers/educode_sales/operations_controller.rb
educode_sales-1.10.28 app/controllers/educode_sales/operations_controller.rb