From 4503bc82001f63f3e55aa4ef8c15346917399231 Mon Sep 17 00:00:00 2001 From: BOHUNG Date: Mon, 24 Feb 2020 14:26:25 +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_patents_helper.rb | 8 ++++---- app/views/admin/patents/download_excel.xlsx.axlsx | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/helpers/admin/personal_patents_helper.rb b/app/helpers/admin/personal_patents_helper.rb index 7eafe8d..8a8d2bc 100644 --- a/app/helpers/admin/personal_patents_helper.rb +++ b/app/helpers/admin/personal_patents_helper.rb @@ -120,7 +120,7 @@ module Admin::PersonalPatentsHelper 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"] = Patent.where(:year.gte => year_start, :year.lte => year_end, :member_profile_id.in => mps) rescue [] + d["data"] = Patent.where(:year.gte => year_start.to_s, :year.lte => year_end.to_s, :member_profile_id.in => mps) rescue [] data << d end return data @@ -147,7 +147,7 @@ module Admin::PersonalPatentsHelper (year_start..year_end).each do |year| # d1 = DateTime.new(year,1,1,0,0) # d2 = DateTime.new(year,12,31,23,59) - t = jl.patents.where(:year => year, :member_profile_id.in => mps).count rescue 0 + t = jl.patents.where(:year => year.to_s, :member_profile_id.in => mps).count rescue 0 data["data"][year.to_s] = t end finaldata << data @@ -158,9 +158,9 @@ module Admin::PersonalPatentsHelper # d2 = DateTime.new(year,12,31,23,59) case type when "category" - t = Patent.where(:year => year, :member_profile_id.in => mps, :patent_type_ids => nil).count rescue 0 + t = Patent.where(:year => year.to_s, :member_profile_id.in => mps, :patent_type_ids => nil).count rescue 0 when "author_type" - t = Patent.where(:year => year, :member_profile_id.in => mps, :patent_author_type_ids => nil).count rescue 0 + t = Patent.where(:year => year.to_s, :member_profile_id.in => mps, :patent_author_type_ids => nil).count rescue 0 end data["data"][year.to_s] = t diff --git a/app/views/admin/patents/download_excel.xlsx.axlsx b/app/views/admin/patents/download_excel.xlsx.axlsx index a5aff3b..f284072 100644 --- a/app/views/admin/patents/download_excel.xlsx.axlsx +++ b/app/views/admin/patents/download_excel.xlsx.axlsx @@ -27,7 +27,7 @@ wb = xlsx_package.workbook row << t("personal_patent.patent_category") - row << t("personal_patent.issue_no") + row << t("personal_patent.patent_no") row << t("personal_patent.publication_date") @@ -40,7 +40,7 @@ wb = xlsx_package.workbook sheet.add_row row, :style => heading data.each do |patent| - row = [patent.member_profile.name] + row = [(patent.member_profile_id.class == Array ? patent.member_profile_id.map{|member_id| MemberProfile.find(member_id).name rescue ""} : [patent.member_profile.name])] @site_in_use_locales.each do |locale| row << patent.patent_title_translations[locale.to_s] end @@ -54,7 +54,7 @@ wb = xlsx_package.workbook row << patent.year row << patent.language row << patent.patent_types.map{|pt| pt.title}.join(", ") rescue "" - row << patent.issue_no + row << patent.patent_no row << patent.publication_date.strftime("%Y-%m-%d") rescue "" row << patent.url row << patent.keywords