From 6def60f8dd49a75891df32de6d7cf7f55f799eaa Mon Sep 17 00:00:00 2001 From: BOHUNG Date: Mon, 24 Feb 2020 14:31:53 +0800 Subject: [PATCH] fix export excel bug caused by related to more than one members and year in mongo's data-type is string not Fixnum. --- app/helpers/admin/personal_researches_helper.rb | 4 ++-- app/views/admin/researchs/download_excel.xlsx.axlsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/admin/personal_researches_helper.rb b/app/helpers/admin/personal_researches_helper.rb index 3d68489..111869c 100644 --- a/app/helpers/admin/personal_researches_helper.rb +++ b/app/helpers/admin/personal_researches_helper.rb @@ -88,7 +88,7 @@ module Admin::PersonalResearchesHelper mps = role.member_profile_ids # d1 = DateTime.new(year_start,1,1,0,0) # d2 = DateTime.new(year_end,12,31,23,59) - d["data"] = Research.where(:year.gte => year_start, :year.lte => year_end, :member_profile_id.in => mps) rescue [] + d["data"] = Research.where(:year.gte => year_start.to_s, :year.lte => year_end.to_s, :member_profile_id.in => mps) rescue [] data << d end return data @@ -124,7 +124,7 @@ module Admin::PersonalResearchesHelper # d2 = DateTime.new(year,12,31,23,59) case type when "category" - t = Research.where(:year => year, :member_profile_id.in => mps, :project_type_id => nil).count rescue 0 + t = Research.where(:year => year.to_s, :member_profile_id.in => mps, :project_type_id => nil).count rescue 0 end data["data"][year.to_s] = t diff --git a/app/views/admin/researchs/download_excel.xlsx.axlsx b/app/views/admin/researchs/download_excel.xlsx.axlsx index be80621..0a1882d 100644 --- a/app/views/admin/researchs/download_excel.xlsx.axlsx +++ b/app/views/admin/researchs/download_excel.xlsx.axlsx @@ -39,7 +39,7 @@ wb = xlsx_package.workbook sheet.add_row row, :style => heading data.each do |proj| - row = [proj.member_profile.name] + row = [(proj.member_profile_id.class == Array ? proj.member_profile_id.map{|member_id| MemberProfile.find(member_id).name rescue ""} : [proj.member_profile.name])] @site_in_use_locales.each do |locale| row << proj.research_title_translations[locale.to_s] end