personal-activity/app/helpers/admin/personal_activities_helper.rb

22 lines
600 B
Ruby

module Admin::PersonalActivitiesHelper
def get_chart_data(year_start,year_end,role,type)
type = nil
finaldata = []
role = Role.find(role) rescue nil
mps = []
if !role.nil?
mps = role.member_profile_ids
end
data = {"name" => "N/A", "data" => {}}
(year_start..year_end).each do |year|
d1 = DateTime.new(year,1,1,0,0)
d2 = DateTime.new(year,12,31,23,59)
t = Activity.where(:year.gte => year, :year.lte => year, :member_profile_id.in => mps).count rescue 0
data["data"][year.to_s] = t
end
finaldata << data
finaldata
end
end