<div class="row">
  <div class="col-md-2 col-sm-3 col-xs-3">
    <ul class="nav nav-tabs tabs-left">
      <li class="active">
          <a href="#recibidos" data-toggle="tab"> Recibidos </a>
      </li>
      <li>
          <a href="#enviados" data-toggle="tab"> Enviados </a>
      </li>                    
    </ul>
  </div>
  <div class="col-md-10 col-sm-9 col-xs-9">
     <div class="tab-content">
        <div class="tab-pane active" id="recibidos">
          <div class="row">
            <div class="col-md-12">
              <table class="table table-striped table-bordered table-hover tableadvanced">
                <thead>
                  <tr>
                    <th>#</th>
                    <th>Fecha</th>
                    <th>Origen</th>
                    <th>Productos</th>
                    <th>Status</th>
                    <th>Status recepción</th>                       
                    <th>Acciones</th>
                  </tr>
                </thead>
                <tbody>
                  <% @received.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.products.count %> </td>
                      <td>
                          <% 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>
                        <% elsif transfer.received? %>
                          <i class='fa fa-check fa-2 font-green'></i> 
                        <% end %>
                      </td>                       
                      <td>
                        <%= link_to transfer, {:class=>"btn btn-icon-only default", :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 %>                        
                        <% if transfer.status =="pending" %>
                          <%= link_to verify_transfer_path(transfer), {:class=>"btn btn-icon-only green-meadow", :title=>"Verificar traspaso"} do %>
                            <i class="fa fa-check-square-o"></i>
                          <% end %>                              
                        <% end %>
                      </td>
                    </tr>
                  <% end %>            
                </tbody>
              </table>                            
            </div>                                  
          </div>
        </div>
        <div class="tab-pane fade" id="enviados">
          <div class="row">
            <div class="col-md-12">
              <table class="table table-striped table-bordered table-hover tableadvanced">
                <thead>
                  <tr>
                    <th>#</th>
                    <th>Fecha</th>
                    <th>Destino</th>
                    <th>Productos</th>
                    <th>Status</th>
                    <th>Status recepción</th>                    
                    <th>Acciones</th>
                  </tr>
                </thead>
                <tbody>
                  <% @sent.each_with_index do |transfer, key| %>
                    <tr>
                      <td> <%= key +1 %> </td>
                      <td> <%= l(transfer.transfer_date, :format => '%d/%B/%Y') %> </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>
                          <% 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>
                        <% elsif transfer.received? %>
                          <i class='fa fa-check fa-2 font-green'></i>                           
                        <% end %>
                      </td>                      
                      <td>
                        <%= link_to transfer, {:class=>"btn btn-icon-only default", :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>
        </div>
     </div>
  </div>
</div>
