<h3>Earnings by Month</h3>
<table class="index_table index">
  <thead>
    <tr>
      <th>Month</th>
      <th>JamTracks</th>
      <th>Subscriptions</th>
      <th>Affiliate Earnings</th>
    </tr>
  </thead>
  <tbody>
    <% AffiliateMonthlyPayment.index(affiliate_partner.partner_user, {})[0].each do |payment| %>
      <tr>
        <td>
          <%= Date::MONTHNAMES[payment.month] if payment.month %>
          <%= payment.year %>
        </td>
        <td>
          <% if payment.jamtracks_sold > 0 %>
            JamTracks: <%= pluralize payment.jamtracks_sold, 'unit' %>
          <% end %>
        </td>
        <td>
          <%
            month_start = Date.new(payment.year, payment.month, 1)
            month_end   = Date.new(payment.year, payment.month, 1).end_of_month
            AffiliateDistribution.subscription_plans_count(affiliate_partner.id, month_start, month_end).each do |plan_count|
            %>
            <div>
              <%= subscription_plan_name(plan_count[:plan]) -%>: <%= pluralize(plan_count.count, 'unit') -%> sold
            </div>
            <%
            end
          %>
        </td>
        <td>
          <%= number_to_currency(payment.due_amount_in_cents.to_f/100.0) %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>