Programming

4. add

# ... (Keep 1, 2, 3 as they were) ...

    # 4. INCOME (Доходы)
    elif prefix_1 == '4':
        category = "Доходы (Income)"
        # Note: Usually in Uzbekistan, accounts 410-451 are interest income, 452+ are non-interest
        if int(prefix_3) < 452:
            return category, "Процентные доходы (Interest)", "fa-arrow-trend-up"
        else:
            return category, "Беспроцентные доходы (Fees, etc.)", "fa-coins"

    # 5. EXPENSES (Расходы)
    elif prefix_1 == '5':
        category = "Расходы (Expenses)"
        if int(prefix_3) < 542:
            return category, "Процентные расходы", "fa-arrow-trend-down"
        elif prefix_2 == '56':
            return category, "Операционные расходы (OPEX)", "fa-building-user"
        elif prefix_3 == '559':
            return category, "Оценка убытков (Резервы)", "fa-shield-halved"
        else:
            return category, "Прочие расходы", "fa-receipt"
            
    return "Прочее", "Прочее", "fa-circle-question"
# ... (Keep your total_assets, total_liabilities, total_equity calculations) ...

    # P&L Calculations
    total_income = df[df['category'] == 'Доходы (Income)']['amount_abs'].sum()
    total_expenses = df[df['category'] == 'Расходы (Expenses)']['amount_abs'].sum()
    
    # Net Profit = Income - Expenses
    net_profit = total_income - total_expenses
    
    # Cost-to-Income Ratio (CIR) = Expenses / Income (Lower is better, usually target < 50%)
    cir_ratio = (total_expenses / total_income * 100) if total_income > 0 else 0

    # ... (Keep your structure_df grouping) ...

    # Add to context
    context.update({
        'total_income': total_income,
        'total_expenses': total_expenses,
        'net_profit': net_profit,
        'cir_ratio': cir_ratio,
        'income_structure': structure_df[structure_df['category'] == 'Доходы (Income)'].to_dict('records'),
        'expense_structure': structure_df[structure_df['category'] == 'Расходы (Expenses)'].to_dict('records'),
    })
<!-- ========================================== -->
        <!-- FINANCIAL PERFORMANCE (P&L) SECTION        -->
        <!-- ========================================== -->
        <div class="mt-5 pt-4" style="border-top: 2px dashed #e0e6ed;">
            <div class="text-center mb-4">
                <h3 class="fw-bold" style="color: #2c3e50;">
                    <i class="fas fa-chart-pie me-2 text-warning"></i> Финансовые результаты (P&L)
                </h3>
            </div>

            <div class="row">
                <!-- INCOME BLOCK -->
                <div class="col-md-5">
                    <div class="col-header bg-success shadow-sm mb-3" style="padding: 15px;">
                        <span>Всего Доходов</span>
                        <h4 class="mb-0 fw-bold font-monospace">{{ total_income|floatformat:0|intcomma }}</h4>
                    </div>
                    {% for item in income_structure %}
                    <div class="acc-item py-2">
                        <div class="acc-icon icon-ast" style="width: 40px; height: 40px; font-size: 1.1rem;"><i class="fas {{ item.icon }}"></i></div>
                        <div class="acc-details">
                            <div class="acc-name" style="font-size: 0.9rem;">{{ item.sub_category }}</div>
                            {% widthratio item.amount_abs total_income 100 as pct %}
                            <div class="acc-bar-wrap" style="height: 4px;"><div class="acc-bar bg-success" style="width: {{ pct }}%;"></div></div>
                        </div>
                        <div class="acc-value ms-3">
                            <div class="acc-amt" style="font-size: 0.9rem;">{{ item.amount_abs|floatformat:0|intcomma }}</div>
                            <div class="acc-pct">{{ pct }}%</div>
                        </div>
                    </div>
                    {% endfor %}
                </div>

                <!-- NET PROFIT CENTER KPI -->
                <div class="col-md-2 d-flex flex-column justify-content-center align-items-center">
                    <div class="text-center w-100 p-3 rounded-4 shadow-sm {% if net_profit > 0 %}bg-primary{% else %}bg-danger{% endif %} text-white" style="position: relative; z-index: 5;">
                        <span class="d-block small text-uppercase letter-spacing-1 mb-1">Чистая прибыль</span>
                        <h4 class="fw-bold m-0 font-monospace">{{ net_profit|floatformat:0|intcomma }}</h4>
                    </div>
                    
                    <div class="text-center mt-3 p-2 border rounded-3 w-100 bg-light">
                        <span class="d-block small text-muted text-uppercase" title="Cost to Income Ratio">CIR (Эффективность)</span>
                        <h5 class="fw-bold m-0 {% if cir_ratio > 60 %}text-danger{% else %}text-success{% endif %}">{{ cir_ratio|floatformat:1 }}%</h5>
                    </div>
                </div>

                <!-- EXPENSE BLOCK -->
                <div class="col-md-5">
                    <div class="col-header bg-danger shadow-sm mb-3" style="padding: 15px;">
                        <span>Всего Расходов</span>
                        <h4 class="mb-0 fw-bold font-monospace">{{ total_expenses|floatformat:0|intcomma }}</h4>
                    </div>
                    {% for item in expense_structure %}
                    <div class="acc-item py-2">
                        <div class="acc-icon icon-lia" style="width: 40px; height: 40px; font-size: 1.1rem;"><i class="fas {{ item.icon }}"></i></div>
                        <div class="acc-details">
                            <div class="acc-name" style="font-size: 0.9rem;">{{ item.sub_category }}</div>
                            {% widthratio item.amount_abs total_expenses 100 as pct %}
                            <div class="acc-bar-wrap" style="height: 4px;"><div class="acc-bar bg-danger" style="width: {{ pct }}%;"></div></div>
                        </div>
                        <div class="acc-value ms-3">
                            <div class="acc-amt" style="font-size: 0.9rem;">{{ item.amount_abs|floatformat:0|intcomma }}</div>
                            <div class="acc-pct">{{ pct }}%</div>
                        </div>
                    </div>
                    {% endfor %}
                </div>
            </div>
        </div>
Foydali bo'ldimi? Yoqmadi 0 Baholash uchun kiring