<table border="1">
  <tr>
   <td>標題</td>
   <td><%= @period.title rescue '' %></td>
 </tr>
  <tr>
   <td>問卷前言</td>
   <td><%= @setting.description rescue '' %></td>
 </tr>
  <tr>
   <td>填答人數</td>
   <td><%= @answers.count rescue '' %></td>
 </tr>
</table>

<br /><br />

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

<br /><br />

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

<br /><br />
對於總務處這一、二年之行政品質表現，您感覺是
<table border="1">
  <tr>
   <td>行政品質表現</td>
   <% @results[:quality_question].each_with_index do |count, option| %>
      <td><%= t("survey_b.quality_question_options")[option] %></td>
   <% end %>
   <td></td>
 </tr>
  <tr>
   <td>填答人數</td>
   <% @qcount = 0 %>
   <% @results[:quality_question].each_with_index do |count, option| %>
      <td><%= count %></td>
      <% @qcount = @qcount + count %>
   <% end %>
   <td><%= @qcount %></td>
 </tr>
  <tr>
   <td>比例</td>
   <% @tqcount = 0 %>
   <% @results[:quality_question].each_with_index do |count, option| %>
      <% @pcount = count.to_f / @qcount  %>
      <td><%= @pcount == 0 ? "0" : sprintf("%.2f", @pcount * 100 )  %>%</td>
      <% @tqcount = @tqcount + @pcount %>
   <% end %>
   <td><%= @tqcount %></td>
 </tr>
</table>

<br />
對本處整體行政品質表現給予評鑑分數
<table border="1">
  <tr>
   <td>行政品質表現</td>
   <% @results[:rate_question].each_with_index do |count, option| %>
      <td><%= t("survey_b.rate_question_options")[option] %></td>
   <% end %>
   <td></td>
 </tr>
  <tr>
   <td>填答人數</td>
   <% @rcount = 0 %>
   <% @results[:rate_question].each_with_index do |count, option| %>
      <td><%= count %></td>
      <% @rcount = @rcount + count %>
   <% end %>
   <td><%= @rcount %></td>
 </tr>
  <tr>
   <td>比例</td>
   <% @tqcount = 0 %>
   <% @results[:rate_question].each_with_index do |count, option| %>
      <% @pcount = count.to_f / @rcount  %>
      <td><%= @pcount == 0 ? "0" : sprintf("%.2f", @pcount * 100 )  %>%</td>
      <% @tqcount = @tqcount + @pcount %>
   <% end %>
   <td><%= @tqcount %></td>
 </tr>
</table>

<br />
以您與總務處各單位接觸之經驗，您覺得以下哪一組的服務品質較優。 (可複選)
<table border="1">
  <tr>
   <td>組別</td>
   <% @results[:good_institutions].each do |institution, count| %>
      <td><%= t("survey_b.institutions.#{institution}") %></td>
   <% end %>
   <td></td>
 </tr>
  <tr>
   <td>人數</td>
   <% @gcount = 0 %>
   <% @results[:good_institutions].each do |institution, count| %>
      <td><%= count %></td>
      <% @gcount = @gcount + count %>
   <% end %>
   <td><%= @gcount %></td>
 </tr>
  <tr>
   <td>比例</td>
   <% @tqcount = 0 %>
   <% @results[:good_institutions].each do |institution, count| %>
      <% @pcount = count.to_f / @gcount  %>
      <td><%= @pcount == 0 ? "0" : sprintf("%.2f", @pcount * 100 )  %>%</td>
      <% @tqcount = @tqcount + @pcount %>
   <% end %>
   <td><%= @tqcount %></td>
 </tr>
</table>

<br />
以您與總務處各單位接觸之經驗，您覺得以下哪一組的服務品質尚待改進。 (可複選)
<table border="1">
  <tr>
   <td>組別</td>
   <% @results[:bad_institutions].each do |institution, count| %>
      <td><%= t("survey_b.institutions.#{institution}") %></td>
   <% end %>
   <td></td>
 </tr>
  <tr>
   <td>人數</td>
   <% @bcount = 0 %>
   <% @results[:bad_institutions].each do |institution, count| %>
      <td><%= count %></td>
      <% @bcount = @bcount + count %>
   <% end %>
   <td><%= @bcount %></td>
 </tr>
  <tr>
   <td>比例</td>
   <% @tqcount = 0 %>
   <% @results[:bad_institutions].each do |institution, count| %>
      <% @pcount = count.to_f / @bcount  %>
      <td><%= @pcount == 0 ? "0" : sprintf("%.2f", @pcount * 100 )  %>%</td>
      <% @tqcount = @tqcount + @pcount %>
   <% end %>
   <td><%= @tqcount %></td>
 </tr>
</table>

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


<br /><br />
您覺得本處之行政品質有那些地方尚待改進嗎？ 
<table border="1">
  <tr>
   <td>填答人數</td>
   <td><%= @comment_question.count %></td>
 </tr>
</table>


<br /><br />
<table border="0">
  <tr>
   <td>發佈日期</td>
   <td><%= display_date_time @period.start_date %></td>
 </tr>
  <tr>
   <td>截止日期</td>
   <td><%= display_date_time @period.end_date %></td>
 </tr>
</table>

