{% extends "ishtar/sheet.html" %}
{% load i18n window_ope_tables window_field window_header %}

{% block head_title %}{% trans "Archaeological file" %}{% endblock %}

{% block content %}

{% if can_add_operation %}
{% window_file_nav item window_id previous next %}
{% else %}
{% window_nav item window_id 'show-file' 'file_modify' 'show-historized-file' 'revert-file' previous next 1 %}
{% endif %}

<h3>{% trans "General"%}</h3>

<ul class='form-flex'>
{% field_li "Year" item.year "<strong>" "</strong>" %}
{% field_li "Numerical reference" item.numeric_reference "<strong>" "</strong>" %}
{% field_li "Other reference" item.internal_reference %}
{% field_li "Name" item.name %}

<li><label>{%trans "Edition date:"%}</label> <span class='value'>{% if item.history_date %}{{ item.history_date }}{% else %}{{ item.history.all.0.history_date }}{% endif %}</span></li> <!-- date = now -->

{% field_li "Reception date" item.reception_date|date:"DATE_FORMAT" %}
{% field_li "Creation date" item.creation_date|date:"DATE_FORMAT" %}
{% field_li "Created by" item.history_creator.ishtaruser.full_label %}

{% comment %}
{% if item.deadline_date and not item.acts %}
    <p><label>{%trans "Deadline:"%}</label> <span class='value'>{% item.deadline_date %}</span></p> <!-- calculated deadline for some preventive files , see saisine_type, not displayed if an act as been send -->
{% endif %}
{% endcomment %}

{% field_li_detail "In charge" item.in_charge %}

<li><label>{%trans "State:"%}</label> <span class='value'>{% if item.is_active %}{%trans "Active file"%}</span></p>
{% else %}{%trans "Closed file"%}</span></li>

{% if item.closing %}<li><label>{%trans "Closing date:"%}</label> <span class='value'>{{ item.closing.date }} <strong>{%trans "by" %}</strong> {{ item.closing.user.full_label }}</span></li>{% endif %}
{% endif %}

{% field_li "Type" item.file_type %}

{% if item.related_file %}<li><label>{%trans "Related file:"%}</label> <span class='value'><a href='#' onclick='load_window("{% url show-file item.related_file.pk ''%}")'>{{ item.related_file }}</a></span></li>{% endif %}

</ul>
{% field "Comment" item.comment "<pre>" "</pre>" %}

<h3>{% trans "Localisation"%}</h3>
{% if item.towns.count %}<p><label>{%trans "Towns:"%}</label> <span class='value'>{{ item.towns.all|join:", " }}</span></p>{% endif %}
{% if item.departments.count %}<p><label>{%trans "Departments:"%}</label> <span class='value'>{{ item.departments.all|join:", " }}</span></p>{% endif %}
{% if item.address %}
<p><label>{%trans "Main address:"%}</label> <span class='value'>{{ item.address }}</span></p>
{% if item.address_complement %}<p><label>{%trans "Complement:"%}</label> <span class='value'>{{ item.address_complement }}</span></p>{%endif%}
{% if item.postal_code %}<p><label>{%trans "Postal code:"%}</label> <span class='value'>{{ item.postal_code }}</span></p>{%endif%}
{% endif %}
{% if item.total_surface %}<p><label>{%trans "Surface:"%}</label> <span class='value'>{{ item.total_surface }} m<sup>2</sup> ({{ item.total_surface_ha }} ha)</span></p>{%endif%}


{% if item.is_preventive %}

<h3>{% trans "Preventive archaelogical file"%}</h3>
<ul class='form-flex'>
{% if item.total_developed_surface %}<li><label>{%trans "Developed surface:"%}</label> <span class='value'>{{ item.total_developed_surface }} m<sup>2</sup> ({{ item.total_developed_surface_ha }} ha)</span></li>{% endif %}

{% field_li "Saisine type" item.saisine_type %}

{% field_li_detail "Responsible for town planning service" item.responsible_town_planning_service %}
{% field_li "Responsible for town planning service address" item.responsible_town_planning_service.full_address %}
{% if item.town_planning_service %}
  {% field_li "Town planning service organization" item.town_planning_service.full_address %}
{% else %}
  {% field_li "Town planning service organization" item.responsible_town_planning_service.attached_to.full_address %}
{% endif %}

{% field_li "Permit type" item.permit_type %}
{% field_li "Permit reference" item.permit_reference %}

