{% extends 'print_base.html' %}
{% load i18n %}
{% load wnsq_tags %}
{% block header %}
    <title>{% trans 'project report'|capfirst %} {{ project.name }}</title>
{% endblock header %}
{% block content %}
    <body class="metro">

    <button class="noprint" onclick="window.print();"><span class="icon-printer on-left"></span>Print</button>

    <!-- header logo and text -->
    <div class="grid">

        <div class="row">
            <div class="span4" style="text-align: left;">
                {% if header_logo %}
                    <img src="{{ header_logo }}"/>
                {% endif %}
            </div>
            <div class="span6" style="text-align: right; font-size: 140%; float:right;">
                {% for header_text_line in header_text %}
                    {% if forloop.first %}
                        <span style="font-size: 180%;">{{ header_text_line }}<br/></span>
                    {% else %}
                        <span>{{ header_text_line }}<br/></span>
                    {% endif %}
                {% endfor %}
            </div>
        </div>
        <!-- header logo and text -->

        <div class="row">
            <div class="span12">
                <h4>{% trans 'project report'|capfirst %} &mdash; {{ project.name }} &mdash; {% now "SHORT_DATETIME_FORMAT" %}</h4>
            </div>
        </div>

        <!-- display the base information for this project in two header tables, one
             holds the information regarding the client, while the other holds all the information
             which comes from lab side, like who is responsible for this project and so on -->

        <div class="row">

            <!-- client information table -->
            <div class="span4">
                <table class="header_table">
                    <thead>
                    <tr>
                        <th colspan="2">{% trans 'client'|capfirst %}</th>
                    </tr>
                    </thead>

                    <tbody>

                    <tr>
                        <td>{% trans 'name'|capfirst %}</td>
                        <td><strong>{{ project.client__client__name }}</strong></td>
                    </tr>

                    <tr>
                        <td>{% trans 'address'|capfirst %}</td>
                        <td>
                            {{ project.client__address }}<br/>
                            {{ project.client__zip }} {{ project.client__city }}<br/>
                            {{ project.client__country }}
                        </td>
                    </tr>

                    <tr>
                        <td>{% trans 'phone'|capfirst %}</td>
                        <td>{{ project.client__phone }}</td>
                    </tr>

                    <tr>
                        <td>{% trans 'contact'|capfirst %}</td>
                        <td>{{ contact_person_client|value_or_nothing }}</td>
                    </tr>

                    </tbody>

                    <tfoot>

                    </tfoot>

                </table>
            </div>

            <div class="span4">
                <table class="header_table">
                    <thead>
                    <tr>
                        <th colspan="2">{% trans 'laboratory'|capfirst %}</th>
                    </tr>
                    </thead>

                    <tbody>
                    <tr>
                        <td>{% trans 'order date'|capfirst %}/{% trans 'project issued'|capfirst %}</td>
                        <td>{{ created_at }}</td>
                    </tr>

                    <tr>
                        <td>{% trans 'reference'|capfirst %}</td>
                        <td>{{ project.reference }}</td>
                    </tr>

                    <tr>
                        <td>{% trans 'project manager'|capfirst %}</td>
                        <td>{{ project_manager|value_or_nothing }}</td>
                    </tr>

                    <tr>
                        <td>{% trans 'lab team'|capfirst %}</td>
                        <td>
                        <span>
                            {% for op in lab_tech_list %}
                                {{ op }}&NonBreakingSpace;
                            {% endfor %}
                        </span>
                        </td>
                    </tr>

                    <tr>
                        <td>{% trans 'report generated by'|capfirst %}</td>
                        <td>{{ created_by }}</td>
                    </tr>

                    </tbody>
                </table>
            </div>

        </div>
        <!-- row client/lab table -->
        <div class="row">
            <div class="span18">
                <p class="generic_remarks">
                    {{ template.generic_remarks|safe|linebreaksbr }}
                </p>
            </div>
        </div>
        <div class="row">
            <div class="span4" style="text-align: center;">
                {% if signature %}
                    <img src="{{ signature }}"/>
                {% endif %}
                {{ created_by }} ({{ created_by_title }})
            </div>
        </div>


    </div>
    <!-- grid -->

    <!-- always page break this onto page two -->
    <table class="report_table" style="page-break-before: always;">
        <thead>
        <tr>
            <th
                    {% if commentsColumn and remarksColumn %}
                        colspan="11"
                    {% elif commentsColumn or remarksColumn %}
                        colspan="10"
                    {% else %}
                        colspan="9"
                    {% endif %}
                    >
                <span style="padding-left: 80px; font-size: 120%;">{% trans 'sample results'|capfirst %}</span>
            </th>
        </tr>
        <tr>
            <th>{% trans 'sample ID'|capfirst %}</th>
            <th>{% trans 'reference'|capfirst %}</th>
            <th>{% trans 'bag'|capfirst %}</th>
            <th>{% trans 'sampling date'|capfirst %}</th>
            <th>{% trans 'analysis date'|capfirst %}<br>
                <span>{% trans 'started' %}/{% trans 'finished' %}</span>
            </th>
            <th>{% trans 'analysis result'|capfirst %}<br>
                <span>(OU<sub>E</sub>/m<sup>3</sup>)</span></th>
            <th>{% trans 'dilution'|capfirst %}</th>
            <th>{% trans 'odour concentration'|capfirst %}<br>
                <span>(OU<sub>E</sub>/m<sup>3</sup>)</span></th>
            <th>{% trans 'panel size'|capfirst %}/ITEs</th>
            {% if commentsColumn %}
                <th>{% trans 'comments'|capfirst %}</th>
            {% endif %}
            {% if remarksColumn %}
                <th>{% trans 'remarks'|capfirst %}</th>
            {% endif %}
        </tr>
        </thead>
        <tbody>
        {% for mes in measurements %}
            <tr>
                <!-- sample name -->
                <td>
                    {{ mes.sample__name }}
                </td>

                <!-- sample reference -->
                <td>
                    {{ mes.sample__reference|value_or_nothing }}
                </td>

                <!-- bag -->
                <td>
                    {{ mes.sample__contained_in__name }}
                </td>

                <!-- sample date/time -->
                <td>
                    {{ mes.sample__sampled_at|date:'d/m/y H:i' }}
                </td>

                <!-- measurement finished at -->
                <td>
                    {{ mes.started_at|date:'d/m/y H:i' }}<br>
                    {{ mes.finished_at|date:'d/m/y H:i' }}<br>
                </td>

                <!-- analysis result -->
                <td>
                    {% if mes.analysis_result %}
                        {{ mes.analysis_result }}
                    {% else %}
                        {% nothing %}
                    {% endif %}
                </td>

                <!-- total predilution -->
                <td>
                    {% if mes.predilution > 1 %}
                        {{ mes.predilution|floatformat:2 }}
                    {% else %}
                        {% nothing %}
                    {% endif %}
                </td>

                <!-- result -->
                <td>
                    {% if mes.result %}
                        {% if not mes.compliant_result %}({% endif %}
                        {{ mes.result }}
                        {% if not mes.compliant_result %}){% endif %}
                    {% else %}
                        {% nothing %}
                    {% endif %}
                </td>

                <td>
                    {{ mes.panelist_count }} / {{ mes.ite_count }}
                </td>

                {% if commentsColumn %}
                    <!-- per sample custom comments -->
                    <td width="15%">
                        {{ mes.comments|safe|linebreaksbr }}
                    </td>
                {% endif %}
                {% if remarksColumn %}
                    <!-- automated remark column -->
                    <td width="15%">
                        {% if mes.remark %}
                            {{ mes.remark|safe|linebreaksbr }}
                        {% else %}
                            {% nothing %}
                        {% endif %}
                    </td>
                {% endif %}
            </tr>
        {% endfor %}
        </tbody>
    </table>

    </body>
{% endblock content %}