{% extends 'base_rigs.html' %}
{% load paginator from filters %}
{% load static %}

{% block title %}Events for Invoice{% endblock %}

{% block js %}
<script src="{% static "js/tooltip.js" %}"></script>
<script>
    $(function () {
      $('[data-toggle="tooltip"]').tooltip();
    });
</script>
{% endblock %}

{% block content %}
    <div class="col-sm-12">
        <h2>Events for Invoice ({{count}} Events, £ {{ total|floatformat:2 }})</h2>
        <p>These events have happened, but paperwork has not yet been sent to treasury</p>
        {% if is_paginated %}
            <div class="col-md-6 col-md-offset-6 col-sm-12 text-right">
                {% paginator %}
            </div>
        {% endif %}
        <div class="table-responsive col-sm-12">
            <table class="table table-hover">
                <thead>
                <tr>
                    <th>Event #</th>
                    <th>Start Date</th>
                    <th>Event Name</th>
                    <th>Client</th>
                    <th>Cost</th>
                    <th>MIC</th>
                    <th></th>
                </tr>
                </thead>
                <tbody>
                {% for object in object_list %}
                    <tr class="
                            {% if object.cancelled %}
                                active text-muted
                            {% elif not object.is_rig %}
                                info
                            {% elif object.confirmed and object.mic %}
                            {# interpreated as (booked and mic) #}
                                success
                            {% elif object.mic %}
                                warning
                            {% else %}
                                danger
                            {% endif %}
                            ">
                        <td><a href="{% url 'event_detail' object.pk %}">N{{ object.pk|stringformat:"05d" }}</a><br>
                            <span class="text-muted">{{ object.get_status_display }}</span></td>
                        <td>{{ object.start_date }}</td>
                        <td>
                            {{ object.name }}
                            {% if object.is_rig and perms.RIGS.view_event and object.authorised %}
                                <span class="glyphicon glyphicon-check"></span>
                            {% endif %}
                        </td>
                        <td>
                            {{ object.organisation.name }}
                            <br>
                            <span class="text-muted">{{ object.internal|yesno:'Internal,External' }}</span>
                        </td>
                        <td>
                            {{ object.sum_total|floatformat:2 }}
                            <br />
                            <span class="text-muted">{% if not object.internal %}{{ object.purchase_order }}{% endif %}</span>
                        </td>
                        <td class="text-center">
                            {% if object.mic %}
                                {{ object.mic.initials }}<br>
                                <img src="{{ object.mic.profile_picture }}" class="event-mic-photo"/>
                            {% else %}
                                <span class="glyphicon glyphicon-exclamation-sign"></span>
                            {% endif %}
                        </td>
                        <td class="text-right">
                            <a href="{% url 'invoice_event' object.pk %}"
                               class="btn btn-default"
                               data-toggle="tooltip"
                               title="'Invoice' this event - click this when paperwork has been sent to treasury">
                                <span class="glyphicon glyphicon-gbp"></span>
                            </a>
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
        {% if is_paginated %}
            <div class="col-md-6 col-md-offset-6 col-sm-12 text-right">
                {% paginator %}
            </div>
        {% endif %}
    </div>
{% endblock %}
