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

{% block title %}Invoices{% endblock %}

{% block content %}
    <div class="col-sm-12">
        <h2>{% block heading %}Invoices{% endblock %}</h2>
        {% block description %}{% endblock %}
        {% if is_paginated %}
            <div class="col-md-6 col-md-offset-6 col-sm-12 text-right">
                {% paginator %}
            </div>
        {% endif %}
        {% block search %}{% endblock %}
        <div class="table-responsive col-sm-12">
            <table class="table table-hover">
                <thead>
                <tr>
                    <th>Invoice #</th>
                    <th>Event</th>
                    <th>Client</th>
                    <th>Event Date</th>
                    <th>Invoice Date</th>
                    <th>Balance</th>
                    <th></th>
                </tr>
                </thead>
                <tbody>
                {% for object in object_list %}
                    <tr>
                        <td class="{% if object.is_closed %}success{% else %}warning{% endif %}">{{ object.pk }}<br>
                        <span class="text-muted">{% if object.void %}(VOID){% elif object.is_closed %}(PAID){% else %}(O/S){% endif %}</span></td>
                        <td class="
                            {% if object.event.cancelled %}
                                active text-muted
                            {% elif not object.event.is_rig %}
                                info
                            {% elif object.event.confirmed and object.event.mic %}
                            {# interpreated as (booked and mic) #}
                                success
                            {% elif object.event.mic %}
                                warning
                            {% else %}
                                danger
                            {% endif %}
                            "><a href="{% url 'event_detail' object.event.pk %}">N{{ object.event.pk|stringformat:"05d" }}</a>: {{ object.event.name }} <br>
                            <span class="text-muted">{{ object.event.get_status_display }}{% if not object.event.mic %}, No MIC{% endif %}
                            </span></td>
                        </td>
                        <td>{% if object.event.organisation %}
                                {{ object.event.organisation.name }}
                                <br>
                                <span class="text-muted">{{ object.event.internal|yesno:'Internal,External' }}</span>
                            {% else %}
                                {{ object.event.person.name }}
                                <br>
                                <span class="text-muted">External</span>
                            {% endif %}
                        </td>
                        <td>{{ object.event.start_date }}</td>
                        <td>{{ object.invoice_date }}</td>
                        <td>
                            {{ object.balance|floatformat:2 }}
                            <br />
                            <span class="text-muted">{{ object.event.purchase_order }}</span>
                        </td>
                        <td class="text-right">
                            <a href="{% url 'invoice_detail' object.pk %}" class="btn btn-default">
                                <span class="glyphicon glyphicon-pencil"></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 %}
