<!-- 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>Reporte de compras y egresos por mes </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 -->
        <%= form_tag(purchases_per_month_path, method: :get, remote: true) do |f| %>
          <div class="search-page search-content-3">
            <div class="row">
              <div class="col-md-12">
                <div class="search-filter bordered">
                <!-- <h4 class=" uppercase form-section"> Búsqueda de producto </h4> <hr> -->
                  <div class="form-group">
                    <div class="row">
                      <div class="col-md-3 col-sm-4">
                        <div class="search-label uppercase">Localización</div>
                        <div class="col-md-12">
                          <%= select_tag "location", grouped_options_for_select([
                            ['Puntos de venta', Pointsale.activos.collect { |p| [ p.name, ('P-' + p.id.to_s) ] }],
                            ['Almacenes', Warehouse.activos.collect { |w| [ w.name, ('W-' + w.id.to_s)] }],
                            ["", ["Todos"]]], selected: "Todos"), class: "pointsale_id form-control select2" %>
                        </div>
                      </div>
                      <div class="col-md-3 col-sm-4">
                        <div class="search-label uppercase"> Del </div>
                        <div class="col-md-6">
                          <div class="input-group input-medium date" data-date-format="dd/mm/yyyy">
                            <!-- <input id="start" type='text' class="form-control" value="< %= l(Date.today.beginning_of_month, format: '%d/%m/%Y') %>" /> -->
                            <%= text_field_tag "start_date", l(Date.today.beginning_of_month, format: '%d/%m/%Y'), class: "form-control" %>
                            <span class="input-group-addon">
                              <span class="glyphicon glyphicon-calendar"></span>
                            </span>
                          </div>
                        </div>
                      </div>
                      <div class="col-md-3 col-sm-4">
                        <div class="search-label uppercase"> Al </div>
                        <div class="col-md-6">
                          <div class="input-group input-medium date" data-date-format="dd/mm/yyyy">
                            <!-- <input id="end" type='text' class="form-control" value="<%= l(Date.today.end_of_month, format: '%d/%m/%Y') %>" /> -->
                            <%= text_field_tag "end_date", l(Date.today.end_of_month, format: '%d/%m/%Y'), class: "form-control" %>
                            <span class="input-group-addon">
                              <span class="glyphicon glyphicon-calendar"></span>
                            </span>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                  <div class="form-group">
                    <div class="row">
                      <div class="col-md-3 col-sm-4" style="margin-top: 20px">
                        <%= submit_tag 'Filtrar', { class: "btn green bold btn-block", style: 'margin:0px' } %>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        <% end %>
        <!-- BEGIN PAGE CONTENT INNER -->
        <div class="page-content-inner">
          <div class="portlet light">
            <div class="portlet-title">
              <div class="caption">
                <span class="caption-subject font-blue-dark bold uppercase">Compras y egresos</span>
              </div>
            </div>
            <div class="portlet-body form" id="sales_content">
              <div class="product_track_search">
                <div class="row">
                  <div class="col-md-12">
                    <div class="note note-success hidden" id="note_info">
                      <h4 class="block">Detalle de compras y egresos del periodo: <strong><span id="start_date_display"></span></strong> al <strong><span id="end_date_display"></span></strong></h4>
                    </div>
                    <div class="col-xs-offset-1 col-xs-5">
                      <div class="text-center well" style="margin-bottom: 0px">
                        <div class="font-grey-mint font-sm">NÚMERO DE COMPRAS</div>
                        <div class="uppercase font-hg font-blue-sharp" id="purchases_quantity">0</div>
                      </div>
                    </div>
                    <div class="col-xs-offset-1 col-xs-5">
                      <div class="text-center well" style="margin-bottom: 0px">
                        <div class="font-grey-mint font-sm">PRODUCTOS COMPRADOS</div>
                        <div class="uppercase font-hg font-blue-sharp" id="prods_total">0</div>
                      </div>
                    </div>
                  </div>
                </div>
                <div class="" style="margin-top:20px">
                  <div class="col-md-3 col-sm-3 col-xs-6">
                    <div class="text-center well" style="margin-bottom: 0px">
                      <div class="font-grey-mint font-sm">Total comprado contado </div>
                      <div class="uppercase font-hg font-blue-sharp"><span id="cash_purchases_total"> $0.00</span> MXN</div>
                      <div class="uppercase font-hg font-blue-sharp"><span id="cash_purchases_total_dollars"> $0.00</span> USD</div>
                    </div>
                  </div>
                  <div class="col-md-3 col-sm-3 col-xs-6">
                    <div class="text-center well hidden" style="margin-bottom: 0px">
                      <div class="font-grey-mint font-sm">Total comprado crédito </div>
                      <div class="uppercase font-hg font-blue-sharp"><span id="credit_purchases_total"> $0.00</span> MXN</div>
                      <div class="uppercase font-hg font-blue-sharp"><span id="credit_purchases_total_dollars"> $0.00</span> USD</div>
                    </div>
                  </div>
                </div>
                <div class="row" style="margin-top:20px">
                  <div class="col-xs-3">
                    <div class="text-center well" style="margin-bottom: 0px">
                      <div class="font-grey-mint font-sm">TOTAL DE EGRESOS</div>
                      <div class="uppercase font-hg font-green" id="expenses_total">$0.00</div>
                    </div>
                  </div>
                  <div class="col-xs-3">
                    <div class="text-center well" style="margin-bottom: 0px">
                      <div class="font-grey-mint font-sm">TOTAL COMPRADO</div>
                      <div class="uppercase font-hg font-green"><span id="purchases_total">$0.00</span> MXN</div>
                      <div class="uppercase font-hg font-green"><span id="purchases_total_dollars">$0.00</span> USD</div>
                    </div>
                  </div>
                </div>
                <br>
                <div class="row">
                  <ul class="nav nav-tabs">
                    <li class="active">
                      <a href="#purchases" data-toggle="tab">Compras</a>
                    </li>
                    <li>
                      <a href="#expenses" data-toggle="tab">Egresos</a>
                    </li>
                  </ul>
                </div>
                <div class="tab-content">
                  <div class="tab-pane active" id="purchases">
                    <div class="row">
                      <div class="col-md-12">
                        <table class="table table-striped table-bordered table-hover tableadvanced" id="purchases_per_month_table">
                          <thead>
                            <tr>
                              <th>Fecha</th>
                              <th>Folio</th>
                              <th>Punto de venta</th>
                              <th>Almacén</th>
                              <th>Proveedor</th>
                              <th class="hidden">Tipo</th>
                              <th>Productos</th>
                              <th>Status</th>
                              <th>Subtotal</th>
                              <th>IVA</th>
                              <th>Total</th>
                            </tr>
                          </thead>
                          <tbody>
                          </tbody>
                        </table>
                      </div>
                    </div>
                  </div>
                  <div class="tab-pane" id="expenses">
                    <div class="row">
                      <div class="col-md-12">
                        <table class="table table-striped table-bordered table-hover tableadvanced" id="expenses_per_month_table">
                          <thead>
                            <tr>
                              <th>Fecha</th>
                              <th>Folio</th>
                              <th>Punto de venta</th>
                              <th>Observaciones</th>
                              <th>Status</th>
                              <th>Total</th>
                            </tr>
                          </thead>
                          <tbody>
                          </tbody>
                        </table>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- END PAGE CONTENT INNER -->
      </div>
    </div>
    <!-- END PAGE CONTENT BODY -->
    <!-- END CONTENT BODY -->
  </div>
  <!-- END CONTENT -->
</div>
<script>
  $(document).on("page:change", function() {
    App.init();
     $('#start_date').datetimepicker({
      icons: {
        date: "fa fa-calendar"
      },
      format: "DD/MM/YYYY"
    });

    $('#end_date').datetimepicker({
      icons: {
        date: "fa fa-calendar"
      },
      format: "DD/MM/YYYY"
    });
  });
</script>
