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

{% block view_content %}
    <div class="container">
        <div class="columns is-multiline">
            <div class="column is-12">
                {% include 'django_ledger/customer/includes/card_customer.html' with customer=invoice.customer %}
            </div>
            <div class="column is-12">
                {% include 'django_ledger/invoice/includes/card_invoice.html' with invoice=invoice style='invoice-detail' entity_slug=view.kwargs.entity_slug %}
                <form action="{% url 'django_ledger:invoice-update' entity_slug=view.kwargs.entity_slug invoice_pk=invoice.uuid %}"
                      method="post">
                    {% csrf_token %}
                    {{ form }}
                    <button type="submit"
                            class="button is-primary is-fullwidth djetler_my_1">{% trans 'Save Invoice' %}</button>

                    <a href="{% url 'django_ledger:invoice-detail' entity_slug=view.kwargs.entity_slug invoice_pk=invoice.uuid %}"
                       class="button is-small is-dark is-fullwidth mt-2">{% trans 'Back to Invoice Detail' %}</a>
                    <a href="{% url 'django_ledger:invoice-list' entity_slug=view.kwargs.entity_slug %}"
                       class="button is-small is-info is-fullwidth mt-2">{% trans 'Invoice List' %}</a>
                    <a href="{% url 'django_ledger:entity-dashboard' entity_slug=view.kwargs.entity_slug %}"
                       class="button is-small is-info is-outlined is-fullwidth mt-2">{% trans 'Go To Dashboard' %}</a>

                </form>
            </div>
            <div class="column is-12">
                {% invoice_item_formset_table itemtxs_formset %}
            </div>
            {% if invoice.is_configured %}
                <div class="column is-12">
                    <div class="card">
                        <div class="card-header">
                            <p class="card-header-title">{% trans 'Invoice State' %}</p>
                        </div>
                        <div class="card-body">
                            <div class="card-content">
                                <div class="columns is-multiline">
                                    <div class="column is-12">
                                        <h3 class="is-size-3">{% trans 'Invoice State' %}</h3>
                                        <p>{{ invoice.cash_account }}:
                                            {% currency_symbol %}{{ invoice.get_amount_cash | currency_format }}</p>
                                        <p>{{ invoice.prepaid_account }}:
                                            {% currency_symbol %}{{ invoice.get_amount_prepaid | currency_format }}</p>
                                        <p>{{ invoice.unearned_account }}:
                                            {% currency_symbol %}{{ invoice.get_amount_unearned | currency_format }}</p>
                                    </div>
                                    <div class="column is-12">
                                        <h3 class="is-size-3">{% trans 'Ledger State' %}</h3>
                                        <p>{{ invoice.cash_account }}:
                                            {% currency_symbol %}{{ invoice.amount_paid | currency_format }}</p>
                                        <p>{{ invoice.prepaid_account }}:
                                            {% currency_symbol %}{{ invoice.amount_receivable | currency_format }}</p>
                                        <p>{{ invoice.unearned_account }}:
                                            {% currency_symbol %}{{ invoice.amount_unearned | currency_format }}</p>
                                    </div>
                                    {% now "Y" as current_year %}
                                    {% now "m" as current_month %}
                                    <div class="column is-6">
                                        <a class="button is-outlined is-small is-primary is-fullwidth"
                                           href="{% url 'django_ledger:ledger-bs-month' ledger_pk=invoice.ledger.uuid entity_slug=view.kwargs.entity_slug year=current_year month=current_month %}">
                                            {% trans 'Balance Sheet' %}</a>
                                    </div>
                                    <div class="column is-6">
                                        <a class="button is-outlined is-small is-info is-fullwidth"
                                           href="{% url 'django_ledger:ledger-ic-month' ledger_pk=invoice.ledger.uuid entity_slug=view.kwargs.entity_slug year=current_year month=current_month %}">
                                            {% trans 'Income Statement' %}</a>
                                    </div>
                                    <div class="column is-12">
                                        <a class="button is-small is-warning is-fullwidth"
                                           href="{% url 'django_ledger:ledger-update' ledger_pk=invoice.ledger.uuid entity_slug=view.kwargs.entity_slug %}">
                                            {% trans 'Invoice Ledger' %}
                                        </a>
                                        <a class="button is-small is-info is-fullwidth mt-2"
                                           href="{% url 'django_ledger:je-list' ledger_pk=invoice.ledger.uuid entity_slug=view.kwargs.entity_slug %}">
                                            {% trans 'Ledger Journal Entries' %}
                                        </a>
                                        <a href="{% url "django_ledger:invoice-action-lock-ledger" entity_slug=view.kwargs.entity_slug invoice_pk=invoice.uuid %}"
                                           class="button is-small is-success is-fullwidth mt-2">{% trans 'Lock Ledger' %}</a>
                                        <a href="{% url "django_ledger:invoice-action-unlock-ledger" entity_slug=view.kwargs.entity_slug invoice_pk=invoice.uuid %}"
                                           class="button is-small is-danger is-fullwidth mt-2">{% trans 'Unlock Ledger' %}</a>
                                        <a href="{% url "django_ledger:invoice-action-force-migrate" entity_slug=view.kwargs.entity_slug invoice_pk=invoice.uuid %}"
                                           class="button is-small is-danger is-fullwidth mt-2">{% trans 'Force Migrate' %}</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            {% else %}
                <div class="column is-12">
                    <div class="card animate__animated animate__tada">
                        <div class="card-header">
                            <p class="card-header-title">{% trans 'Invoice Configuration' %}</p>
                        </div>
                        <div class="card-body">
                            <div class="card-content">
                                <div class="field">
                                    <div class="control">
                                        <label for="{{ form.cash_account.id_for_label }}" class="label">
                                            {{ form.cash_account.label }}</label>
                                        {{ form.cash_account }}
                                    </div>
                                </div>
                                <div class="field">
                                    <div class="control">
                                        <label for="{{ form.prepaid_account.id_for_label }}" class="label">
                                            {{ form.prepaid_account.label }}</label>
                                        {{ form.prepaid_account }}
                                    </div>
                                </div>
                                <div class="field">
                                    <div class="control">
                                        <label for="{{ form.unearned_account.id_for_label }}" class="label">
                                            {{ form.unearned_account.label }}</label>
                                        {{ form.unearned_account }}
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            {% endif %}
        </div>
    </div>
{% endblock %}
