<%= form_for(@pos_config, :html => { class: "form-horizontal" }) do |f| %>
<div class="portlet-body form">
  <% if @pos_config.errors.any? %>
    <div class="alert alert-danger">
      <strong>Tiene <%= pluralize(@pos_config.errors.count, "error") %> no se puede guardar la configuración</strong><br>
    </div>
  <% end %>
  <div class="form-body">
    <div class="row">
      <div class="col-md-11 col-sm-12">
        <div class="form-group">
          <%= f.label :cancel_partial_payment, { class: "col-md-3 col-sm-6 control-label" } do %>Días para cancelar abono
            <span class="required">*</span>
          <% end %>
          <div class="col-md-1 col-sm-3">
            <%= f.number_field :cancel_partial_payment, { class: "form-control input-xsmall" } %>
          </div>
          <%= f.label :refund_sale, { class: "col-md-3 col-sm-6 control-label" } do %>Días para aceptar devolución
            <span class="required">*</span>
          <% end %>
          <div class="col-md-1 col-sm-3">
            <%= f.number_field :refund_sale, { class: "form-control input-xsmall" } %>
          </div>
        </div>
        <div class="form-group">
          <%= f.label :days_cancel_sale, { class: "col-md-3 col-sm-6 control-label" } do %>Días para cancelar venta
            <span class="required">*</span>
          <% end %>
          <div class="col-md-1 col-sm-3">
            <%= f.number_field :days_cancel_sale, { class: "form-control input-xsmall" } %>
          </div>
          <%= f.label :days_cancel_purchase, { class: "col-md-3 col-sm-6 control-label"} do %>Días para cancelar compra
            <span class="required">*</span>
          <% end %>
          <div class="col-md-1 col-sm-3">
            <%= f.number_field :days_cancel_purchase, { class: "form-control input-xsmall" } %>
          </div>
        </div>
        <div class="form-group">
          <%= f.label :reserve_sale_percent, { class: "col-md-3 col-sm-6 control-label" } do %>Porcentaje para realizar apartado
            <span class="required">*</span>
          <% end %>
          <div class="col-md-1 col-sm-3">
            <%= f.number_field :reserve_sale_percent, { class: "form-control input-xsmall" } %>
          </div>
          <%= f.label :days_cancel_reserved, { class: "col-md-3 control-label" } do %>Días para cancelar apartado
            <span class="required">*</span>
          <% end %>
          <div class="col-md-1">
            <%= f.number_field :days_cancel_reserved, { class: "form-control input-xsmall" } %>
          </div>
        </div>
        <div class="form-group">
          <%= f.label :tax_percent, { class: "col-md-3 control-label" } do %>IVA a aplicar
            <span class="required">*</span>
          <% end %>
          <div class="col-md-1">
            <%= f.number_field :tax_percent, { class: "form-control input-xsmall" } %>
          </div>
          <%= f.label :commission_percent, { class: "col-md-3 control-label" } do %>Porcentaje por comisión de venta
            <span class="required">*</span>
          <% end %>
          <div class="col-md-1">
            <%= f.number_field :commission_percent, { class: "form-control input-xsmall" } %>
          </div>
        </div>
        <div class="form-group">
          <%= f.label :gain_margin, { class: "col-md-3 control-label" } do %>Porcentaje de margen de ganancia
            <span class="required">*</span>
          <% end %>
          <div class="col-md-1">
            <%= f.number_field :gain_margin, { class: "form-control input-xsmall" } %>
          </div>
          <%= f.label :enable_haggle, { class: "col-md-3 control-label" } do %> ¿Permitir regateo en ventas? <span class="required">*</span><% end %>
          <div class="col-md-1">
            <%= f.check_box(:enable_haggle,
              {
                class: "make-switch",
                data: {
                  on_color: "success",
                  off_color: "danger",
                  on_text: "Si",
                  off_text: "No"
                }
              }, "true","false"
            ) %>
            <%= f.hidden_field :enable_haggle %>
          </div>
        </div>
        <div class="form-group">
          <div id="haggle_div" class="<%= 'hidden' unless @pos_config.enable_haggle %>">
            <%= f.label :haggle_in_sale_percent, { class: "col-md-3 control-label" } do %>Porcentaje máximo de regateo para ventas
              <span class="required">*</span>
            <% end %>
            <div class="col-md-3">
              <%= f.number_field :haggle_in_sale_percent, { class: "form-control input-xsmall" } %>
            </div>
          </div>
        </div>
        <div class="form-group">
          <%= f.label :time_zone, { class: "col-md-3 control-label" } do %>Zona horaria
            <span class="required">*</span>
          <% end %>
          <div class="col-md-1">
            <%= f.time_zone_select :time_zone, ActiveSupport::TimeZone.us_zones, {}, {:class => 'form-control select2 input-large' } %>
          </div>
        </div>
        <div class="form-group">
          <%= f.label :ticket_description, { class: "col-md-3 control-label" } do %>Encabezado para tickets
            <span class="required">*</span>
          <% end %>
          <div class="col-md-7">
            <%= f.text_area :ticket_description, { class: "form-control", rows: 5 } %>
            <span class="help-block">Si no se especifica un encabezado para cada uno de los puntos de venta, se usará este de manera general.</span>
          </div>
        </div>
        <div class="form-group">
          <%= f.label :ticket_footer, { class: "col-md-3 control-label" } do %>Pie de página para tickets
            <span class="required">*</span>
          <% end %>
          <div class="col-md-7">
            <%= f.text_area :ticket_footer, { class: "form-control", rows: 5 } %>
          </div>
        </div>
        <div class="form-group">
          <%= f.label :ticket_img, "Imagen para el ticket", { class: "col-md-3 control-label"} %>
          <div class="col-md-9">
            <div class="fileinput fileinput-new" data-provides="fileinput">
              <div class="fileinput-new thumbnail" style="width: 200px; height: 150px;">
                <% if @pos_config.ticket_img? %>
                <%= image_tag @pos_config.ticket_img %>
                <% else %>
                <%= image_tag "no-image.png" %>
                <% end %>
              </div>
              <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px;"> </div>
              <div>
                <span class="btn default btn-file">
                  <span class="fileinput-new"> Seleccione imagen </span>
                  <span class="fileinput-exists"> Cambiar </span>
                  <%= f.file_field :ticket_img, { class: "default"} %>
                  <%= f.hidden_field :ticket_img_cache %>
                </span>
                <a href="javascript:;" class="btn red fileinput-exists" data-dismiss="fileinput"> Borrar </a>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <div class="form-actions">
    <div class="row">
      <div class="col-md-offset-1 col-md-9">
        <%= f.submit 'Guardar', { class: "btn green" } %>
        <%= link_to 'Cancelar', root_path, { class: "btn default" } %>
      </div>
    </div>
  </div>
</div>
<% end %>
<script type="text/javascript">
  $(document).on("page:change", function() {
    App.init();
  });

  $('input[name="pos_config[enable_haggle]"]').on('switchChange.bootstrapSwitch', function(event, state) {
    if (state) {
      $("#haggle_div").removeClass("hidden");
    } else {
      $("#haggle_div").addClass("hidden");
    }
    $('input[name="pos_config[enable_haggle]"]').val(state);
  });
</script>