{% field_li "General contractor" item.general_contractor.full_address %}
{% if item.corporation_general_contractor %}
  {% field_li "General contractor organization" item.corporation_general_contractor.full_address %}
{% else%}
  {% field_li "General contractor organization" item.general_contractor.attached_to.full_address %}
{% endif %}

</ul>
{% else %}

<h3>{% trans "Research archaeology"%}</h3>
{% if item.departments.count %}<p><label>{%trans "Departments"%}{%trans ":"%}</label> <span class='value'>{% for department in item.departments.all %}{% if forloop.counter0 %}, {% endif %}{{ department }}{% endfor %}</span></p>{% endif %}
{% if item.scientist %}<p><label>{%trans "Head scientist"%}{%trans ":"%}</label> <span class='value'>{{ item.scientist }}</span></p>{% endif %}
{% if item.requested_operation_type %}<p><label>{%trans "Requested operation type"%}{%trans ":"%}</label> <span class='value'>{{ item.requested_operation_type }}</span></p>{% endif %}
{% if item.organization %}<p><label>{%trans "Organization"%}{%trans ":"%}</label> <span class='value'>{{ item.organization }}</span></p>{% endif %}
{% if item.cira_advised != None %}<p><label>Passage en CIRA</label> <span class='value'>{{ item.cira_advised|yesno }}</span></p>{% endif %}
{% if item.mh_register != None %}<p><label>Sur Monument Historique classé</label> <span class='value'>{{ item.mh_register|yesno }}</span></p>{% endif %}
{% if item.mh_listing != None %}<p><label>Sur Monument Historique inscrit</label> <span class='value'>{{ item.mh_listing|yesno }}</span></p>{% endif %}
{% if item.classified_area != None %}<p><label>{% trans "Classified area"  %}</label> <span class='value'>{{ item.classified_area|yesno }}</span></p>{% endif %}
{% if item.protected_area != None %}<p><label>{% trans "Protected area"  %}</label> <span class='value'>{{ item.protected_area|yesno }}</span></p>{% endif %}
{% if item.research_comment %}<p><label>{%trans "Comment"%}{%trans ":"%}</label> <span class='value'>{{ item.research_comment }}</span></p>{% endif %}

{% endif %}

{% if not next %}

{% trans "Associated parcels" as parcels_label %}
{% include "ishtar/blocks/window_tables/parcels.html" %}

{% trans "Administrative acts" as administrativeacts_label %}
{% table_administrativact administrativeacts_label item.administrative_act.all %}

<h4>{%trans "Associated operations"%}</h4>
<div class='clean-table'>
<div class='clean-table-wrap'>
<table>
  <tr>
    <th>{% trans "Ref." %}</th>
    <th>Code Patriarche</th>
    <th>{% trans "Type" %}</th>
    <th>{% trans "In charge" %}</th>
    <th>{% trans "Start date" %}</th>
    <th>{% trans "Excavation end date" %}</th>
    <th class='link'>&nbsp;</th>
  </tr>
  {% for operation in item.operations.all %}
  <tr>
    <td>{{operation.year_index}}</td>
    <td>{{operation.full_code_patriarche|default:""}}</td>
    <td class='string'>{{operation.operation_type}}</td>
    <td class='string'>{{operation.in_charge|default:""}}</td>
    <td>{{operation.start_date|default:""}}</td>
    <td>{{operation.excavation_end_date|default:""}}</td>
    <td class='link'><a href="#" class='display_details' onclick='load_window("{%url show-operation operation.pk ''%}")'><i class="fa fa-info-circle" aria-hidden="true"></i></a></td>
  </tr>
  {% empty %}
  <tr><td colspan="8" class='no_items'>{% trans "No operation associated to this archaelogical file" %}</td></tr>
  {% endfor %}
</table>
</div>
</div>

<h4>{%trans "Admninistrative acts linked to associated operations"%}</h4>
<div class='clean-table'>
<div class='clean-table-wrap'>
<table>
  <tr>
    <th>{% trans "Year" %}</th>
    <th>{% trans "Ref." %}</th>
    <th>{% trans "Type" %}</th>
    <th>{% trans "Date" %}</th>
  </tr>
  {% for act in item.operation_acts %}
  <tr>
    <td>{{act.signature_date.year}}</td>
    <td>{{act.ref_sra}}</td>
    <td class='string'>{{act.act_type}}</td>
    <td>{{act.signature_date}}</td>
  </tr>
  {% empty %}
  <tr><td colspan="4" class='no_items'>{% trans "No administrative act linked to operations" %}</td></tr>
  {% endfor %}
</table>
</div>
</div>

{% endif %}
{% endblock %}
