<!-- 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>Promociones</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 promociones</span>
                  </div>
                  <div class="actions">
                    <% if can? :create, Promotion %>
                      <%= link_to new_promotion_path, { class: "btn bold green pull-right" } do %>
                        Nueva promoción <i class="fa fa-plus"></i>
                      <% end %>
                    <% end %>
                  </div>
                </div>
                <div class="portlet-body">
                  <table class="table table-striped table-bordered table-hover tableadvanced">
                    <thead>
                      <tr>
                        <th>#</th>
                        <th>Periodo</th>
                        <th>Descuento</th>
                        <th>Línea / Sublínea</th>
                        <th>Producto</th>
                        <th>Status</th>
                        <th>Acciones</th>
                      </tr>
                    </thead>
                    <tbody>
                      <% @promotions.each_with_index do |promotion, key| %>
                        <tr>
                          <td><%= key + 1 %></td>
                          <td>
                            Del <strong><%= l(promotion.start_date, format: '%d/%B/%Y') %></strong> al <strong><%= l(promotion.end_date, format: '%d/%B/%Y') %></strong>
                          </td>
                          <td> <%= promotion.percent %>%</td>
                          <td>
                            <%=
                              if promotion.subcategory_id.present?
                                Category.find(promotion.subcategory_id).category
                              elsif promotion.category_id.present?
                                promotion.category.category
                              else
                                ""
                              end %>
                          </td>
                          <td> <%= promotion.product.present? ? promotion.product.full_display : '' %> </td>
                          <td class="text-center">
                            <% if promotion.active? %>
                              <span class="label label-success">Vigente</span>
                            <% else %>
                              <span class="label label-danger">NO vigente</span>
                            <% end %>
                          </td>
                          <td>
                            <% if can? :destroy, Promotion %>
                              <%= link_to promotion, method: :delete, class: "btn btn-icon-only btn-danger", title: "Eliminar promoción", data: { confirm: '¿Está seguro de eliminar la promoción?' } do %>
                                <i class="fa fa-trash-o"></i>
                              <% end %>
                            <% 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>
