Quelltext des aktuellen Standes
<?php
$this->layout('layouts/main', [
'page_title' => $page_title,
'current_route' => $current_route,
'full_width' => true,
]);
$t = $stats['totals'] ?? [];
$avg = (float)($stats['avg_duration'] ?? 0);
$topDev = $stats['top_devices'] ?? [];
$topBor = $stats['top_borrowers'] ?? [];
$byMonth = $stats['by_month'] ?? [];
$never = $stats['never_lent'] ?? [];
$invValue = (float)($stats['inventory_value'] ?? 0);
$maxMonth = 0;
foreach ($byMonth as $m) { $maxMonth = max($maxMonth, (int)$m['cnt']); }
$maxDev = 0;
foreach ($topDev as $d) { $maxDev = max($maxDev, (int)$d['cnt']); }
?>
<style>
a { text-decoration: none; }
.lst-grid { display:grid; grid-template-columns:1fr 1fr; gap:1.25rem; align-items:start; }
.lst-bar-row { display:flex; align-items:center; gap:0.75rem; margin-bottom:0.5rem; }
.lst-bar-label { flex:0 0 4.5rem; font-size:0.8rem; color:var(--gray-600); }
.lst-bar-track { flex:1; background:var(--gray-100); border-radius:var(--radius-sm); height:1.1rem; overflow:hidden; }
.lst-bar-fill { height:100%; background:var(--color-primary); border-radius:var(--radius-sm); min-width:2px; }
.lst-bar-val { flex:0 0 2.5rem; text-align:right; font-size:0.8rem; font-weight:600; color:var(--gray-700); }
@media(max-width:900px){ .lst-grid { grid-template-columns:1fr; } }
</style>
<div>
<!-- Content Header -->
<div class="content-header">
<div>
<h1><?= $this->te('Auswertung') ?></h1>
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="/"><?= $this->te('Home') ?></a></li>
<li class="breadcrumb-item"><a href="/loans"><?= $this->te('Leihgeräte') ?></a></li>
<li class="breadcrumb-item active"><?= $this->te('Auswertung') ?></li>
</ol>
</div>
<div class="content-header-actions">
<a href="/loans" class="btn btn-default btn-sm"><i class="fas fa-calendar"></i> <?= $this->te('Kalender') ?></a>
<a href="/loans/lendings" class="btn btn-default btn-sm"><i class="fas fa-list"></i> <?= $this->te('Ausleihen') ?></a>
</div>
</div>
<!-- KPI -->
<div class="page-body" style="padding-bottom:0;">
<div class="kpi-row">
<div class="kpi-col">
<div class="small-box bg-info">
<div class="inner"><h3><?= (int)($t['total'] ?? 0) ?></h3><p><?= $this->te('Ausleihen gesamt') ?></p></div>
<div class="icon"><i class="fas fa-tasks"></i></div>
</div>
</div>
<div class="kpi-col">
<div class="small-box <?= (int)($t['active'] ?? 0) > 0 ? 'bg-warning' : 'bg-secondary' ?>">
<div class="inner"><h3><?= (int)($t['active'] ?? 0) ?></h3><p><?= $this->te('Aktiv ausgeliehen') ?></p></div>
<div class="icon"><i class="fas fa-share-square"></i></div>
</div>
</div>
<div class="kpi-col">
<div class="small-box <?= (int)($t['overdue'] ?? 0) > 0 ? 'bg-danger' : 'bg-secondary' ?>">
<div class="inner"><h3><?= (int)($t['overdue'] ?? 0) ?></h3><p><?= $this->te('Überfällig') ?></p></div>
<div class="icon"><i class="fas fa-exclamation-triangle"></i></div>
</div>
</div>
<div class="kpi-col">
<div class="small-box bg-secondary">
<div class="inner"><h3><?= $avg > 0 ? $this->number($avg, 1) : '–' ?></h3><p><?= $this->te('Ø Leihdauer (Tage)') ?></p></div>
<div class="icon"><i class="fas fa-hourglass-half"></i></div>
</div>
</div>
<?php if ($invValue > 0): ?>
<div class="kpi-col">
<div class="small-box bg-secondary">
<div class="inner"><h3><?= $this->e($this->money($invValue, 0)) ?></h3><p><?= $this->te('Anschaffungswert Bestand') ?></p></div>
<div class="icon"><i class="fas fa-euro-sign"></i></div>
</div>
</div>
<?php endif; ?>
</div>
</div>
<div class="page-body">
<div class="lst-grid">
<!-- Top-Geräte -->
<div class="detail-card">
<div class="detail-card-header"><span class="detail-card-title"><i class="fas fa-laptop"></i> <?= $this->te('Meistgenutzte Geräte') ?></span></div>
<div class="detail-card-body" style="padding:0;">
<?php if (empty($topDev)): ?>
<div class="empty-state" style="padding:1.5rem;"><?= $this->te('Noch keine Ausleihen erfasst.') ?></div>
<?php else: ?>
<div class="table-wrapper">
<table class="data-table">
<thead><tr><th scope="col"><?= $this->te('Gerät') ?></th><th scope="col"><?= $this->te('Typ') ?></th><th scope="col" style="text-align:right;"><?= $this->te('Ausleihen') ?></th></tr></thead>
<tbody>
<?php foreach ($topDev as $d): ?>
<tr>
<td><a class="table-link" href="/loans/devices/<?= (int)$d['id'] ?>"><?= $this->e($d['title']) ?></a></td>
<td><?= $this->e($d['type'] ?? '–') ?></td>
<td style="text-align:right;font-weight:600;"><?= (int)$d['cnt'] ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</div>
</div>
<!-- Häufigste Ausleiher -->
<div class="detail-card">
<div class="detail-card-header"><span class="detail-card-title"><i class="fas fa-users"></i> <?= $this->te('Häufigste Ausleiher') ?></span></div>
<div class="detail-card-body" style="padding:0;">
<?php if (empty($topBor)): ?>
<div class="empty-state" style="padding:1.5rem;"><?= $this->te('Noch keine Ausleihen erfasst.') ?></div>
<?php else: ?>
<div class="table-wrapper">
<table class="data-table">
<thead><tr><th scope="col"><?= $this->te('Ausleiher') ?></th><th scope="col" style="text-align:right;"><?= $this->te('Ausleihen') ?></th></tr></thead>
<tbody>
<?php foreach ($topBor as $b): ?>
<tr>
<td><?= $this->e($b['borrower_name']) ?></td>
<td style="text-align:right;font-weight:600;"><?= (int)$b['cnt'] ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
</div>
</div>
</div>
<!-- Verlauf (12 Monate) -->
<div class="detail-card">
<div class="detail-card-header"><span class="detail-card-title"><i class="fas fa-chart-bar"></i> <?= $this->te('Ausleihen der letzten 12 Monate') ?></span></div>
<div class="detail-card-body">
<?php if (empty($byMonth)): ?>
<div class="empty-state"><?= $this->te('Keine Daten im Zeitraum.') ?></div>
<?php else: ?>
<?php foreach ($byMonth as $m):
$cnt = (int)$m['cnt'];
$pct = $maxMonth > 0 ? round($cnt / $maxMonth * 100) : 0;
$ts = strtotime($m['ym'] . '-01');
?>
<div class="lst-bar-row">
<span class="lst-bar-label"><?= $ts ? date('m/y', $ts) : $this->e($m['ym']) ?></span>
<span class="lst-bar-track"><span class="lst-bar-fill" style="width:<?= $pct ?>%;"></span></span>
<span class="lst-bar-val"><?= $cnt ?></span>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
<!-- Nie ausgeliehen -->
<?php if (!empty($never)): ?>
<div class="detail-card">
<div class="detail-card-header"><span class="detail-card-title"><i class="fas fa-box"></i> Nie ausgeliehene Geräte (<?= count($never) ?>)</span></div>
<div class="detail-card-body">
<div style="display:flex;flex-wrap:wrap;gap:0.4rem;">
<?php foreach ($never as $d): ?>
<a href="/loans/devices/<?= (int)$d['id'] ?>" class="badge" style="text-decoration:none;"><?= $this->e($d['title']) ?></a>
<?php endforeach; ?>
</div>
</div>
</div>
<?php endif; ?>
</div>
</div>