<!-- 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>Devoluciones</h1>
        </div>
        <!-- END PAGE TITLE -->
      </div>
    </div>
    <!-- END PAGE HEAD-->
    <!-- BEGIN PAGE CONTENT BODY -->
    <div class="page-content">
      <div class="container-fluid">
        <!-- 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">
          <div id="notice">
          <% if success %>
            <div class="alert alert-success">
              <p><%= success %></p>
            </div>
          <% elsif warning %>
            <div class="alert alert-warning">
              <p><%= warning %></p>
            </div>
          <% end %>
          </div>
          <div class="row">
            <div class="col-md-12">
              <div class="portlet light ">
                <div class="portlet-title">
                  <div class="caption">
                    <i class="fa fa-list "></i>
                    <span class="caption-subject bold uppercase">Lista de devoluciones</span>
                  </div>
                  <div class="actions">
                    <% if session[:open_cash_register_id].present?%>
                      <% if can? :create, ProductsReturn %>
                        <%= link_to new_products_return_path, :class=>"btn bold green pull-right" do %> Nueva devolución <i class="fa fa-plus"></i><% end %>
                      <% end %>
                    <% else %>
                      <div class="alert alert-warning pull-right">Para agregar una devolucion se necesita una caja abierta. </div>
                    <% end %>
                  </div>
                </div>
                <div class="portlet-body">
                  <table class="table table-striped table-bordered table-hover tableadvanced">
                    <thead>
                      <tr>
                        <th>Folio</th>
                        <% if current_user.usertype == "A" %>
                          <th>Punto de venta</th>
                        <% end %>
                        <th>Fecha</th>
                        <th>Venta</th>
                        <th>Productos devueltos</th>
                        <th>Nuevo monto</th>
                        <th>Monto devuelto</th>
                        <th>Diferencia</th>
                        <th>Responsable</th>
                        <th width="15%">Acciones</th>
                      </tr>
                    </thead>
                    <tbody>
                    <% @products_returns.each_with_index do |product_return, key| %>
                        <tr>
                          <td> <%= product_return.return_code %></td>
                          <% if current_user.usertype == "A" %>
                            <td><%= product_return.pointsale.name %></td>
                          <% end %>
                          <td><%= l(product_return.created_at, :format => '%d/%m/%Y') %></td>
                          <td><%= product_return.sale.sale_code %></td>
                          <td><%= product_return.products_return_ins.sum(:quantity).round %></td>
                          <td><%= number_to_currency(product_return.new_amount, precision: 2)%></td>
                          <td><%= number_to_currency(product_return.returned_amount, precision: 2) %></td>
                          <td><%= number_to_currency(product_return.difference_amount, precision: 2)%></td>
                          <td><%= product_return.user.first_name %></td>
                          <td>
                            <%= link_to sale_path(product_return.sale), {:class=>"btn btn-icon-only default", :title=>"Ver detalle de la devolución"} do %> <i class="fa fa-search"></i> <% end %>
                          </td>
                        </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 -->
