<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>Cajas abiertas</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 cajas abiertas</span>
                  </div> 
                </div>
                <div class="portlet-body">
                  <table class="table table-striped table-bordered table-hover tableadvanced" id="cash_outs_table">
                    <thead>
                      <tr>
                        <th>#</th>
                        <th>Punto de venta</th> 
                        <th>Caja registradora</th>
                        <th>Ingresos</th>
                        <th>Egresos</th>
                        <th>Total</th>
                        <th>Usuario</th>
                        <th>Hora apertura</th>
                      </tr>
                    </thead>
                    <tbody>
                      <% @opened_cash_registers.each_with_index do |open_cash, key| %>
                        <tr>
                          <td><%= key + 1 %></td>
                          <td>
                            <%= OpenCashRegister.get_pointsale(open_cash.id, "open_cash_register").name %> 
                          </td> 
                          <td><%= open_cash.cash_register.name %> </td>
                          <td>
                            <% amount_in =  CashRegistersMove.where(:open_cash_register => open_cash.id, :move_type =>  1).sum(:quantity) %> 
                           <%= number_to_currency(amount_in, precision: 2) %>
                          </td>
                          <td>
                            <% amount_out = CashRegistersMove.where(:open_cash_register => open_cash.id, :move_type =>  0).sum(:quantity) %>
                           <%= number_to_currency(amount_out, precision: 2) %>   
                           </td>
                           <td>
                             <%= number_to_currency((amount_in - amount_out), precision: 2) %>   
                           </td>
                          <td><%= open_cash.user.first_name %></td>
                          <td><%= l(open_cash.created_at, :format => '%I:%M %p') %></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