sql行结果行转列现实,以及数值/百分比显示切换

<div class="ui blue segment">
  <div class="right floated ui mini buttons"> 
    <button class="ui mini button green show_data">#</button>
    <button class="ui mini button show_rake">%</button>
  </div>
  <table class="ui selectable striped celled table">
    <thead>
    <tr>
      <th class="center aligned" style="width: 10%;">Time</th>
      <th class="center aligned" style="width: 10%;">Client Development</th>
      <th class="center aligned" style="width: 15%;">Beginning of Month</th>
      <th class="center aligned" style="width: 15%;">End of Month</th>
      <th class="center aligned" style="width: 15%;">Trend</th>
    </tr>
    </thead>
    <tbody>
    <% (@reports_detail_size-1).times.each do |index| %>
        <tr >
          <td rowspan="5"><%= @reports_detail[index]['created_at'].strftime('%Y-%m-%d') %> - <%= @reports_detail[index+1]['created_at'].strftime('%Y-%m-%d') %></td>
          <td>Total Client</td>
          <td>
            <span class='date'><%= a = @reports_detail[index]['buyer_count'] ; a %></span>
            <span class="rake">--</span>
          </td>
          <td>
            <span class='date'><%= b = @reports_detail[index+1]['buyer_count'] ; b %></span>
            <span class="rake">--</span>
          </td>
          <td class="center aligned" >
            <span class='date'><%= c = b - a ; c.abs %> <i class="long arrow <%= c.to_i > 0 ? 'up' : 'down'%> icon"></i> </span>
            <span class="rake"><%= cc = (a - b ) *  100 / a ; cc.abs.round(2) %>% <i class="long arrow <%= cc.to_i > 0 ? 'up' : 'down'%> icon"></i> </span>
          </td>
        </tr>
        <tr >
          <td>No Contact</td>
          <td>
            <span class='date'><%= d = @reports_detail[index]['buyer_no_contact'] ; d %></span>
            <span class="rake"><%= dd = d * 100 / a ; dd.round(2) %>%</span>
          </td>
          <td>
            <span class='date'><%= e = @reports_detail[index+1]['buyer_no_contact'] ; e %></span>
            <span class="rake"><%= ee = e * 100 / b ; ee.round(2) %>%</span>
          </td>
          <td class="center aligned" >
            <span class='date'><%= f = e - d ; f.abs %> <i class="long arrow <%= f.to_i > 0 ? 'up' : 'down'%> icon"></i> </span>
            <span class="rake"><%= ff = (ee - dd) * 100 / ee ; ff.abs.round(2) %>% <i class="long arrow <%= ff.to_i > 0 ? 'up' : 'down'%> icon"></i> </span>
          </td>
        </tr>
        <tr >
          <td>Contacting</td>
          <td>
            <span class='date'><%= g = @reports_detail[index]['buyer_contacting'] ; g %></span>
            <span class="rake"><%= gg = g * 100 / a ; gg.round(2) %>%</span>
          </td>
          <td>
            <span class='date'><%= h = @reports_detail[index+1]['buyer_contacting'] ; h %></span>
            <span class="rake"><%= hh = h * 100 / b ; hh.round(2) %>%</span>
          </td>
          <td class="center aligned" >
            <span class='date'><%= i = h-g ; i.abs %> <i class="long arrow <%= i.to_i > 0 ? 'up' : 'down'%> icon"></i> </span>
            <span class="rake"><%= ii = (hh - gg) * 100 / hh ; ii.abs.round(2) %>% <i class="long arrow <%= ii.to_i > 0 ? 'up' : 'down'%> icon"></i> </span>
          </td>
        </tr>
        <tr >
          <td>Developed</td>
          <td>
            <span class='date'><%= j = @reports_detail[index]['buyer_developed'] ; j %></span>
            <span class="rake"><%= jj = j * 100 / a ; jj.round(2) %>%</span>
          </td>
          <td>
            <span class='date'><%= k = @reports_detail[index+1]['buyer_developed'] ; k %></span>
            <span class="rake"><%= kk = k * 100 / b ; kk.round(2) %>%</span>
          </td>
          <td class="center aligned" >
            <span class='date'><%= l = k-j ; l.abs %> <i class="long arrow <%= l.to_i > 0 ? 'up' : 'down'%> icon"></i> </span>
            <span class="rake"><%= ll = (kk - jj) * 100 / kk ; ll.abs.round(2) %>% <i class="long arrow <%= ll.to_i > 0 ? 'up' : 'down'%> icon"></i> </span>
          </td>
        </tr>
        <tr >
          <td>Failed</td>
          <td>
            <span class='date'><%= m = @reports_detail[index]['buyer_failed'] ; m %></span>
            <span class="rake"><%= mm = m * 100 / a ; mm.round(2) %>%</span>
          </td>
          <td>
            <span class='date'><%= n = @reports_detail[index+1]['buyer_failed'] ; n %></span>
            <span class="rake"><%= nn = n * 100 / b ; nn.round(2) %>%</span>
          </td>
          <td class="center aligned" >
            <span class='date'><%= q = n-m ; q.abs %> <i class="long arrow <%= q.to_i > 0 ? 'up' : 'down'%> icon"></i> </span>
            <span class="rake"><%= qq = nn == 0 ? 0 : (nn - mm) * 100 / nn ; qq.abs.round(2) %>% <i class="long arrow <%= qq.to_i > 0 ? 'up' : 'down'%> icon"></i> </span>
          </td>
        </tr>
    <% end %>
    </tbody>
  </table>

</div>

猜你喜欢

转载自schooltop.iteye.com/blog/2382305