<%= form_tag(get_open_cash_registers_path, method: :post, :html => {:class=>"form-horizontal", :id=> "open_cash_registers_form"}) do |f| %>
  <div class="portlet-body form">
    <div id="error_explanation"></div>
    <div class="row">
      <div class="col-md-12">
        <!-- caja registradora -->
        <div class="form-group">
          <%= label_tag :open_cash_register_id, "Seleccionar caja registradora", {:class=>"col-md-4 control-label"} do %> Caja registradora
          <span class="required">*</span>
          <% end %>
          <div class="input-group col-md-4 select2-bootstrap-prepend">
            <%= select_tag :open_cash_register_id, options_for_select(Pointsale.find(current_user.pointsale_id).open_cash_registers.where("open_cash_registers.status = 0").map{|o| [o.cash_register.name, o.id]}), class: 'form-control select2', include_blank: 'Seleccione' %>
          </div>
        </div>    
      </div>
    </div>

    <h4 class="form-section" style="margin:20px 0px 10px 0px"></h4>
    <div class="actions">
      <%= submit_tag 'guardar', {:class=>"hidden"} %>
      <button type="button" class="btn btn-success" onclick="submitForm()" id="openCashButton">Realizar corte de caja</button>
    </div>
  </div>
<% end %>
<script>
  $(document).ready(function() {
    $('#openCashButton').attr('disabled', true);   
  });

  $('#open_cash_register_id').on('change', function() {
    if ($(this).val() != "") {
      $('#openCashButton').attr('disabled', false);
    } else {
      $('#openCashButton').attr('disabled', true);
    }
  });  

  function submitForm() {
    // $('#dialog').modal('toggle');
    // $('#open_cash_register_id').val();
    // window.location = "/cash_outs/new/" + $('#open_cash_register_id').val() ; 
 
    $.ajax({
      type:'post', 
      url: '/select_open_cash_to_close/' + $('#open_cash_register_id').val()
    });
  }
</script>