{#
The Mia! Accounting Project
journal.html: The journal

 Copyright (c) 2023 imacat.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

Author: imacat@mail.imacat.idv.tw (imacat)
First written: 2023/3/4
#}
{% extends "accounting/base.html" %}

{% block accounting_scripts %}
  <script src="{{ url_for("accounting.static", filename="js/material-fab-speed-dial.js") }}"></script>
  <script src="{{ url_for("accounting.static", filename="js/period-chooser.js") }}"></script>
{% endblock %}

{% block header %}{% block title %}{{ A_("Journal %(period)s", period=report.period.desc|title) }}{% endblock %}{% endblock %}

{% block content %}

<div class="mb-3 accounting-toolbar">
  {% with use_period_chooser = true %}
    {% include "accounting/report/include/toolbar-buttons.html" %}
  {% endwith %}
</div>

{% include "accounting/report/include/add-journal-entry-material-fab.html" %}

{% include "accounting/report/include/period-chooser.html" %}

{% include "accounting/report/include/search-modal.html" %}

{% if report.has_data %}
  {% with pagination = report.pagination %}
    {% include "accounting/include/pagination.html" %}
  {% endwith %}

  <div class="d-none d-md-block accounting-report-table accounting-journal-table">
    <div class="accounting-report-table-header">
      <div class="accounting-report-table-row">
        <div>{{ A_("Date") }}</div>
        <div>{{ A_("Currency") }}</div>
        <div>{{ A_("Account") }}</div>
        <div>{{ A_("Description") }}</div>
        <div class="accounting-amount">{{ A_("Debit") }}</div>
        <div class="accounting-amount">{{ A_("Credit") }}</div>
      </div>
    </div>
    <div class="accounting-report-table-body">
      {% for line_item in report.line_items %}
        <a class="accounting-report-table-row" href="{{ url_for("accounting.journal-entry.detail", journal_entry=line_item.journal_entry)|accounting_append_next }}">
          <div>{{ line_item.journal_entry.date|accounting_format_date }}</div>
          <div>{{ line_item.currency.name }}</div>
          <div>
            <span class="d-none d-md-inline">{{ line_item.account.code }}</span>
            {{ line_item.account.title }}
          </div>
          <div>{{ line_item.description|accounting_default }}</div>
          <div class="accounting-amount">{{ line_item.debit|accounting_format_amount|accounting_default }}</div>
          <div class="accounting-amount">{{ line_item.credit|accounting_format_amount|accounting_default }}</div>
        </a>
      {% endfor %}
    </div>
  </div>

  <div class="list-group d-md-none">
  {% for line_item in report.line_items %}
    <a class="list-group-item list-group-item-action" href="{{ url_for("accounting.journal-entry.detail", journal_entry=line_item.journal_entry)|accounting_append_next }}">
      <div class="d-flex justify-content-between">
        <div {% if not line_item.is_debit %} class="accounting-mobile-journal-credit" {% endif %}>
          <div class="text-muted small">
            {{ line_item.journal_entry.date|accounting_format_date }}
            {{ line_item.account.title }}
            {% if line_item.currency.code != accounting_default_currency_code() %}
              <span class="badge rounded-pill bg-info">{{ line_item.currency.code }}</span>
            {% endif %}
          </div>
          {% if line_item.description is not none %}
            <div>{{ line_item.description }}</div>
          {% endif %}
        </div>

        <div>
          <span class="badge rounded-pill bg-info">{{ line_item.amount|accounting_format_amount }}</span>
        </div>
      </div>
    </a>
  {% endfor %}
  </div>
{% else %}
  <p>{{ A_("There is no data.") }}</p>
{% endif %}

{% endblock %}
