Added the comparative table
This commit is contained in:
parent
53253bcc83
commit
14e0ee7a76
@ -142,11 +142,24 @@
|
||||
<span class="kpi-label">Categorías</span>
|
||||
<span class="kpi-value">{{ kpi_categories }}</span>
|
||||
</div>
|
||||
|
||||
<div class="kpi-card">
|
||||
<span class="kpi-label"> Media diaria</span>
|
||||
<span class="kpi-value">{{ daily_average|floatformat:2 }}€ / día</span>
|
||||
</div>
|
||||
|
||||
{% if selected_month == today.month and selected_year == today.year %}
|
||||
<div class="kpi-card" style="border-left: 4px solid #ff9f43;">
|
||||
<span class="kpi-label">Proyección fin de mes</span>
|
||||
<span class="kpi-value">{{ projected_end_of_month|floatformat:2 }}€</span>
|
||||
<small style="color: gray; display:block;">Basado en tu ritmo de gasto actual</small>
|
||||
</div>
|
||||
{% endif %}
|
||||
</section>
|
||||
|
||||
{% if compare_enabled %}
|
||||
<section class="comparison">
|
||||
<h3>📊 Resumen comparativo</h3>
|
||||
<h3>Resumen comparativo</h3>
|
||||
<p>
|
||||
Gastos periodo actual: <strong>{{ kpi_total|floatformat:2 }} €</strong><br>
|
||||
Gastos periodo anterior: <strong>{{ kpi_previous_total|floatformat:2 }} €</strong><br>
|
||||
@ -158,6 +171,30 @@
|
||||
{% if kpi_trend == "up" %}⚠️ Has gastado más que el periodo pasado. {% else %} ¡Bien! Has reducido tus gastos. {% endif %}
|
||||
</small>
|
||||
</p>
|
||||
|
||||
<h3>Desglose de cambios por categoría</h3>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Categoría</th>
|
||||
<th>Periodo Anterior</th>
|
||||
<th>Periodo Actual</th>
|
||||
<th>Variación</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for cat in category_comparison %}
|
||||
<tr>
|
||||
<td>{{ cat.category }}</td>
|
||||
<td>{{ cat.previous|floatformat:2 }}€</td>
|
||||
<td>{{ cat.current|floatformat:2 }}€</td>
|
||||
<td style="font-weight: bold; color: {% if cat.difference > 0 %}#d9534f{% else %}#5cb85c{% endif %};">
|
||||
{% if cat.difference > 0 %}+{% endif %}{{ cat.difference|floatformat:2 }}€
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</section>
|
||||
{% endif %}
|
||||
|
||||
|
||||
@ -354,6 +354,8 @@ def dashboard(request):
|
||||
})
|
||||
|
||||
#Graphic
|
||||
daily_average = 0
|
||||
projected_end_of_month = 0
|
||||
if selected_month:
|
||||
by_day_qs = (
|
||||
expenses_filtered.annotate(day=ExtractDay("date"))
|
||||
@ -364,6 +366,14 @@ def dashboard(request):
|
||||
|
||||
import calendar
|
||||
num_days = calendar.monthrange(selected_year, selected_month)[1]
|
||||
if selected_year == today.year and selected_month == today.month:
|
||||
days_passed = today.day
|
||||
else:
|
||||
days_passed = calendar.monthrange(selected_year, selected_month)[1]
|
||||
|
||||
daily_average = total_amount / days_passed if days_passed > 0 else 0
|
||||
total_days_in_month = calendar.monthrange(selected_year, selected_month)[1]
|
||||
projected_end_of_month = daily_average * total_days_in_month
|
||||
|
||||
chart_labels = list(range(1, num_days + 1))
|
||||
chart_totals = [day_totals.get(d, 0) for d in chart_labels]
|
||||
@ -378,7 +388,7 @@ def dashboard(request):
|
||||
chart_labels = ["Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic"]
|
||||
chart_totals = [month_totals.get(m, 0) for m in range(1, 13)]
|
||||
chart_type = "month"
|
||||
|
||||
|
||||
year_list = (
|
||||
Expense.objects.filter(owner=request.user)
|
||||
.annotate(year=ExtractYear("date"))
|
||||
@ -462,13 +472,14 @@ def dashboard(request):
|
||||
|
||||
# Recent expenses
|
||||
recent_expenses = Expense.objects.filter(owner=request.user).order_by('-date', '-id')[:7]
|
||||
|
||||
|
||||
# Send the data to the dashboard
|
||||
return render(
|
||||
request,
|
||||
"expenses/dashboard.html",
|
||||
{
|
||||
"active_menu": "dashboard",
|
||||
"today": today,
|
||||
"by_category": by_category,
|
||||
"by_category_chart": by_category_chart,
|
||||
"chart_labels": chart_labels,
|
||||
@ -495,6 +506,8 @@ def dashboard(request):
|
||||
"period": period,
|
||||
"goals": goals,
|
||||
"recent_expenses": recent_expenses,
|
||||
"daily_average": daily_average,
|
||||
"projected_end_of_month": projected_end_of_month,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user