{% extends 'django_ledger/layouts/content_layout_1.html' %}
{% load i18n %}
{% load static %}
{% load django_ledger %}

{% block view_content %}
    <div class="columns">
        <div class="column is-4">
            <div class="columns is-multiline">
                <div class="column is-12">
                    {% include 'django_ledger/invoice/includes/card_invoice.html' with invoice=invoice entity_slug=view.kwargs.entity_slug style='invoice-detail' %}
                </div>
                <div class="column is-12">
                    {% include 'django_ledger/customer/includes/card_customer.html' with customer=invoice.customer %}
                </div>
                <div class="column is-12">
                    <a class="button is-info is-fullwidth is-outlined"
                       href="{% url 'django_ledger:invoice-list' entity_slug=view.kwargs.entity_slug %}">
                        {% trans 'Invoice List' %}
                    </a>
                </div>
            </div>
        </div>
        <div class="column is-8">
            <div class="columns is-multiline">
                <div class="column is-12">
                    <nav class="level">
                        <div class="level-item has-text-centered">
                            <div>
                                <p class="heading">{% trans 'Cash Account' %}:
                                    <a href="{% url 'django_ledger:account-detail' account_pk=invoice.cash_account.uuid coa_slug=invoice.cash_account.coa_model.slug entity_slug=view.kwargs.entity_slug %}"
                                       class="has-text-danger">{{ invoice.cash_account.code }}</a>
                                <p class="title">
                                    {% currency_symbol %}{{ invoice.get_amount_cash | absolute | currency_format }}</p>
                            </div>
                        </div>

                        {% if invoice.accrue %}
                            <div class="level-item has-text-centered">
                                <div>
                                    <p class="heading">{% trans 'Accounts Receivable' %}:
                                        <a href="{% url 'django_ledger:account-detail' account_pk=invoice.prepaid_account.uuid coa_slug=invoice.prepaid_account.coa_model.slug entity_slug=view.kwargs.entity_slug %}"
                                           class="has-text-danger">{{ invoice.prepaid_account.code }}</a>
                                    </p>
                                    <p class="title has-text-success">
                                        {% currency_symbol %}{{ invoice.get_amount_prepaid | currency_format }}</p>
                                </div>
                            </div>
                            <div class="level-item has-text-centered">
                                <div>
                                    <p class="heading">{% trans 'Deferred Revenue' %}:
                                        <a href="{% url 'django_ledger:account-detail' account_pk=invoice.unearned_account.uuid coa_slug=invoice.unearned_account.coa_model.slug entity_slug=view.kwargs.entity_slug %}"
                                           class="has-text-danger">{{ invoice.unearned_account.code }}</a>

                                    </p>
                                    <p class="title has-text-danger">
                                        {% currency_symbol %}{{ invoice.get_amount_unearned | currency_format }}</p>
                                </div>
                            </div>

                            <div class="level-item has-text-centered">
                                <div>
                                    <p class="heading">Accrued {{ invoice.get_progress_percent }}%</p>
                                    <p class="title">
                                        {% currency_symbol %}{{ invoice.get_amount_earned | currency_format }}</p>
                                </div>
                            </div>
                        {% else %}
                            <div class="level-item has-text-centered">
                                <div>
                                    <p class="heading">You Are Owed</p>
                                    <p class="title has-text-success">
                                        {% currency_symbol %}{{ invoice.get_amount_open | currency_format }}</p>
                                </div>
                            </div>
                        {% endif %}
                    </nav>
                </div>
                <div class="column is-12">
                    <div class="card">
                        <div class="card-header">
                            <h2 class="card-header-title has-text-weight-light is-size-3">
                                <span class="icon is-large">{% icon 'grommet-icons:transaction' 36 %}</span>
                                {% trans 'Invoice Items' %}
                            </h2>
                        </div>
                        {# todo: make this table a template... #}
                        <div class="card-content">
                            <div class="table-container">
                                <table class="table is-fullwidth is-narrow is-stripped is-bordered">

                                    <thead>
                                    <tr>
                                        <th>{% trans 'Item' %}</th>
                                        <th>{% trans 'Unit Cost' %}</th>
                                        <th>{% trans 'Quantity' %}</th>
                                        <th>{% trans 'Total' %}</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {% for invoice_item in itemtxs_qs %}
                                        <tr>
                                            <td>{{ invoice_item.item_model }}</td>
                                            <td>{% currency_symbol %}{{ invoice_item.unit_cost | currency_format }}</td>
                                            <td>{{ invoice_item.quantity }}</td>
                                            <td>
                                                {% currency_symbol %}{{ invoice_item.total_amount | currency_format }}</td>
                                        </tr>
                                    {% endfor %}
                                    </tbody>
                                    <tfoot>
                                    <tr>
                                        <th></th>
                                        <th></th>
                                        <th>{% trans 'Total' %}</th>
                                        <th>
                                            {% currency_symbol %}{{ total_amount_due | currency_format }}
                                        </th>

                                    </tr>
                                    </tfoot>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
                {% if invoice.is_active %}
                    <div class="column is-12">
                        <div class="buttons is-centered">
                            <a href="{% url 'django_ledger:ledger-bs' entity_slug=view.kwargs.entity_slug ledger_pk=invoice.ledger_id %}"
                               class="button is-info is-light is-outlined">{% trans 'Balance Sheet' %}</a>
                            <a href="{% url 'django_ledger:ledger-ic' entity_slug=view.kwargs.entity_slug ledger_pk=invoice.ledger_id %}"
                               class="button is-info is-light is-outlined">{% trans 'Income Statement' %}</a>
                            <a href="{% url 'django_ledger:ledger-cf' entity_slug=view.kwargs.entity_slug ledger_pk=invoice.ledger_id %}"
                               class="button is-info is-light is-outlined">{% trans 'Cash Flow Statement' %}</a>
                        </div>
                        <div class="column is-12">
                            <div class="buttons is-centered">
                                <a href="{% url 'django_ledger:ledger-bs-year' entity_slug=view.kwargs.entity_slug ledger_pk=invoice.ledger_id year=invoice.get_status_action_date.year %}?format=pdf&report_subtitle={{ invoice.generate_descriptive_title }}"
                                   class="button is-success is-light is-outlined">
                                    {% trans 'Balance Sheet PDF' %}{% icon 'bytesize:download' 24 %}</a>
                                <a href="{% url 'django_ledger:ledger-ic-year' entity_slug=view.kwargs.entity_slug ledger_pk=invoice.ledger_id year=invoice.get_status_action_date.year %}?format=pdf&report_subtitle={{ invoice.generate_descriptive_title }}"
                                   class="button is-success is-light is-outlined">
                                    {% trans 'Income Statement PDF' %}{% icon 'bytesize:download' 24 %}</a>
                                <a href="{% url 'django_ledger:ledger-cf-year' entity_slug=view.kwargs.entity_slug ledger_pk=invoice.ledger_id year=invoice.get_status_action_date.year %}?format=pdf&report_subtitle={{ invoice.generate_descriptive_title }}"
                                   class="button is-success is-light is-outlined">
                                    {% trans 'Cash Flow Statement PDF' %}{% icon 'bytesize:download' 24 %}</a>
                            </div>
                        </div>
                    </div>
                {% endif %}
                <div class="column is-12">
                    <div class="card">
                        <div class="card-header">
                            <h2 class="card-header-title has-text-weight-light is-size-3">
                                <span class="icon is-large">{% icon 'grommet-icons:transaction' 36 %}</span>
                                {% trans 'Invoice Transactions' %}
                            </h2>
                        </div>
                        <div class="card-content">
                            {% transactions_table invoice %}
                        </div>
                    </div>
                </div>
                <div class="column is-12">
                    {% include 'django_ledger/includes/card_markdown.html' with style='card_1'  title='Invoice Notes' notes_html=invoice.notes_html %}
                </div>
            </div>
        </div>
    </div>
{% endblock %}
