<div class="row">
  <div class="col-md-12">
    <input type='hidden' name='filter' id='filter' value='<%= @filter %>' >
    <input type='hidden' name='current_page' id='current_page' value='<%= @current_page %>' >
    <table class="table table-striped table-bordered table-hover tableadvanced">
      <thead>
        <tr>
          <th>#</th>
          <th>Fecha</th>
          <th>Origen</th>
          <th>Destino</th>
          <th>Productos</th>
          <th>Status</th>
          <th>Status recepción</th>
          <th>Acciones</th>
        </tr>
      </thead>
      <tbody>
        <% @transfers.each_with_index do |transfer, key| %>
          <tr>
            <td> <%= key +1 %> </td>
            <td> <%= l(transfer.transfer_date, :format => '%d/%B/%Y') %> </td>
            <td>
             <%= transfer.origin_is_pointsale == 1 ? Pointsale.find(transfer.origin_id).name : Warehouse.find(transfer.origin_id).name %>
            </td>
            <td>
              <%= transfer.destiny_is_pointsale == 1 ? Pointsale.find(transfer.destiny_id).name : Warehouse.find(transfer.destiny_id).name %>
            </td>
            <td> <%= transfer.products.count %> </td>
            <td class="text-center">
                <% case transfer.status %>
                  <% when "cancelled" %>
                    <span class="label label-danger"> CANCELADO </span>
                  <% when "pending" %>
                    <span class="label bg-yellow-crusta"> PENDIENTE DE RECEPCIÓN </span>
                  <% when "received" %>
                    <span class="label label-success"> RECIBIDO </span>
                <% end %>
            </td>
            <td class="text-center">
              <% if transfer.transfer_details.where(:has_looses => 1).count > 0 &&
                transfer.transfer_details.where(:has_surplus => 1).count == 0 %>
                <span class="label label-warning"> CON PERDIDAS </span>
              <% elsif transfer.transfer_details.where(:has_surplus => 1).count > 0 &&
                transfer.transfer_details.where(:has_looses => 1).count == 0 %>
                <span class="label label-warning"> CON EXCEDENTE </span>
              <% elsif transfer.transfer_details.where(:has_surplus => 1).count > 0  &&
              transfer.transfer_details.where(:has_looses => 1).count > 0 %>
                <span class="label label-danger"> CON INCONSISTENCIAS </span>
              <% end %>
            </td>
            <td class="text-center">
              <%= link_to transfer, {:class=>"btn btn-icon-only default filtros", :title=>"Ver traspaso"} do %>
                <i class="fa fa-search"></i>
              <% end %>
              <%= link_to print_transfer_receipt_path(transfer.id, format: 'pdf'), {:class=>"btn btn-icon-only default", :target => "blank"} do %>
                <i class="fa fa-print"></i>
              <% end %>
            </td>
          </tr>
        <% end %>
      </tbody>
    </table>
  </div>
</div>
