{% extends 'base.html' %}

{% block title %}Invoice {{ object.pk }}{% endblock %}

{% block content %}
    <div class="col-sm-12">
        <div class="row">
            <div class="col-sm-8">
                <h2>Invoice {{ object.pk }}</h2>
            </div>

            <div class="col-sm-4 text-right">
                <a href="{% url 'invoice_void' object.pk %}" class="btn btn-default" title="Void Invoice">
                    <span class="glyphicon glyphicon-text-background"></span>
                </a>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-6">
                <div class="panel panel-default">
                    <div class="panel-heading">Invoice Details</div>
                    <div class="panel-body">
                        {% if object.event.organisation %}
                            {{ object.event.organisation.name }}<br/>
                            {{ object.event.organisation.address|linebreaksbr }}
                        {% else %}
                            {{ object.event.person.name }}<br/>
                            {{ object.event.person.address|linebreaksbr }}
                        {% endif %}
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="panel panel-{% if object.void %}danger{% else %}info{% endif %}">
                    <div class="panel-heading">Event Details</div>
                    <div class="panel-body">
                        <dl class="dl-horizontal">
                            <dt>Event Number</dt>
                            <dd>N{{ object.event.pk|stringformat:"05d" }}</dd>

                            <dt>Event</dt>
                            <dd>{{ objet.event.pk }}</dd>

                            <dt>Event Venue</dt>
                            <dd>{{ object.event.venue }}</dd>

                            <dt>Event MIC</dt>
                            <dd>{{ object.event.mic.name }}</dd>

                            <dt>Status</dt>
                            <dd>{{ object.event.get_status_display }}</dd>

                            {% if object.event.dry_hire %}
                                <dd>&nbsp;</dd>
                                <dt>Checked In By</dt>
                                <dd>{{ object.checked_in_by.name }}</dd>
                            {% endif %}

                            <dt>PO</dt>
                            <dd>{{ object.event.purchase_order }}</dd>
                        </dl>
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-6">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <div class="pull-right">
                            <a href="{% url 'payment_create' %}?invoice={{ object.pk }}"
                               class="btn btn-default modal-href"
                               data-target="#{{ form.person.id_for_label }}">
                                <span class="glyphicon glyphicon-plus"></span> Add
                            </a>
                        </div>
                        <table class="table table-hover">
                            <thead>
                            <tr>
                                <td>Date</td>
                                <td>Amount</td>
                                <td>Method</td>
                                <td></td>
                            </tr>
                            </thead>
                            <tbody>
                            {% for payment in object.payment_set.all %}
                                <tr>
                                    <td>{{ payment.date }}</td>
                                    <td>{{ payment.amount|floatformat:2 }}</td>
                                    <td>{{ payment.get_method_display }}</td>
                                    <td>
                                        <a href="{% url 'payment_delete' payment.pk %}"
                                           class="btn btn-small btn-danger"><span class="glyphicon glyphicon-remove"</a>
                                    </td>
                                </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

            <div class="col-sm-6">
                <div class="panel panel-default">
                    <div class="panel-body">
                        {% with object.event as object %}
                            {% include 'RIGS/item_table.html' %}
                        {% endwith %}
                    </div>
                </div>
            </div>
        </div>

    </div>
{% endblock %}