{% 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, TODO: appears just once for now -->
    <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_DATE_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 style="margin-bottom: 15pt; text-align: justify;">
                    {{ template.generic_remarks|linebreaks }}
                </p>
            </div>
        </div>
        <div class="row">
            <div class="span4">
                {% if signature %}
                    <img src="{{ signature }}"/>
                {% endif %}
            </div>
        </div>


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

    <table class="report_table"
            {% if samples_second_page %}
           style="page-break-before: always;"
            {% endif %}
            >
        <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 'name'|capfirst %}</th>
            <th>{% trans 'reference'|capfirst %}</th>
            <th>{% trans 'bag'|capfirst %}</th>
            <th>{% trans 'sampling date'|capfirst %}</th>
            <th>{% trans 'analysis date'|capfirst %}</th>
            <th>{% trans 'dilution'|capfirst %}</th>
            <th>{% trans 'analysis result'|capfirst %}</th>
            <th>OU<sub>E</sub>/m<sup>3</sup></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.finished_at|date:'d/m/y H:i' }}
                </td>

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

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

                <!-- result -->
                <td>
                    {% if mes.result %}
                        {% if not mes.compliant_result %}({% endif %}
                        {{ mes.result|floatformat:2 }}
                        {% 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 }}
                    </td>
                {% endif %}
                {% if remarksColumn %}
                    <!-- automated remark column -->
                    <td width="15%">
                        {{ mes.remark|value_or_nothing }}
                    </td>
                {% endif %}
            </tr>
        {% endfor %}
        </tbody>
    </table>

    <div class="footerdiv grid">

        <div class="row">
            <div class="span4">
                {% for line in footer_text %}
                    {{ line }}<br/>
                {% endfor %}
            </div>
            <div class="offset8" style="text-align: right; float:right; vertical-align: text-bottom;">
                {% if footer_logo %}
                    <img src="{{ footer_logo }}" width="100"/>
                {% endif %}
            </div>
        </div>

    </div>

    </body>
{% endblock content %}