{% extends "base.html" %}
{% load i18n range units %}
{% block extra_head %}
{{form.media}}
{% endblock %}
{% block content %}
<div class='dashboard'>

  <h2>{% trans "Operations" %}</h2>

  <h3>{% trans "Global informations" %}</h3>
  <div>
    <div class='table'>
    <table>
      <caption>{% trans "Total" %}</caption>
      <tr>
        <th>{% trans "Status" %}</th><th>{% trans "Number" %}</th>
      </tr>
      {% for lbl, nb in dashboard.total %}
      <tr>
        <th class='sub'>{{lbl}}</th><td>{{nb}}</td>
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "Area by type of operation" %}</caption>
      <tr>
        <th>{% trans "Status" %}</th><th>{% trans "Area (ha)" %}</th>
      </tr>
      {% for surface in dashboard.surface_by_type %}
      <tr>
        <th class='sub'>{{surface.operation_type__label}}</th><td>{{surface.number|m2_to_ha}}</td>
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "By types" %}</caption>
      <tr>
        <th>{% trans "State" %}</th>{%for typ in dashboard.types %}<th>{{typ.label}}</th>{% endfor %}
      </tr>
      {% for lbl, types in dashboard.by_type %}
      <tr>
        <th class='sub'>{{lbl}}</th>{%for nb in types %}<td>{{nb}}</td>{% endfor %}
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "By year" %}</caption>
      <tr>
        <th>{% trans "State" %}</th>{%for yr in dashboard.years %}<th>{{yr}}</th>{% endfor %}
      </tr>
      {% for lbl, years in dashboard.by_year %}
      <tr>
        <th class='sub'>{{lbl}}</th>{%for nb in years %}<td>{{nb}}</td>{% endfor %}
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "By realisation year" %}</caption>
      <tr>
        <th>{% trans "State" %}</th>{%for yr in dashboard.realisation_years %}<th>{{yr.year}}</th>{% endfor %}
      </tr>
      {% for lbl, years in dashboard.by_realisation_year %}
      <tr>
        <th class='sub'>{{lbl}}</th>{%for nb in years %}<td>{{nb}}</td>{% endfor %}
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "Effective operation by type and year" %}</caption>
      <tr>
        <th>{% trans "Type" %}</th>{%for yr in dashboard.years %}<th>{{yr}}</th>{% endfor %}
      </tr>
      {% for lbl, years in dashboard.effective %}
      <tr>
        <th class='sub'>{{lbl}}</th>{%for nb in years %}<td>{{nb}}</td>{% endfor %}
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "By realisation month" %}</caption>
      <tr>
        <th>{% trans "State" %}</th>{%for mt in dashboard.last_months %}<th>{{mt.date|date:"F Y"|capfirst}}</th>{% endfor %}
      </tr>
      {% for lbl, months in dashboard.by_realisation_month %}
      <tr>
        <th class='sub'>{{lbl}}</th>{%for nb in months %}<td>{{nb}}</td>{% endfor %}
      </tr>
      {% endfor %}
    </table></div>

  </div>

  <h3>{% trans "Survey informations" %}</h3>
  <div>

    <div class='table'>
    <table>
      <caption>{% trans "Total" %}</caption>
      <tr>
        <th>{% trans "Status" %}</th><th>{% trans "Number" %}</th>
      </tr>
      {% for lbl, nb in dashboard.survey.total %}
      <tr>
        <th class='sub'>{{lbl}}</th><td>{{nb}}</td>
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "By year" %}</caption>
      <tr>
        <th>{% trans "State" %}</th>{%for yr in dashboard.years %}<th>{{yr}}</th>{% endfor %}
      </tr>
      {% for lbl, years in dashboard.survey.by_year %}
      <tr>
        <th class='sub'>{{lbl}}</th>{%for nb in years %}<td>{{nb}}</td>{% endfor %}
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "By realisation year" %}</caption>
      <tr>
        <th>{% trans "State" %}</th>{%for yr in dashboard.realisation_years %}<th>{{yr.year}}</th>{% endfor %}
      </tr>
      {% for lbl, years in dashboard.survey.by_realisation_year %}
      <tr>
        <th class='sub'>{{lbl}}</th>{%for nb in years %}<td>{{nb}}</td>{% endfor %}
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "Current year" %}</caption>
      <tr>
        <th>{% trans "Status" %}</th>{% for lbl in dashboard.filters_label %}<th>{{lbl}}</th>{%endfor%}
      </tr>
      <tr>
        <th class='sub'>{% trans "Area"%}</th>{% for nb in dashboard.survey.area %}<td>{{nb}}</td>{%endfor%}
      </tr>
      <tr>
        <th class='sub'>{% trans "Man-day"%}</th>{% for nb in dashboard.survey.manday %}<td>{{nb}}</td>{%endfor%}
      </tr>
      <tr>
        <th class='sub'>{% trans "Man-day/hectare"%}</th>{% for nb in dashboard.survey.mandayhect %}<td>{{nb}}</td>{%endfor%}
      </tr>
    </table></div>

    <p><strong>{% trans "Man-day/hectare for effective operations (current year):" %}</strong> {{dashboard.survey.mandayhect_effective}}</p>

    <div class='table'>
    <table>
      <caption>{% trans "Organizations (current year)" %}</caption>
      <tr>
        <th>&nbsp;</th><th>{% trans "Area" %}</th><th>{% trans "Man-day" %}</th><th>{% trans "Man-day/hectare" %}</th>
      </tr>
      {% for org in dashboard.survey.org %}
      <tr>
        <th class='sub'>{{org.scientist__attached_to__name}}</th><td>{{org.area}}</td><td>{{org.manday}}</td><td>{{org.mandayhect}}</td>
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "Current realisation year" %}</caption>
      <tr>
        <th>{% trans "Status" %}</th>{% for lbl in dashboard.filters_label %}<th>{{lbl}}</th>{%endfor%}
      </tr>
      <tr>
        <th class='sub'>{% trans "Area"%}</th>{% for nb in dashboard.survey.area_realised %}<td>{{nb}}</td>{%endfor%}
      </tr>
      <tr>
        <th class='sub'>{% trans "Man-day"%}</th>{% for nb in dashboard.survey.manday_realised %}<td>{{nb}}</td>{%endfor%}
      </tr>
      <tr>
        <th class='sub'>{% trans "Man-day/hectare"%}</th>{% for nb in dashboard.survey.mandayhect_realised %}<td>{{nb}}</td>{%endfor%}
      </tr>
    </table></div>

    <p><strong>{% trans "Man-day/hectare for effective operations (current realisation year):" %}</strong> {{dashboard.survey.mandayhect_real_effective}}</p>

    <div class='table'>
    <table>
      <caption>{% trans "Organizations (current realisation year)" %}</caption>
      <tr>
        <th>&nbsp;</th><th>{% trans "Area" %}</th><th>{% trans "Man-day" %}</th><th>{% trans "Man-day/hectare" %}</th>
      </tr>
      {% for org in dashboard.survey.org_realised %}
      <tr>
        <th class='sub'>{{org.in_charge__attached_to__name}}</th><td>{{org.area}}</td><td>{{org.manday}}</td><td>{{org.mandayhect}}</td>
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "Area by organization by year" %}</caption>
      <tr>
        <th>{% trans "Organization" %}</th>{% for yr in dashboard.years%}<th>{{yr}}</th>{% endfor %}
      </tr>
      {% for org, vals in dashboard.survey.org_by_year %}
      <tr>
        <th class='sub'>{{org}}</th>{% for area, cost in vals %}<td>{{area}}</td>{% endfor %}
      </tr>
      {% endfor %}
      <tr>
        <th>{% trans "Mean" %}</th>{% for area in dashboard.survey.org_by_year_area_mean %}<td>{{area}}</td>{% endfor %}
      </tr>
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "Effective operations areas (ha)" %}</caption>
      <tr>
        <th>&nbsp;</th>{% for yr in dashboard.years%}<th>{{yr}}</th>{% endfor %}
      </tr>
      <tr>
        <th>{% trans "Sum" %}</th>{% for nb, mean in dashboard.survey.effective %}<td>{{nb|m2_to_ha}}</td>{% endfor %}
      </tr>
      <tr>
        <th>{% trans "Average" %}</th>{% for nb, avg in dashboard.survey.effective %}<td>{{avg|m2_to_ha}}</td>{% endfor %}
      </tr>
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "Man-Days/hectare by Year" %}</caption>
      <tr>
        <th>&nbsp;</th>{% for yr in dashboard.years%}<th>{{yr}}</th>{% endfor %}
      </tr>
      <tr>
        <th>{% trans "Man-Days/hectare" %}</th>{% for nb, mean in dashboard.survey.mandayshect %}<td>{{nb}}</td>{% endfor %}
      </tr>
      <tr>
        <th>{% trans "Average" %}</th>{% for nb, avg in dashboard.survey.mandayshect %}<td>{{avg}}</td>{% endfor %}
      </tr>
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "By month" %}</caption>
      <tr>
        <th>{% trans "State" %}</th>{%for mt in dashboard.last_months %}<th>{{mt.date|date:"F Y"|capfirst}}</th>{% endfor %}
      </tr>
      {% for lbl, months in dashboard.survey.by_month %}
      <tr>
        <th class='sub'>{{lbl}}</th>{%for nb in months %}<td>{{nb}}</td>{% endfor %}
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "By department" %}</caption>
      <tr>
        <th>{% trans "Department" %}</th>{%for yr in dashboard.years %}<th>{{yr}}</th>{% endfor %}<th>{% trans "Sum" %}</th>
      </tr>
      {% for lbl, years in dashboard.survey.by_dpt %}
      <tr>
        <th class='sub'>{{lbl}}</th>{%for nb in years %}<td{%if forloop.last%} class='sub'{%endif%}>{{nb}}</td>{% endfor %}
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "Effective operation by department" %}</caption>
      <tr>
        <th rowspan='2'>{% trans "Department" %}</th>{%for yr in dashboard.years %}<th colspan='2'>{{yr}}</th>{% endfor %}<th colspan='2'>{% trans "Sum" %}</th>
      </tr>
      <tr>
        {%for yr in dashboard.years %}<th>{%trans "Nb."%}</th><th>{%trans "Area"%}</th>{% endfor %}<th>{%trans "Nb."%}</th><th>{%trans "Area"%}</th>
      </tr>
      {% for lbl, years in dashboard.survey.effective_by_dpt %}
      <tr>
        <th class='sub'>{{lbl}}</th>{%for nb, area, cost, fnap in years %}<td{%if forloop.last%} class='sub'{%endif%}>{{nb}}</td><td{%if forloop.last%} class='sub'{%endif%}>{{area}}</td>{% endfor %}
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "Main towns by number" %}</caption>
      <tr>
        <th>{% trans "Town" %}</th><th>{% trans "Number" %}</th>
      </tr>
      {% for lbl, nb in dashboard.survey.towns %}
      <tr>
        <th class='sub'>{{lbl}}</th><td>{{nb}}</td>
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "Main towns by surface" %}</caption>
      <tr>
        <th>{% trans "Town" %}</th><th>{% trans "Total surface (ha)" %}</th>
      </tr>
      {% for lbl, nb in dashboard.survey.towns_surface %}
      <tr>
        <th class='sub'>{{lbl}}</th><td>{{nb|m2_to_ha}}</td>
      </tr>
      {% endfor %}
    </table></div>
  </div>

  <h3>{% trans "Excavation informations" %}</h3>
  <div>
    <div class='table'>
    <table>
      <caption>{% trans "Total" %}</caption>
      <tr>
        <th>{% trans "Status" %}</th><th>{% trans "Number" %}</th>
      </tr>
      {% for lbl, nb in dashboard.excavation.total %}
      <tr>
        <th class='sub'>{{lbl}}</th><td>{{nb}}</td>
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "By year" %}</caption>
      <tr>
        <th>{% trans "State" %}</th>{%for yr in dashboard.years %}<th>{{yr}}</th>{% endfor %}
      </tr>
      {% for lbl, years in dashboard.excavation.by_year %}
      <tr>
        <th class='sub'>{{lbl}}</th>{%for nb in years %}<td>{{nb}}</td>{% endfor %}
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "By realisation year" %}</caption>
      <tr>
        <th>{% trans "State" %}</th>{%for yr in dashboard.realisation_years %}<th>{{yr.year}}</th>{% endfor %}
      </tr>
      {% for lbl, years in dashboard.excavation.by_realisation_year %}
      <tr>
        <th class='sub'>{{lbl}}</th>{%for nb in years %}<td>{{nb}}</td>{% endfor %}
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "Current realisation year" %}</caption>
      <tr>
        <th>{% trans "Status" %}</th>{% for lbl in dashboard.filters_label %}<th>{{lbl}}</th>{%endfor%}
      </tr>
      <tr>
        <th class='sub'>{% trans "Area"%}</th>{% for nb in dashboard.excavation.area_realised %}<td>{{nb}}</td>{%endfor%}
      </tr>
      <tr>
        <th class='sub'>{% trans "Man-day"%}</th>{% for nb in dashboard.excavation.manday_realised %}<td>{{nb}}</td>{%endfor%}
      </tr>
      <tr>
        <th class='sub'>{% trans "Man-day/hectare"%}</th>{% for nb in dashboard.excavation.mandayhect_realised %}<td>{{nb}}</td>{%endfor%}
      </tr>
    </table></div>

    <p><strong>{% trans "Man-day/hectare for effective operations (current realisation year):" %}</strong> {{dashboard.excavation.mandayhect_real_effective}}</p>

    <div class='table'>
    <table>
      <caption>{% trans "Organizations (current realisation year)" %}</caption>
      <tr>
        <th>&nbsp;</th><th>{% trans "Area" %}</th><th>{% trans "Man-day" %}</th><th>{% trans "Man-day/hectare" %}</th>
      </tr>
      {% for org in dashboard.excavation.org_realised %}
      <tr>
        <th class='sub'>{{org.in_charge__attached_to__name}}</th><td>{{org.area}}</td><td>{{org.manday}}</td><td>{{org.mandayhect}}</td>
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "Area by organization by year" %}</caption>
      <tr>
        <th>{% trans "Organization" %}</th>{% for yr in dashboard.years%}<th>{{yr}}</th>{% endfor %}
      </tr>
      {% for org, vals in dashboard.excavation.org_by_year %}
      <tr>
        <th class='sub'>{{org}}</th>{% for area, cost in vals %}<td>{{area}}</td>{% endfor %}
      </tr>
      {% endfor %}
      <tr>
        <th>{% trans "Sum" %}</th>{% for area in dashboard.excavation.org_by_year_area_sum %}<td>{{area}}</td>{% endfor %}
      </tr>
      <tr>
        <th>{% trans "Mean" %}</th>{% for area in dashboard.excavation.org_by_year_area_mean %}<td>{{area}}</td>{% endfor %}
      </tr>
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "Area by organization by realisation year" %}</caption>
      <tr>
        <th>{% trans "Organization" %}</th>{% for yr in dashboard.years%}<th>{{yr}}</th>{% endfor %}
      </tr>
      {% for org, vals in dashboard.excavation.org_by_year %}
      <tr>
        <th class='sub'>{{org}}</th>{% for area, cost in vals %}<td>{{area}}</td>{% endfor %}
      </tr>
      {% endfor %}
      <tr>
        <th>{% trans "Sum" %}</th>{% for area in dashboard.excavation.org_by_year_area_sum %}<td>{{area}}</td>{% endfor %}
      </tr>
      <tr>
        <th>{% trans "Mean" %}</th>{% for area in dashboard.excavation.org_by_year_area_mean %}<td>{{area}}</td>{% endfor %}
      </tr>
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "By month" %}</caption>
      <tr>
        <th>{% trans "State" %}</th>{%for mt in dashboard.last_months %}<th>{{mt.date|date:"F Y"|capfirst}}</th>{% endfor %}
      </tr>
      {% for lbl, months in dashboard.excavation.by_month %}
      <tr>
        <th class='sub'>{{lbl}}</th>{%for nb in months %}<td>{{nb}}</td>{% endfor %}
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "By department" %}</caption>
      <tr>
        <th>{% trans "Department" %}</th>{%for yr in dashboard.years %}<th>{{yr}}</th>{% endfor %}<th>{% trans "Sum" %}</th>
      </tr>
      {% for lbl, years in dashboard.excavation.by_dpt %}
      <tr>
        <th class='sub'>{{lbl}}</th>{%for nb in years %}<td{%if forloop.last%} class='sub'{%endif%}>{{nb}}</td>{% endfor %}
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "Effective operation by department" %}</caption>
      <tr>
        <th rowspan='2'>{% trans "Department" %}</th>{%for yr in dashboard.years %}<th colspan='3'>{{yr}}</th>{% endfor %}<th colspan='3'>{% trans "Sum" %}</th>
      </tr>
      <tr>
        {%for yr in dashboard.years %}<th>{%trans "Nb."%}</th><th>{%trans "Cost"%}</th><th>{%trans "FNAP cost"%}</th>{% endfor %}<th>{%trans "Nb."%}</th><th>{%trans "Cost"%}</th><th>{%trans "FNAP cost"%}</th>
      </tr>
      {% for lbl, years in dashboard.excavation.effective_by_dpt %}
      <tr>
        <th class='sub'>{{lbl}}</th>{%for nb, area, cost, fnap in years %}<td{%if forloop.last%} class='sub'{%endif%}>{{nb}}</td><td{%if forloop.last%} class='sub'{%endif%}>{{cost}}</td><td{%if forloop.last%} class='sub'{%endif%}>{{fnap}}</td>{% endfor %}
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "Main towns by number" %}</caption>
      <tr>
        <th>{% trans "Town" %}</th><th>{% trans "Number" %}</th>
      </tr>
      {% for lbl, nb in dashboard.excavation.towns %}
      <tr>
        <th class='sub'>{{lbl}}</th><td>{{nb}}</td>
      </tr>
      {% endfor %}
    </table></div>

    <div class='table'>
    <table>
      <caption>{% trans "Main towns by cost" %}</caption>
      <tr>
        <th>{% trans "Town" %}</th><th>{% trans "Cost (euros)" %}</th>
      </tr>
      {% for lbl, nb in dashboard.excavation.towns_cost %}
      <tr>
        <th class='sub'>{{lbl}}</th><td>{{nb}}</td>
      </tr>
      {% endfor %}
    </table></div>


  </div>
</div>
{% endblock %}
