{% extends 'base.html' %}
{% load static %}
{% block title %}{{ year }} Yearly Financial Report{% endblock %}
{% block content %}
<div class="container-fluid">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <div><h1 class="h3 mb-0">{{ year }} Annual Financial Report</h1></div>
        <a href="{% url 'reports:financial_report' %}" class="btn btn-outline-secondary"><i class="fas fa-arrow-left me-2"></i>Back</a>
    </div>
    <div class="row mb-4">
        <div class="col-md-4"><div class="card border-left-success shadow h-100 py-2"><div class="card-body"><div class="text-xs font-weight-bold text-success text-uppercase mb-1">Total Revenue</div><div class="h4 fw-bold">{{ total_revenue|floatformat:0 }} XAF</div></div></div></div>
        <div class="col-md-4"><div class="card border-left-danger shadow h-100 py-2"><div class="card-body"><div class="text-xs font-weight-bold text-danger text-uppercase mb-1">Total Expenses</div><div class="h4 fw-bold">{{ total_expenses|floatformat:0 }} XAF</div></div></div></div>
        <div class="col-md-4"><div class="card border-left-primary shadow h-100 py-2"><div class="card-body"><div class="text-xs font-weight-bold text-primary text-uppercase mb-1">Net Profit</div><div class="h4 fw-bold {% if total_profit >= 0 %}text-success{% else %}text-danger{% endif %}">{{ total_profit|floatformat:0 }} XAF</div></div></div></div>
    </div>
    <div class="card shadow">
        <div class="card-header py-3"><h6 class="m-0 font-weight-bold text-primary">Monthly Breakdown</h6></div>
        <div class="card-body p-0">
            <table class="table table-hover mb-0">
                <thead class="table-dark"><tr><th>Month</th><th class="text-end">Revenue (XAF)</th><th class="text-end">Expenses (XAF)</th><th class="text-end">Net (XAF)</th></tr></thead>
                <tbody>
                    {% for row in monthly_data %}
                    <tr>
                        <td class="fw-bold">{{ row.month }}</td>
                        <td class="text-end text-success">{{ row.revenue|floatformat:0 }}</td>
                        <td class="text-end text-danger">{{ row.expenses|floatformat:0 }}</td>
                        <td class="text-end fw-bold {% if row.profit >= 0 %}text-primary{% else %}text-warning{% endif %}">{{ row.profit|floatformat:0 }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
                <tfoot class="table-dark">
                    <tr>
                        <td class="fw-bold">TOTAL</td>
                        <td class="text-end fw-bold text-success">{{ total_revenue|floatformat:0 }}</td>
                        <td class="text-end fw-bold text-danger">{{ total_expenses|floatformat:0 }}</td>
                        <td class="text-end fw-bold">{{ total_profit|floatformat:0 }}</td>
                    </tr>
                </tfoot>
            </table>
        </div>
    </div>
</div>
{% endblock %}
