<!-- BEGIN CONTAINER -->
<div class="page-container">
  <!-- BEGIN CONTENT -->
  <div class="page-content-wrapper">
    <!-- BEGIN CONTENT BODY -->
    <!-- BEGIN PAGE HEAD-->
    <div class="page-head">
      <div class="container-fluid">
        <!-- BEGIN PAGE TITLE -->
        <div class="page-title">
          <h1>Compra </h1>
        </div>
        <!-- END PAGE TITLE -->
      </div>
    </div>
    <!-- END PAGE HEAD-->
    <!-- BEGIN PAGE CONTENT BODY -->
    <div class="page-content">
      <div class="container-fluid">
        <div class="pull-right margin-bottom-10 ">
          <%= link_to  purchases_path(:filter => @filter, :current_page => @current_page), {:class=>"fr-space btn blue-hoki "} do %> 
            <i class="fa fa-angle-left "></i>
            Regresar
          <% end %>
        </div>
        <!-- BEGIN PAGE BREADCRUMBS -->
        <ul class="page-breadcrumb breadcrumb">
          <%= render_breadcrumbs :tag => :li, :separator => ' <i class="fa fa-circle"></i> ' %>
        </ul>
        <!-- END PAGE BREADCRUMBS -->
        <!-- BEGIN PAGE CONTENT INNER -->
        <div class="page-content-inner margin-top-10">
          <div class="row">
            <!-- informacion de la venta -->
            <div class="col-md-3 col-sm-12">
              <div class="portlet light bordered ">
                <div class="portlet-title">
                  <div class="caption"> <i class="fa fa-shopping-cart"></i>Información de la compra </div>
                </div>
                <div class="portlet-body">
                  <div class="row static-info">
                    <div class="col-md-1 name"> <i class="fa fa-barcode"></i> </div>
                    <div class="col-md-8 value"> <%= @purchase.purchase_code %> </div>
                  </div>
                  <div class="row static-info">
                    <div class="col-md-1 name"> <i class="fa fa-odnoklassniki"></i> </div>
                    <div class="col-md-8 value"> <%= @purchase.user.first_name %> </div>
                  </div>
                  <div class="row static-info">
                    <div class="col-md-1 name"> <i class="fa fa-fw fa-cart-plus"></i> </div>
                    <div class="col-md-8 value"> <%= @purchase.pointsale.present? ? @purchase.pointsale.name : @purchase.warehouse.name %> </div>
                  </div>
                  <div class="row static-info">
                    <div class="col-md-1 name"> <i class="fa fa-fw fa-suitcase"></i> </div>
                    <div class="col-md-8 value"> <%= @purchase.supplier.nick_name %> </div>
                  </div>
                  <div class="row static-info">
                    <div class="col-md-1 name"> <i class="fa fa-calendar-o"></i> </div>
                    <div class="col-md-8 value"> <%= l(@purchase.purchase_date, :format => '%A, %d de %B de %Y') %> </div>
                  </div>
                  <div class="row static-info">
                    <div class="col-md-1 name"> <i class="fa fa-fw fa-cubes"></i> </div>
                    <div class="col-md-8 value"> <%= @purchase.products.count %> producto(s)</div>
                  </div>
                  <div class="row static-info">
                    <div class="col-md-1 name"> <i class="fa fa-flag"></i> </div>
                    <div class="col-md-8 value"> 
                      <% if @purchase.status == "cancelled" %>
                        <span class="label label-sm label-danger"> <i class="fa fa-times"></i> Cancelada </span>
                      <% else %> 
                        <span class="label label-sm label-success"> <i class="fa fa-check"></i> Activa </span>

                      <% end %>
                    </div>
                  </div>
                  <div class="row static-info">
                    <div class="col-md-1 name"><i class="fa fa-info"></i></div>
                    <div class="col-md-8 value"> 
                        <span class="label label-sm label-primary">
                          <% if @purchase.is_in_dollars %>
                            Compra en dolares 
                          <% else %>
                            Compra en pesos
                          <% end %>
                        </span>
                    </div>
                  </div>                  
                  <div class="row static-info">
                    <div class="col-md-1 name"> <i class="fa fa-money"></i> </div>
                    <div class="col-md-8 value"> <%= number_to_currency(@purchase.total, precision: 2) %> <%= @purchase.is_in_dollars ? 'USD' : 'MXN'%></div>
                  </div>                
                </div>
              </div>
            </div>
            <!-- detalle de los productos -->
            <div class="col-md-9 col-sm-12">
              <div class="portlet light bordered ">
                <div class="portlet-title">
                  <div class="caption"> 
                    <i class="fa fa-fw fa-cubes"></i>Detalle de los productos
                  </div>
                </div>
                <% if @purchase.is_in_dollars %>
                  <h4 class="pull-right">Tipo de cambio: <%= number_to_currency(@purchase.exchange, precision: 2) %> </h4>                
                <% end %>
                <div class="portlet-body">  
                  <table class="table table-striped table-hover">
                    <thead>
                      <tr>
                        <th>#</th>
                        <th>SKU</th>
                        <th>Imagen</th>
                        <th>Producto</th>
                        <th>Cantidad</th>
                        <% if @purchase.is_in_dollars %>
                          <th>Precio USD</th>
                        <% end %>
                        <th>Precio MXN</th>
                        <th>IVA</th>
                        <th>Importe</th>
                      </tr>
                    </thead>
                    <tbody>
                      <% @purchase.purchase_details.each_with_index do |detail, key| %>
                        <tr>
                          <td> <%= key + 1 %> </td>
                          <td> <%= detail.product.sku %> </td>
                          <td> <img src="<%= detail.product.small_img %>" width="50" height="50"/> </td>
                          <td> 
                            <%= detail.product.name %><br>
                            <%= detail.product.display_attributes %> 
                          </td>
                          <td> <%= detail.quantity.round %> </td>
                          <% if @purchase.is_in_dollars %>
                            <td> <%= number_to_currency(detail.price, precision: 2) %> USD </td>
                            <td> <%= number_to_currency(detail.price * @purchase.exchange, precision: 2) %> MXN </td>
                          <% else %>
                            <td> <%= number_to_currency(detail.price, precision: 2) %> MXN </td>
                          <% end %>
                          <td> <%= number_to_currency(detail.tax, precision: 2) %> MXN</td>
                          <% if @purchase.is_in_dollars %>
                            <td> <%= number_to_currency(detail.amount * @purchase.exchange, precision: 2) %> MXN</td>
                          <% else %>
                            <td> <%= number_to_currency(detail.amount, precision: 2) %> MXN</td>
                          <% end %>
                        </tr>
                      <% end %>
                    </tbody>
                  </table>              
                </div>
              </div>            
            </div> 
          </div>
        </div>
        <!-- END PAGE CONTENT INNER -->
      </div>
    </div>
    <!-- END PAGE CONTENT BODY -->
    <!-- END CONTENT BODY -->
  </div>
  <!-- END CONTENT -->
</div>
  <!-- END CONTAINER