Files
finansePRO/app/Views/investments/index.php
T
2026-07-06 20:16:00 +02:00

89 lines
3.9 KiB
PHP

<?= $this->extend('layout/main') ?>
<?= $this->section('content') ?>
<?php $fmt = static fn ($v) => number_format((float) $v, 2, ',', ' ') . ' zł'; ?>
<div class="d-flex justify-content-between align-items-center mb-3 flex-wrap gap-2">
<h1 class="h4 mb-0">Pulpit inwestycji</h1>
<div class="btn-group">
<a href="<?= site_url('investments/operations/new') ?>" class="btn btn-sm btn-outline-primary">+ Wpłata / wypłata</a>
<a href="<?= site_url('investments/valuations/new') ?>" class="btn btn-sm btn-outline-primary">+ Wycena</a>
</div>
</div>
<div class="row g-3 mb-4">
<div class="col-md-4"><div class="card stat-card shadow-sm"><div class="card-body">
<div class="text-muted small">Wpłacono netto</div>
<div class="value"><?= $fmt($net_invested) ?></div>
</div></div></div>
<div class="col-md-4"><div class="card stat-card shadow-sm"><div class="card-body">
<div class="text-muted small">Bieżąca wartość</div>
<div class="value"><?= $fmt($value) ?></div>
</div></div></div>
<div class="col-md-4"><div class="card stat-card shadow-sm"><div class="card-body">
<div class="text-muted small">Zarobek</div>
<div class="value <?= $profit >= 0 ? 'amount-income' : 'amount-expense' ?>"><?= $fmt($profit) ?></div>
</div></div></div>
</div>
<div class="card shadow-sm mb-4"><div class="card-body">
<h2 class="h6">Portfel w czasie</h2>
<div id="chartPortfolio"></div>
</div></div>
<div class="card shadow-sm"><div class="card-body">
<h2 class="h6">Rozbicie na instrumenty</h2>
<div class="table-responsive">
<table class="table table-hover mb-0 align-middle">
<thead class="table-light">
<tr>
<th>Instrument</th>
<th class="text-end">Wpłacono netto</th>
<th class="text-end">Wartość</th>
<th class="text-end">Zarobek</th>
<th class="text-end">% zwrotu</th>
</tr>
</thead>
<tbody>
<?php if (empty($instruments)): ?>
<tr><td colspan="5" class="text-center text-muted py-4">Brak instrumentów.</td></tr>
<?php else: foreach ($instruments as $i): ?>
<tr>
<td><?= esc($i['name']) ?></td>
<td class="text-end"><?= $fmt($i['net_invested']) ?></td>
<td class="text-end"><?= $i['has_value'] ? $fmt($i['value']) : '<span class="text-muted">brak wyceny</span>' ?></td>
<td class="text-end <?= $i['profit'] >= 0 ? 'amount-income' : 'amount-expense' ?>">
<?= $i['has_value'] ? $fmt($i['profit']) : '—' ?>
</td>
<td class="text-end <?= $i['profit'] >= 0 ? 'amount-income' : 'amount-expense' ?>">
<?= $i['percent'] !== null && $i['has_value'] ? number_format($i['percent'], 2, ',', ' ') . '%' : '—' ?>
</td>
</tr>
<?php endforeach; endif; ?>
</tbody>
</table>
</div>
</div></div>
<?= $this->endSection() ?>
<?= $this->section('scripts') ?>
<script>
const timeline = <?= json_encode($timeline, JSON_UNESCAPED_UNICODE) ?>;
new ApexCharts(document.querySelector('#chartPortfolio'), {
chart: { type: 'line', height: 340 },
series: [
{ name: 'Wpłacono netto', data: timeline.map(r => Number(r.net)) },
{ name: 'Wartość', data: timeline.map(r => Number(r.value)) },
{ name: 'Zarobek', data: timeline.map(r => Number(r.profit)) }
],
xaxis: { categories: timeline.map(r => r.date), type: 'category' },
colors: ['#455a64', '#1565c0', '#1a7f37'],
stroke: { curve: 'smooth', width: 2 },
markers: { size: 4 },
dataLabels: { enabled: false },
noData: { text: 'Brak wycen — dodaj wpłaty i wycenę, aby zobaczyć wykres' }
}).render();
</script>
<?= $this->endSection() ?>