From 852166dabb6104f88327dd090a9907efbf868b1d Mon Sep 17 00:00:00 2001 From: rulingcom Date: Fri, 11 Oct 2013 11:45:52 +0800 Subject: [PATCH] Addded export feature in Survey_b, By Spen --- config/initializers/mime_types.rb | 2 + .../survey_b/back_end/survey_b_controller.rb | 60 ++++ .../back_end/periods/_period.html.erb | 1 + .../back_end/survey_b/export.html.erb | 257 ++++++++++++++++++ .../back_end/survey_b/result.html.erb | 43 ++- .../survey_b/config/locales/en.yml | 1 + .../survey_b/config/locales/zh_tw.yml | 1 + .../survey_b/config/routes.rb | 1 + 8 files changed, 365 insertions(+), 1 deletion(-) create mode 100644 vendor/built_in_modules/survey_b/app/views/panel/survey_b/back_end/survey_b/export.html.erb diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index 087fb2caf..fd2b85dc8 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -5,3 +5,5 @@ # Mime::Type.register_alias "text/html", :iphone Mime::Type.register_alias "text/html", :mobile + +Mime::Type.register 'application/vnd.ms-excel',:xls \ No newline at end of file diff --git a/vendor/built_in_modules/survey_b/app/controllers/panel/survey_b/back_end/survey_b_controller.rb b/vendor/built_in_modules/survey_b/app/controllers/panel/survey_b/back_end/survey_b_controller.rb index 20284f5b0..3893c5a6c 100644 --- a/vendor/built_in_modules/survey_b/app/controllers/panel/survey_b/back_end/survey_b_controller.rb +++ b/vendor/built_in_modules/survey_b/app/controllers/panel/survey_b/back_end/survey_b_controller.rb @@ -89,4 +89,64 @@ class Panel::SurveyB::BackEnd::SurveyBController < OrbitBackendController end end + def export + + if params[:period] && @period = SurveyBPeriod.find(params[:period]) + @answers = ::SurveyBAnswer.where(:created_at.gte => @period.start_date, :created_at.lte => @period.end_date) + @comment_question = ::SurveyBAnswer.where(:created_at.gte => @period.start_date, :created_at.lte => @period.end_date, :comment_question.nin => ['']) + else + @answers = ::SurveyBAnswer.all + @comment_question = ::SurveyBAnswer.where(:comment_question.nin => ['']) + end + @results = Hash[(t('survey_b.institutions').keys + [ 'all' ]).map do |i_key| + [i_key, Hash[(t('survey_b.questions').keys + ['count', 'sum', 'sum7'] ).map{|q_key| [q_key, 0] }].merge({ 'count' => 0, 'sum' => 0, 'sum7' => 0 })] + end] + [:good_institutions, :bad_institutions].each do |item| + @results[item] = Hash[t('survey_b.institutions').map{|k, i| [k, 0] }] + end + [:person_question, :rate_question, :quality_question].each do |item| + @results[item] = t("survey_b.#{item}_options").map{|o| 0 } + end + @answers.each do |answer| + t('survey_b.institutions').each do |i_key, institution| + if answer[i_key.to_s] + @results[i_key]['count'] += 1 + t('survey_b.questions').keys.each do |q_key| + point = 10 - ( answer[i_key.to_s][q_key.to_s].to_i * 2 ) + @results[i_key][q_key] += point + @results[i_key]['sum'] += point + if q_key != :question6 + @results[i_key]['sum7'] += point + end + end + end + end + [:good_institutions, :bad_institutions].each do |item| + if answer[item.to_s] + answer[item.to_s].each do |institution| + @results[item][institution] += 1 + end + end + end + [:person_question, :rate_question, :quality_question].each do |item| + if answer[item.to_s] + @results[item][answer[item.to_s].to_i] += 1 + end + end + end + t('survey_b.institutions').each do |i_key, institution| + (t('survey_b.questions').keys + ['count', 'sum', 'sum7'] ).each do |q_key| + @results['all'][q_key] += @results[i_key][q_key] + end + end + + @setting = SurveyBSetting.first + + headers['Content-Type'] = "application/vnd.ms-excel" + headers['Content-Disposition'] = "attachment; filename=#{@period.title}.xls" + headers['Cache-Control'] = '' + + render :layout => false + end + end \ No newline at end of file diff --git a/vendor/built_in_modules/survey_b/app/views/panel/survey_b/back_end/periods/_period.html.erb b/vendor/built_in_modules/survey_b/app/views/panel/survey_b/back_end/periods/_period.html.erb index d52eaf483..13394fb47 100644 --- a/vendor/built_in_modules/survey_b/app/views/panel/survey_b/back_end/periods/_period.html.erb +++ b/vendor/built_in_modules/survey_b/app/views/panel/survey_b/back_end/periods/_period.html.erb @@ -14,6 +14,7 @@
  • <%= link_to t(:list_), panel_survey_b_back_end_survey_b_index_path(:period => period, :page => params[:page]) %>
  • <%= link_to t('edit'), edit_panel_survey_b_back_end_period_path(period, :page => params[:page]) %>
  • <%= link_to t(:delete_), panel_survey_b_back_end_period_path(period), :confirm => t('sure?'), :method => :delete %>
  • +
  • <%= link_to t('survey_b.export'), export_panel_survey_b_back_end_survey_b_index_path(:period => period, :page => params[:page]) %>
  • diff --git a/vendor/built_in_modules/survey_b/app/views/panel/survey_b/back_end/survey_b/export.html.erb b/vendor/built_in_modules/survey_b/app/views/panel/survey_b/back_end/survey_b/export.html.erb new file mode 100644 index 000000000..4fa718ac7 --- /dev/null +++ b/vendor/built_in_modules/survey_b/app/views/panel/survey_b/back_end/survey_b/export.html.erb @@ -0,0 +1,257 @@ + + + + + + + + + + + + + +
    標題<%= @period.title rescue '' %>
    問卷前言<%= @setting.description rescue '' %>
    填答人數<%= @answers.count rescue '' %>
    + +

    + +一 、 顧客滿意填表人身分分析 + + + + <% @results[:person_question].each_with_index do |count, option| %> + + <% end %> + + + + <% @results[:person_question].each_with_index do |count, option| %> + + <% end %> + + + + <% @results[:person_question].each_with_index do |count, option| %> + <% @pcount = count.to_f / @answers.count %> + + <% end %> + +
    身份<%= t("survey_b.person_question_options")[option] %>
    填答人數<%= count %>
    比例<%= @pcount == 0 ? "0" : sprintf("%.2f", @pcount * 100 ) %>%
    + +

    + +二、 整體行政品質表現比較分析 + +

    +對於總務處這一、二年之行政品質表現,您感覺是 + + + + <% @results[:quality_question].each_with_index do |count, option| %> + + <% end %> + + + + + <% @qcount = 0 %> + <% @results[:quality_question].each_with_index do |count, option| %> + + <% @qcount = @qcount + count %> + <% end %> + + + + + <% @tqcount = 0 %> + <% @results[:quality_question].each_with_index do |count, option| %> + <% @pcount = count.to_f / @qcount %> + + <% @tqcount = @tqcount + @pcount %> + <% end %> + + +
    行政品質表現<%= t("survey_b.quality_question_options")[option] %>
    填答人數<%= count %><%= @qcount %>
    比例<%= @pcount == 0 ? "0" : sprintf("%.2f", @pcount * 100 ) %>%<%= @tqcount %>
    + +
    +對本處整體行政品質表現給予評鑑分數 + + + + <% @results[:rate_question].each_with_index do |count, option| %> + + <% end %> + + + + + <% @rcount = 0 %> + <% @results[:rate_question].each_with_index do |count, option| %> + + <% @rcount = @rcount + count %> + <% end %> + + + + + <% @tqcount = 0 %> + <% @results[:rate_question].each_with_index do |count, option| %> + <% @pcount = count.to_f / @rcount %> + + <% @tqcount = @tqcount + @pcount %> + <% end %> + + +
    行政品質表現<%= t("survey_b.rate_question_options")[option] %>
    填答人數<%= count %><%= @rcount %>
    比例<%= @pcount == 0 ? "0" : sprintf("%.2f", @pcount * 100 ) %>%<%= @tqcount %>
    + +
    +以您與總務處各單位接觸之經驗,您覺得以下哪一組的服務品質較優。 (可複選) + + + + <% @results[:good_institutions].each do |institution, count| %> + + <% end %> + + + + + <% @gcount = 0 %> + <% @results[:good_institutions].each do |institution, count| %> + + <% @gcount = @gcount + count %> + <% end %> + + + + + <% @tqcount = 0 %> + <% @results[:good_institutions].each do |institution, count| %> + <% @pcount = count.to_f / @gcount %> + + <% @tqcount = @tqcount + @pcount %> + <% end %> + + +
    組別<%= t("survey_b.institutions.#{institution}") %>
    人數<%= count %><%= @gcount %>
    比例<%= @pcount == 0 ? "0" : sprintf("%.2f", @pcount * 100 ) %>%<%= @tqcount %>
    + +
    +以您與總務處各單位接觸之經驗,您覺得以下哪一組的服務品質尚待改進。 (可複選) + + + + <% @results[:bad_institutions].each do |institution, count| %> + + <% end %> + + + + + <% @bcount = 0 %> + <% @results[:bad_institutions].each do |institution, count| %> + + <% @bcount = @bcount + count %> + <% end %> + + + + + <% @tqcount = 0 %> + <% @results[:bad_institutions].each do |institution, count| %> + <% @pcount = count.to_f / @bcount %> + + <% @tqcount = @tqcount + @pcount %> + <% end %> + + +
    組別<%= t("survey_b.institutions.#{institution}") %>
    人數<%= count %><%= @bcount %>
    比例<%= @pcount == 0 ? "0" : sprintf("%.2f", @pcount * 100 ) %>%<%= @tqcount %>
    + +

    +三、 各單位顧客滿意度調查分析 + + + + <% @results[:bad_institutions].each do |institution, count| %> + + <% end %> + + + + <% @tcount = 0 %> + + <% t('survey_b.institutions').each do |i_key, institution| %> + <% if @results[i_key]['count'] == 0 %> + + <% @tcount = @tcount + @results[i_key]['count'] %> + <% else %> + + <% @tcount = @tcount + (( @results[i_key]['sum'].to_f / t('survey_b.questions').count.to_f ) / @results[i_key]['count'].to_f ) %> + <% end %> + <% end %> + + + + <% @tcount = 0 %> + + <% t('survey_b.institutions').each do |i_key, institution| %> + <% if @results[i_key]['count'] == 0 %> + + <% @tcount = @tcount + @results[i_key]['count'] %> + <% else %> + + <% @tcount = @tcount + ( ( @results[i_key]['sum7'].to_f / 7.0 ) / @results[i_key]['count'].to_f ) %> + <% end %> + <% end %> + + + + <% @tcount = 0 %> + + <% t('survey_b.institutions').each do |i_key, institution| %> + + <% @tcount = @tcount + @results[i_key]['count'] %> + <% end %> + + +<% t('survey_b.questions').each do |q_key, question| %> + <% @tcount = 0 %> + + + + <% t('survey_b.institutions').each do |i_key, institution| %> + <% if @results[i_key]['count'] == 0 %> + + <% @tcount = @tcount + @results[i_key]['count'] %> + <% else %> + + <% @tcount = @tcount + ( @results[i_key][q_key].to_f / @results[i_key]['count'].to_f ) %> + <% end %> + <% end %> + + +<% end %> +
    組別<%= t("survey_b.institutions.#{institution}") %>
    <%= t('survey_b.answered_sum') %><%= t('survey_b.no_data') %><%= ( ( @results[i_key]['sum'].to_f / t('survey_b.questions').count.to_f ) / @results[i_key]['count'].to_f ).round(2) %><%= @tcount %>
    <%= t('survey_b.answered_sum7') %><%= t('survey_b.no_data') %><%= ( ( @results[i_key]['sum7'].to_f / 7.0 ) / @results[i_key]['count'].to_f ).round(2) %><%= @tcount %>
    <%= t('survey_b.answered_count') %><%= @results[i_key]['count'] %><%= @tcount %>
    <%= question.sub /\d\./, '' %><%= t('survey_b.no_data') %><%= ( @results[i_key][q_key].to_f / @results[i_key]['count'].to_f ).round(2) %><%= @tcount %>
    + + +

    +您覺得本處之行政品質有那些地方尚待改進嗎? + + + + + +
    填答人數<%= @comment_question.count %>
    + + +

    + + + + + + + + + +
    發佈日期<%= display_date_time @period.start_date %>
    截止日期<%= display_date_time @period.end_date %>
    + diff --git a/vendor/built_in_modules/survey_b/app/views/panel/survey_b/back_end/survey_b/result.html.erb b/vendor/built_in_modules/survey_b/app/views/panel/survey_b/back_end/survey_b/result.html.erb index 0fc0a7a66..2e7c2769c 100644 --- a/vendor/built_in_modules/survey_b/app/views/panel/survey_b/back_end/survey_b/result.html.erb +++ b/vendor/built_in_modules/survey_b/app/views/panel/survey_b/back_end/survey_b/result.html.erb @@ -56,36 +56,77 @@ <% end %> + \ No newline at end of file diff --git a/vendor/built_in_modules/survey_b/config/locales/en.yml b/vendor/built_in_modules/survey_b/config/locales/en.yml index fac061bf7..bcb9e5864 100644 --- a/vendor/built_in_modules/survey_b/config/locales/en.yml +++ b/vendor/built_in_modules/survey_b/config/locales/en.yml @@ -3,6 +3,7 @@ en: survey_b: survey_b: 滿意度調查 result: 結果 + export: 匯出 setting: 設定 description: 前言 diff --git a/vendor/built_in_modules/survey_b/config/locales/zh_tw.yml b/vendor/built_in_modules/survey_b/config/locales/zh_tw.yml index 2929e947e..790592b90 100644 --- a/vendor/built_in_modules/survey_b/config/locales/zh_tw.yml +++ b/vendor/built_in_modules/survey_b/config/locales/zh_tw.yml @@ -3,6 +3,7 @@ zh_tw: survey_b: survey_b: 滿意度調查 result: 結果 + export: 匯出 setting: 設定 description: 前言 diff --git a/vendor/built_in_modules/survey_b/config/routes.rb b/vendor/built_in_modules/survey_b/config/routes.rb index 62ceee74b..23fd4a666 100644 --- a/vendor/built_in_modules/survey_b/config/routes.rb +++ b/vendor/built_in_modules/survey_b/config/routes.rb @@ -7,6 +7,7 @@ Rails.application.routes.draw do collection do get 'result' get 'delete' + get 'export' end end resources :periods