mirror of
https://github.com/wahyd4/links.git
synced 2026-08-08 21:04:53 +10:00
add transaction history section to invest dashboard
This commit is contained in:
@@ -4,7 +4,7 @@ import logging
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.utils import timezone
|
||||
|
||||
from .models import Portfolio
|
||||
from .models import Portfolio, Transaction
|
||||
from .services import get_portfolio_value, get_weekly_overview, get_all_holdings, get_performance_chart_data
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -29,11 +29,18 @@ def dashboard(request):
|
||||
group['change_pct'] = row.get('change_pct')
|
||||
group['position_count'] = row.get('position_count', len(group['holdings']))
|
||||
|
||||
recent_transactions = (
|
||||
Transaction.objects
|
||||
.select_related('portfolio')
|
||||
.order_by('-date', '-created_at')[:100]
|
||||
)
|
||||
|
||||
return render(request, 'invest/dashboard.html', {
|
||||
'overview': overview,
|
||||
'fy_label': fy_label,
|
||||
'all_holdings': all_holdings,
|
||||
'chart_data_json': get_performance_chart_data() or 'null',
|
||||
'recent_transactions': recent_transactions,
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -153,6 +153,43 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- ── Transaction history ──────────────────────────────────── -->
|
||||
{% if recent_transactions %}
|
||||
<div class="mt-8">
|
||||
<p class="text-xs font-semibold tracking-widest text-stone-400 uppercase mb-3">Transaction History</p>
|
||||
<div class="bg-white rounded-lg shadow-sm overflow-hidden">
|
||||
<table class="w-full text-sm">
|
||||
<thead>
|
||||
<tr class="text-xs font-semibold tracking-widest text-stone-400 uppercase border-b border-stone-100">
|
||||
<th class="px-6 py-3 text-left">Date</th>
|
||||
<th class="px-6 py-3 text-left">Portfolio</th>
|
||||
<th class="px-6 py-3 text-left">Action</th>
|
||||
<th class="px-6 py-3 text-left">Ticker</th>
|
||||
<th class="px-6 py-3 text-right">Qty</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for tx in recent_transactions %}
|
||||
<tr class="border-b border-stone-50 hover:bg-stone-50">
|
||||
<td class="px-6 py-3 text-stone-500 whitespace-nowrap">{{ tx.date|date:"j M Y" }}</td>
|
||||
<td class="px-6 py-3 text-stone-500">{{ tx.portfolio.name }}</td>
|
||||
<td class="px-6 py-3">
|
||||
{% if tx.action == 'BUY' %}
|
||||
<span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-semibold bg-green-100 text-green-800">BUY</span>
|
||||
{% else %}
|
||||
<span class="inline-flex items-center px-2 py-0.5 rounded text-xs font-semibold bg-red-100 text-red-700">SELL</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td class="px-6 py-3 font-medium text-stone-900">{{ tx.stock_code }}</td>
|
||||
<td class="px-6 py-3 text-right text-stone-500">{{ tx.quantity|floatformat:0 }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block extra_js %}
|
||||
|
||||
Reference in New Issue
Block a user