{% extends "./layout/default" %}

{% block breadcrumbs %}
    {{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, journal) }}
{% endblock %}

{% block content %}
    <div class="row">
        <div class="col-lg-6 col-md-6 col-sm-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'transaction_journal_information'|_ }}</h3>
                </div>
                <div class="box-body table-responsive no-padding">
                    <table class="table table-hover">
                        <tbody>
                        <tr>
                            <td>{{ trans('list.type') }}</td>
                            <td>{{ journal.transactiontype.type|_ }}</td>
                        </tr>
                        <tr>
                            <td>{{ trans('list.description') }}</td>
                            <td>{{ journal.description }}</td>
                        </tr>
                        <!-- source(s) -->
                        <tr>
                            <td>{{ 'source_accounts'|_ }}</td>
                            <td>{{ sourceAccount(journal)|raw }}</td>
                        </tr>

                        <!-- destination(s) -->
                        <tr>
                            <td>{{ 'destination_accounts'|_ }}</td>
                            <td>{{ destinationAccount(journal)|raw }}</td>
                        </tr>
                        <!-- total amount -->
                        <tr>
                            <td>{{ 'total_amount'|_ }}</td>
                            <td>
                                {{ journalAmount(journal) }}
                            </td>
                        </tr>
                        <tr>
                            <td style="width:30%;">{{ trans('list.date') }}</td>
                            <td>{{ journal.date.formatLocalized(monthAndDayFormat) }}</td>
                        </tr>
                        </tbody>
                    </table>
                </div>
                <div class="box-footer">
                    <div class="pull-right">
                        <a class="btn btn-default" href="{{ route('transactions.edit',journal.id) }}"><i class="fa fa-pencil fa-fw"></i> {{ 'edit'|_ }}</a>
                        <a href="{{ route('transactions.delete',journal.id) }}" class="btn btn-danger"><i class="fa fa-trash fa-fw"></i> {{ 'delete'|_ }}</a>
                    </div>
                </div>
            </div>

            <!-- events, if present -->
            {% if journal.piggyBankEvents|length > 0 %}
                <div class="box">
                    <div class="box-header with-border">
                        <h3 class="box-title">{{ 'piggyBanks'|_ }}</h3>
                    </div>
                    <div class="box-body table-responsive no-padding">
                        {% include 'list/piggy-bank-events' with {'events': events, 'showPiggyBank':true} %}
                    </div>
                </div>
            {% endif %}
        </div>
        <div class="col-lg-6 col-md-6 col-sm-12">

            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'transaction_journal_meta'|_ }}</h3>
                </div>
                <div class="box-body table-responsive no-padding">
                    <table class="table table-hover">
                        <tbody>
                        <tr>
                            <td>{{ 'categories'|_ }}</td>
                            <td>{{ journalCategories(journal)|raw }}</td>
                        </tr>
                        <tr>
                            <td>{{ 'budgets'|_ }}</td>
                            <td>{{ journalBudgets(journal)|raw }}</td>
                        </tr>

                        {% if journal.hasMeta('interest_date') %}
                            <tr>
                                <td>{{ trans('list.interest_date') }}</td>
                                <td>{{ journal.getMeta('interest_date').formatLocalized(monthAndDayFormat) }}</td>
                            </tr>

                        {% endif %}

                        {% if journal.hasMeta('book_date') %}
                            <tr>
                                <td>{{ trans('list.book_date') }}</td>
                                <td>{{ journal.getMeta('book_date').formatLocalized(monthAndDayFormat) }}</td>
                            </tr>
                        {% endif %}
                        {% if journal.hasMeta('process_date') %}
                            <tr>
                                <td>{{ trans('list.process_date') }}</td>
                                <td>{{ journal.getMeta('process_date').formatLocalized(monthAndDayFormat) }}</td>
                            </tr>

                        {% endif %}

                        {% if journal.hasMeta('due_date') %}
                            <tr>
                                <td>{{ trans('list.due_date') }}</td>
                                <td>{{ journal.getMeta('due_date').formatLocalized(monthAndDayFormat) }}</td>
                            </tr>

                        {% endif %}
                        {% if journal.hasMeta('payment_date') %}
                            <tr>
                                <td>{{ trans('list.payment_date') }}</td>
                                <td>{{ journal.getMeta('payment_date').formatLocalized(monthAndDayFormat) }}</td>
                            </tr>

                        {% endif %}
                        {% if journal.hasMeta('invoice_date') %}
                            <tr>
                                <td>{{ trans('list.invoice_date') }}</td>
                                <td>{{ journal.getMeta('invoice_date').formatLocalized(monthAndDayFormat) }}</td>
                            </tr>
                        {% endif %}
                        {% if journal.hasMeta('internal_reference') and journal.getMeta('internal_reference') != "" %}
                            <tr>
                                <td>{{ trans('list.internal_reference') }}</td>
                                <td>{{ journal.getMeta('internal_reference') }}</td>
                            </tr>
                        {% endif %}

                        {% if journal.hasMeta('notes') and journal.getMeta('notes') != "" %}
                            <tr>
                                <td>{{ trans('list.notes') }}</td>
                                <td>{{ journal.getMeta('notes')|nl2br }}</td>
                            </tr>

                        {% endif %}

                        {% if journal.bill %}
                            <tr>
                                <td>{{ 'bill'|_ }}</td>
                                <td><a href="{{ route('bills.show', journal.bill_id) }}">{{ journal.bill.name }}</a></td>
                            </tr>
                        {% endif %}
                        {% if journal.tags|length > 0 %}
                            <tr>
                                <td>{{ 'tags'|_ }}</td>
                                <td>
                                    {% for tag in journal.tags %}

                                        <h4 style="display: inline;"><a class="label label-success" href="{{ route('tags.show',tag) }}">
                                                {% if tag.tagMode == 'nothing' %}
                                                    <i class="fa fa-fw fa-tag"></i>
                                                {% endif %}
                                                {% if tag.tagMode == 'balancingAct' %}
                                                    <i class="fa fa-fw fa-refresh"></i>
                                                {% endif %}
                                                {% if tag.tagMode == 'advancePayment' %}
                                                    <i class="fa fa-fw fa-sort-numeric-desc"></i>
                                                {% endif %}
                                                {{ tag.tag }}</a>
                                        </h4>
                                    {% endfor %}
                                </td>
                            </tr>
                        {% endif %}
                        </tbody>
                    </table>
                </div>
            </div>
            {% if journal.attachments|length > 0 %}
                <div class="box">
                    <div class="box-header with-border">
                        <h3 class="box-title">{{ 'attachments'|_ }}</h3>
                    </div>
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover">
                            {% for att in journal.attachments %}
                                <tr>
                                    <td>
                                        <div class="btn-group btn-group-xs">
                                            <a href="{{ route('attachments.edit', att.id) }}" class="btn btn-default"><i class="fa fa-pencil"></i></a>
                                            <a href="{{ route('attachments.delete', att.id) }}" class="btn btn-danger"><i class="fa fa-trash"></i></a>
                                        </div>
                                    </td>
                                    <td>
                                        <i class="fa {{ att.mime|mimeIcon }}"></i>
                                        <a href="{{ route('attachments.download', att.id) }}" title="{{ att.filename }}">
                                            {% if att.title %}
                                                {{ att.title }}
                                            {% else %}
                                                {{ att.filename }}
                                            {% endif %}
                                        </a>
                                        ({{ att.size|filesize }})
                                        {% if att.description %}
                                            <br/>
                                            <em>{{ att.description }}</em>
                                        {% endif %}
                                    </td>
                                    <td style="width:100px;">
                                        <img src="{{ route('attachments.preview', att.id) }}"/>
                                    </td>
                                </tr>
                            {% endfor %}
                        </table>
                    </div>
                </div>
            {% endif %}
            {% if transactions|length == 1 %}
                <div class="box">
                    <div class="box-header with-border">
                        <h3 class="box-title">{{ 'transaction_journal_other_options'|_ }}</h3>
                    </div>
                    <div class="box-body">
                        {% if journal.transactionType.type != "Withdrawal" %}
                            <p>
                                <i class="fa fa-exchange" aria-hidden="true"></i>
                                <a href="{{ route('transactions.convert.index', ['withdrawal', journal.id]) }}">
                                    {{ ('convert_'~journal.transactionType.type~'_to_withdrawal')|_ }}
                                </a>
                            </p>
                        {% endif %}
                        {% if journal.transactionType.type != "Deposit" %}
                            <p>
                                <i class="fa fa-exchange" aria-hidden="true"></i>
                                <a href="{{ route('transactions.convert.index', ['deposit', journal.id]) }}">
                                    {{ ('convert_'~journal.transactionType.type~'_to_deposit')|_ }}
                                </a>
                            </p>
                        {% endif %}

                        {% if journal.transactionType.type != "Transfer" %}
                            <p>
                                <i class="fa fa-exchange" aria-hidden="true"></i>
                                <a href="{{ route('transactions.convert.index', ['transfer', journal.id]) }}">
                                    {{ ('convert_'~journal.transactionType.type~'_to_transfer')|_ }}
                                </a>
                            </p>
                        {% endif %}
                        {% if transactions|length == 1 %}
                            <p>
                                <i class="fa fa-copy" aria-hidden="true"></i>
                                <a href="{{ route('transactions.clone', [journal.id]) }}">
                                    {{ ('clone_'~journal.transactionType.type|lower)|_ }}
                                </a>
                            </p>
                        {% endif %}

                    </div>
                </div>
            {% endif %}
        </div>
    </div>

    <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12">

            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">{{ 'transactions'|_ }}</h3>
                </div>
                <table class="table table-bordered table-striped">
                    <thead>
                    <tr>
                        <th>{{ trans('list.description') }}</th>
                        <th>{{ trans('list.source_account') }}</th>
                        <th>&#916;</th>
                        <th>{{ trans('list.destination_account') }}</th>
                        <th>&#916;</th>
                        <th>{{ trans('list.amount') }}</th>
                        <th>{{ trans('list.budget') }}</th>
                        <th>{{ trans('list.category') }}</th>
                    </tr>
                    </thead>
                    <tbody>
                    {% for transaction in transactions %}
                        <tr>
                            <td>
                                {% if transaction.description == "" %}
                                    {{ journal.description }}
                                {% else %}
                                    {{ transaction.description }}
                                {% endif %}
                            </td>
                            <td>
                                {% if transaction.source_account_type == 'Cash account' %}
                                    <span class="text-success">(cash)</span>
                                {% else %}
                                    <a href="{{ route('accounts.show', transaction.source_account_id) }}">{{ transaction.source_account_name }}</a>
                                {% endif %}

                            </td>
                            <td>
                                {{ formatSourceBefore(transaction) }} &rarr; {{ formatSourceAfter(transaction) }}
                            </td>
                            <td>
                                {% if transaction.destination_account_type == 'Cash account' %}
                                    <span class="text-success">(cash)</span>
                                {% else %}
                                    <a href="{{ route('accounts.show', transaction.destination_account_id) }}">{{ transaction.destination_account_name }}</a>
                                {% endif %}

                            </td>
                            <td>
                                {{ formatDestinationBefore(transaction) }} &rarr; {{ formatDestinationAfter(transaction) }}
                            </td>
                            <td>
                                {{ journalAmount(journal) }}
                            </td>
                            <td>
                                {{ transactionIdBudgets(transaction.source_id) }}
                            </td>
                            <td>
                                {{ transactionIdCategories(transaction.source_id) }}
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <!-- end -->
{% endblock %}
