{% extends 'base.html' %}
{% load i18n %}

{% block content %}
<div class="container-fluid py-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div>
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb mb-1">
                    <li class="breadcrumb-item"><a href="{% url 'accounting_dashboard' %}">{% trans "Accounting" %}</a></li>
                    <li class="breadcrumb-item active">{% trans "Profit & Loss" %}</li>
                </ol>
            </nav>
            <h2 class="mb-0">{% trans "Profit & Loss Statement" %}</h2>
            <p class="text-muted small">{% trans "Period ending" %} {{ date|date:"F d, Y" }}</p>
        </div>
        <button class="btn btn-outline-primary" onclick="window.print()">
            <i class="bi bi-printer"></i> {% trans "Print Report" %}
        </button>
    </div>

    <div class="row justify-content-center">
        <div class="col-lg-8">
            <div class="card border-0 shadow-sm">
                <div class="card-body p-0">
                    <table class="table mb-0">
                        <thead class="bg-primary text-white">
                            <tr>
                                <th class="py-3 ps-4">{% trans "Description" %}</th>
                                <th class="text-end py-3 pe-4">{% trans "Amount" %}</th>
                            </tr>
                        </thead>
                        <tbody>
                            <!-- Revenue -->
                            <tr class="bg-light fw-bold">
                                <td colspan="2" class="ps-4">{% trans "REVENUE" %}</td>
                            </tr>
                            {% for acc in revenue_accounts %}
                            <tr>
                                <td class="ps-5">{% if LANGUAGE_CODE == 'ar' %}{{ acc.name_ar }}{% else %}{{ acc.name_en }}{% endif %}</td>
                                <td class="text-end pe-4">{{ acc.balance|floatformat:global_settings.decimal_places }}</td>
                            </tr>
                            {% endfor %}
                            <tr class="fw-bold">
                                <td class="ps-4">{% trans "Total Revenue" %}</td>
                                <td class="text-end pe-4 border-top">{{ revenue_total|floatformat:global_settings.decimal_places }}</td>
                            </tr>

                            <!-- Expenses -->
                            <tr class="bg-light fw-bold">
                                <td colspan="2" class="ps-4 mt-4">{% trans "EXPENSES" %}</td>
                            </tr>
                            {% for acc in expense_accounts %}
                            <tr>
                                <td class="ps-5">{% if LANGUAGE_CODE == 'ar' %}{{ acc.name_ar }}{% else %}{{ acc.name_en }}{% endif %}</td>
                                <td class="text-end pe-4">({{ acc.balance|floatformat:global_settings.decimal_places }})</td>
                            </tr>
                            {% endfor %}
                            <tr class="fw-bold">
                                <td class="ps-4">{% trans "Total Expenses" %}</td>
                                <td class="text-end pe-4 border-top">({{ expense_total|floatformat:global_settings.decimal_places }})</td>
                            </tr>
                        </tbody>
                        <tfoot class="bg-dark text-white fw-bold">
                            <tr>
                                <td class="py-3 ps-4">{% trans "NET PROFIT / LOSS" %}</td>
                                <td class="text-end py-3 pe-4">{{ net_profit|floatformat:global_settings.decimal_places }}</td>
                            </tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
@media print {
    .breadcrumb, .btn, .sidebar, .header { display: none !important; }
    .main-content { margin: 0 !important; padding: 0 !important; }
}
</style>
{% endblock %}
