class Survey < ApplicationRecord

	def self.search(filter,from,to)
		if filter.blank?
	        keyword = ''
	    else
	        keyword = "dining_name LIKE ?","%#{filter}%"
	    end

	    if from.present? && to.present?
	      	survey = Survey.where("DATE_FORMAT(created_at,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(created_at,'%d-%m-%Y') <= ?", from,to)
	    	query = survey.where(keyword)
	    else
	    	where("dining_name LIKE ?", "%#{filter}%")
	    end
	end
end
