require_dependency "educode_sales/application_controller" module EducodeSales class IdeaRecyclesController < ApplicationController before_action :find_idea, only: [:edit, :destroy, :detail, :history] def index respond_to do |format| format.html do staff_ids = EducodeSales::Idea.all.pluck(:staff_id) creator_ids = EducodeSales::Idea.all.pluck(:creator_id) @creator_arr = EducodeSales::Staff.joins(:user).where(id: creator_ids).pluck("concat(users.lastname,users.firstname)", :id) @staff_arr = EducodeSales::Staff.joins(:user).where(id: staff_ids).pluck("concat(users.lastname,users.firstname)", :id) end format.json do @ideas = Idea.deleted if params[:q] && params[:q][:created_at].present? date = params[:q][:created_at].split(" - ") @ideas = @ideas.where("educode_sales_ideas.created_at >= ? AND educode_sales_ideas.created_at <= ?", date[0], date[1]) end if params[:q].present? && params[:q][:name].present? @ideas = @ideas.where("educode_sales_ideas.name like ?", "%#{params[:q][:name]}%") end if params[:q].present? && params[:q][:school].present? @ideas = @ideas.left_joins(:school).where("schools.name like ?", "%#{params[:q][:school]}%") end if params[:q].present? && params[:q][:creator_id].present? @ideas = @ideas.where("educode_sales_ideas.creator_id = ?", params[:q][:creator_id].to_i) end if params[:q].present? && params[:q][:staff_id].present? @ideas = @ideas.where("educode_sales_ideas.staff_id = ?", params[:q][:staff_id].to_i) end if params[:q].present? && params[:q][:status].present? @ideas = @ideas.where(status: params[:q][:status]) end if params[:q].present? && params[:q][:types].present? @ideas = @ideas.where(types: params[:q][:types]) end if params[:q].present? && params[:q][:model].present? @ideas = @ideas.where(model: params[:q][:model]) end if params[:q].present? && params[:q][:history_type].present? if params[:q][:history_type].to_i == 0 @ideas = @ideas.where("educode_sales_ideas.history_type=#{params[:q][:history_type]} or educode_sales_ideas.history_type is null ") else @ideas = @ideas.where(history_type: params[:q][:history_type]) end end if params[:q].present? && params[:q][:level].present? @ideas = @ideas.where(level: params[:q][:level]) end @ideas = @ideas.page(params[:page]).per(params[:limit]) end end end def new render layout: false end def create end def detail render layout: false end def history render layout: false end def update end def destroy @idea.recycle render_success end def edit end private def idea_params params.permit(:school_id, :name, :level, :staff_id, :status, :types, :model, :hardware, :project, :money, :end_time, :content, :department_id, :manager_name, :manager_phone) end def find_idea @idea = Idea.find(params[:id]) end end end