BathHacked/energy-sparks

View on GitHub
app/views/admin/reports/tariffs/index.html.erb

Summary

Maintainability
Test Coverage
<% content_for :page_title, 'Tariffs report' %>

<h1>Data report for tariffs</h1>

<div class="row">
  <table class="table table-striped">
    <thead>
    <tr>
      <th>School</th>
      <th>Smart Meter Tariffs</th>
      <th>Number of tariffs</th>
      <th>Earliest date range</th>
      <th>Latest date range</th>
    </tr>
    </thead>
    <tbody>
    <% @group_meters.each do |school_group_name, school_meters| %>
      <% name = school_group_name || 'Ungrouped' %>
      <tr class='table-active' id='<%=name.parameterize%>' ><td colspan="8"><strong><%= name %></strong></td></tr>
      <% school_meters.each do |school, meters| %>
        <% meters.each do |meter| %>
          <% meter_energy_tariffs = meter.energy_tariffs.order(:start_date) %>
          <tr>
            <td><%= link_to(school.name, school_path(school)) %></td>
            <td><%= link_to icon_and_display_name(meter), smart_meter_tariffs_school_energy_tariffs_path(school) %></td>
            <td><%= meter_energy_tariffs.count %></td>
            <td><%= formatted_date_range_for(meter_energy_tariffs.first) if meter_energy_tariffs.count > 1 %></td>
            <td><%= formatted_date_range_for(meter_energy_tariffs.last) %></td>
          </tr>
        <% end %>
      <% end %>
    <% end %>
    </tbody>
  </table>
</div>