{% extends "base.html" %}
{% load static %}

{% block title %}Inicio{% endblock %}

{% block page-title %}
<a href="{% url 'home' %}"><strong>GEA</strong></a> | Panel principal
{% endblock %}

{% block content %}
<!-- Status -->
<div class="row">
  <div class="col-md-4">
    <div class="card shadow-lg mb-4 border-primary">
      <div class="card-header bg-primary text-white">
        <span class="float-right"><a href="/admin/gea/expediente/?inscripto=si" class="btn btn-primary"
            title="Ver todos"><i class="fas fa-fw fa-plus"></i></a></span>
        <h4 class="card-title"><i class="fas fa-fw fa-map"></i> <strong>Planos inscriptos</strong></h4>
        <small>Últimos {{ insc_list.count }} expedientes inscriptos.</small>
      </div>
      <div class="card-body">
        <ul class="list-group list-group-flush">
          {% for e in insc_list %}
          <li class="list-group-item">
            <span class="badge badge-primary float-right">{{ e.inscripcion_fecha }}</span>
            <a href="/admin/gea/expediente/{{ e.id }}/">{{ e.id }}</a> - Plano Nº <a
              href="ftp://zentyal.estudio.lan/planos/1/{{ e.inscripcion_numero }}.pdf/">{{ e.inscripcion_numero }}</a>
          </li>
          {% empty %}
          <li class="list-group-item active">
            No hay Expedientes en este Estado.
          </li>
          {% endfor %}
        </ul>
      </div>
    </div>
  </div>
  <div class="col-md-4">
    <div class="card shadow-lg mb-4 border-warning">
      <div class="card-header bg-warning text-white">
        <span class="float-right">
          <a href="/admin/gea/expediente/?cancelado__exact=0&orden_pendiente=si&sin_inscripcion__exact=0"
            class="btn btn-warning" title="Ver todos"><i class="fas fa-fw fa-plus"></i></a>
        </span>
        <h4 class="card-title"><i class="fas fa-fw fa-file-signature"></i> <strong>Órdenes de trabajo</strong></h4>
        <small>Últimas {{ insc_list.count }} órdenes de trabajo.</small>
      </div>
      <div class="card-body">
        <ul class="list-group list-group-flush">
          {% for e in ord_list %}
          <li class="list-group-item">
            <span class="badge badge-primary float-right">{{ e.orden_fecha }}</span>
            <a href="/admin/gea/expediente/{{ e.id }}/">{{ e.id }}</a> - CoPA Nº <strong>{{ e.orden_numero }}</strong>
          </li>
          {% empty %}
          <li class="list-group-item active">
            No hay Expedientes en este Estado.
          </li>
          {% endfor %}
        </ul>
      </div>
    </div>
  </div>
  <div class="col-md-4">
    <div class="card shadow-lg mb-4 border-success">
      <div class="card-header bg-success text-white">
        <h4 class="card-title"><i class="fas fa-fw fa-compass"></i> <strong>Relevamientos</strong></h4>
        <small>Últimos {{ relev_list.count }} relevamientos.</small>
      </div>
      <div class="card-body">
        <ul class="list-group list-group-flush">
          {% for e in relev_list %}
          <li class="list-group-item">
            <span class="badge badge-primary float-right">{{ e.fecha_medicion }}</span>
            <a href="/admin/gea/expediente/{{ e.id }}/">{{ e.id }}</a> -
            {{ e.expedientepersona_set.first.persona.apellidos }}
          </li>
          {% empty %}
          <li class="list-group-item active">
            No hay Expedientes en este Estado.
          </li>
          {% endfor %}
        </ul>
      </div>
    </div>
  </div>
</div>
<div class="row">
  <div class="col-md-8">
    <div class="card shadow-lg mb-4 border-info">
      <div class="card-header bg-info text-white">
        <h4 class="card-title"><i class="fas fa-fw fa-folder-open"></i> <strong>Alta de Expedientes</strong></h4>
        <small>Últimas {{ open_list.count }} altas.</small>
      </div>
      <div class="card-body">
        <ul class="list-group list-group-flush">
          {% for e in open_list %}
          <li class="list-group-item">
            <span class="badge badge-primary float-right">{{ e.created }}</span>
            <a href="/admin/gea/expediente/{{ e.id }}/">{{ e.id }}</a> -
            <strong>{{ e.expedientepersona_set.first.persona.apellidos }}</strong> -
            <em>{{ e.expedientelugar_set.first.lugar.nombre }}</em>
          </li>
          {% empty %}
          <li class="list-group-item active">
            No hay Expedientes en este Estado.
          </li>
          {% endfor %}
        </ul>
      </div>
    </div>
  </div>
