{% extends "base.html" %}

{% block title %}Project Income Statement - {{ project.project_title }}{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="card shadow">
        <div class="card-header bg-primary text-white">
            <h4 class="mb-0">Income Statement for: {{ project.project_title }}</h4>
        </div>
        <div class="card-body">
            <h5 class="text-success">Revenues</h5>
            {% if revenues %}
            <table class="table table-bordered table-striped">
                <thead class="table-light">
                    <tr>
                        <th>Account</th>
                        <th class="text-end">Amount</th>
                    </tr>
                </thead>
                <tbody>
                    {% for rev in revenues %}
                    <tr>
                        <td>{{ rev.account }}</td>
                        <td class="text-end">{{ rev.amount|floatformat:2 }}</td>
                    </tr>
                    {% endfor %}
                    <tr class="table-active">
                        <td><strong>Total Revenue</strong></td>
                        <td class="text-end"><strong>{{ total_revenue|floatformat:2 }}</strong></td>
                    </tr>
                </tbody>
            </table>
            {% else %}
            <p>No revenue recorded for this project.</p>
            {% endif %}

            <h5 class="text-danger mt-4">Expenses</h5>
            {% if expenses %}
            <table class="table table-bordered table-striped">
                <thead class="table-light">
                    <tr>
                        <th>Account</th>
                        <th class="text-end">Amount</th>
                    </tr>
                </thead>
                <tbody>
                    {% for exp in expenses %}
                    <tr>
                        <td>{{ exp.account }}</td>
                        <td class="text-end">{{ exp.amount|floatformat:2 }}</td>
                    </tr>
                    {% endfor %}
                    <tr class="table-active">
                        <td><strong>Total Expenses</strong></td>
                        <td class="text-end"><strong>{{ total_expense|floatformat:2 }}</strong></td>
                    </tr>
                </tbody>
            </table>
            {% else %}
            <p>No expenses recorded for this project.</p>
            {% endif %}

            <div class="mt-4">
                <h5 class="{{ net_income_class }}">
                    Net Income: {{ net_income|floatformat:2 }}
                </h5>
            </div>

            <div class="mt-3 text-end">
                <a href="{% url 'project_dashboard' project.id %}" class="btn btn-secondary">
                    <i class="bi bi-arrow-left"></i> Back to Dashboard
                </a>
            </div>
        </div>
    </div>
</div>
{% endblock %}