</div>
<div class="row">
  <div class="col-md-12">
    <div class="card shadow-lg mb-4 border-primary">
      <div class="card-header bg-primary text-white">
        <!-- <form class="navbar-form navbar-right" action="." method="get">
          <div class="form-group">
            <div class="input-group input-group-sm">
              <span class="input-group-addon"><i class="fas fa-fw fa-folder"></i> <i class="fas fa-fw fa-user"></i> <i
                  class="fas fa-fw fa-thumb-tack"></i></span>
              <input type="text" id="search" name="search" placeholder="Expediente/Persona/Lugar/PII" class="form-control"
                value="{{ request.GET.search }}" size="30">
              <span class="input-group-btn"><button type="submit" class="btn btn-sm btn-success"><i
                    class="fas fa-fw fa-search"></i></button></span>
            </div>
          </div>
        </form> -->
        <span class="float-right">
          <a href="{% url 'expedientes' %}" class="btn btn-primary"><i class="fas fa-fw fa-plus fa-lg"></i></a>
        </span>
        <h4 class="card-title"><i class="fas fa-fw fa-folder-open"></i> <strong>Expedientes abiertos</strong></h4>
        <small><strong>{{ count }}</strong> expediente{% if count > 1 %}s{% endif %} filtrado{% if count > 1 %}s{% endif %}</small>
      </div>
      <div class="card-body">
        <table class="table table-sm table-hover table-striped">
          <thead>
            <tr>
              <th>Expediente</th>
              <th>Persona(s)</th>
              <th>Lugar(es)</th>
              <th>Partida(s)</th>
            </tr>
          </thead>
          <tbody>
            {% for e in object_list %}
            <tr>
              <td>
                <!-- EXPEDIENTE -->
                <a href="/admin/gea/expediente/{{ e.id }}/">{{ e.id }}</a>
                <!--<a href="{% url 'expediente' e.id %}">{{ e.id }}</a>-->
              </td>
              <td>
                <!-- PERSONAS -->
                {% if e.orden_numero and not e.inscripcion_numero %}<span class="badge badge-warning">ORDEN
                  PENDIENTE</span> N&ordm; {{ e.orden_numero }} - {{ e.orden_fecha }}<br>{% endif %}
                {% if e.cancelado %}<span class="badge badge-danger">CANCELADO</span> {{ e.cancelado_por }}<br>{% endif %}
                {% if e.expedientepersona_set %}
                {% for ep in e.expedientepersona_set.all %}
                <a href="/admin/gea/persona/{{ ep.persona.id }}/">{{ ep.persona.nombre_completo }}</a>
                {% if ep.comitente %}<span class="badge badge-primary">COMITENTE</span>{% endif %}
                {% if ep.persona.telefono %}({{ ep.persona.telefono }}){% endif %}
                {% if not forloop.last %}<br>{% endif %}
                {% endfor %}
                {% endif %}
              </td>
              <td>
                <!-- LUGARES -->
                {% if e.expedientelugar_set %}
                {% for el in e.expedientelugar_set.all %}
                <a href="/admin/gea/lugar/{{ el.lugar.id }}/">{{ el.lugar.nombre }}</a>
                {% for cl in el.catastrolocal_set.all %}<br>{{ cl }}{% endfor %}{% if not forloop.last %}<br>{% endif %}
                {% endfor %}
                {% endif %}
              </td>
              <td>
                <!-- PARTIDAS -->
                {% if e.expedientepartida_set %}
                {% for ep in e.expedientepartida_set.all %}
                {% if ep.set_ruta %}<a href="{{ ep.set_ruta }}">{% endif %}{{ ep.partida.sd }}-{{ ep.partida }}{% if ep.set_ruta %}</a>{% endif %}
                <a href='http://scit.santa-fe.gov.ar/tramites/consultapartida.php?parti={{ ep.partida.sd }}{{ ep.partida.pii|stringformat:"06d" }}{{ ep.partida.subpii|stringformat:"04d" }}&origen=1'
                  target="_blank"><i class="fas fa-fw fa-file"></i></a>{% if not forloop.last %}<br>{% endif %}
                {% endfor %}
                {% endif %}
              </td>
            </tr>
            {% empty %}
            <div class="alert alert-info" role="alert">
              <i class="fas fa-fw fa-info-circle" aria-hidden="true"></i>
              <span class="sr-only">Información:</span>
              No se encontraron Expedientes.
            </div>
            {% endfor %}
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
{% endblock %}