# π CARDS STATISTICHE STANDARD
## Template per cards e visualizzazione statistiche
---
## ποΈ **PATTERN 3: CARDS STATISTICHE**
### π― **Utilizzo**: Dashboard e pagine overview moduli
### **Template Base 4 Cards**:
```blade
@section('stats-cards')
{{ $stats['totale'] ?? 0 }}
Totale Items
{{ $stats['attivi'] ?? 0 }}
Attivi
{{ $stats['pending'] ?? 0 }}
In Sospeso
{{ $stats['problemi'] ?? 0 }}
Problemi
@endsection
```
---
## π¨ **COLORI STANDARD CARDS**
### **Color Mapping per Consistency**:
```css
/* AdminLTE Small Box Colors */
.small-box.bg-primary {
background: #007bff !important;
color: #fff;
} /* Totali/Generici */
.small-box.bg-success {
background: #28a745 !important;
color: #fff;
} /* Positivi/Attivi/Successi */
.small-box.bg-warning {
background: #ffc107 !important;
color: #212529;
} /* In Attesa/Sospeso/Warning */
.small-box.bg-danger {
background: #dc3545 !important;
color: #fff;
} /* Errori/Problemi/Critici */
.small-box.bg-info {
background: #17a2b8 !important;
color: #fff;
} /* Info/Neutro/Secondario */
.small-box.bg-secondary {
background: #6c757d !important;
color: #fff;
} /* Disattivi/Archiviati */
```
### **Quando Usare Ogni Colore**:
- **π΅ Primary (blue)**: Contatori totali, numeri generici
- **π’ Success (green)**: Stati positivi, attivi, completati
- **π‘ Warning (yellow)**: In attesa, sospesi, da verificare
- **π΄ Danger (red)**: Errori, problemi, scaduti
- **π΅ Info (cyan)**: Informazioni neutre, statistiche
- **β« Secondary (gray)**: Inattivi, archiviati, disabilitati
---
## π **ESEMPI SPECIFICI PER MODULO**
### **Fornitori**:
```blade
@section('stats-cards')
{{ $stats['totale_fornitori'] ?? 0 }}
Totale Fornitori
{{ $stats['attivi'] ?? 0 }}
Attivi
{{ $stats['questo_mese'] ?? 0 }}
Nuovi Questo Mese
{{ $stats['fatture_pending'] ?? 0 }}
Fatture in Attesa
@endsection
```
### **Gestioni**:
```blade
@section('stats-cards')
{{ $stats['totale_gestioni'] ?? 0 }}
Totale Gestioni
{{ $stats['aperte'] ?? 0 }}
Gestioni Aperte
{{ $stats['da_chiudere'] ?? 0 }}
Da Chiudere
{{ $stats['archiviate'] ?? 0 }}
Archiviate
@endsection
```
---
## π± **RESPONSIVE DESIGN**
### **Template Mobile-Friendly**:
```blade
@section('stats-cards')
{{ $stats['totale'] ?? 0 }}
Totale Items
Totale
@endsection
```
### **CSS Responsive per Cards**:
```css
/* Responsive adjustments */
@media (max-width: 576px) {
.small-box h3 {
font-size: 1.5rem; /* PiΓΉ piccolo su mobile */
}
.small-box p {
font-size: 0.875rem;
margin-bottom: 0;
}
.small-box .icon {
font-size: 2rem; /* Icona piΓΉ piccola */
bottom: 5px;
right: 5px;
}
}
@media (max-width: 768px) {
.small-box {
margin-bottom: 1rem; /* PiΓΉ spazio tra cards */
}
}
```
---
## π’ **FORMATTAZIONE NUMERI**
### **Helper per Formattazione**:
```php
// In Controller - formatHelper per stats
private function formatStats($stats) {
return [
'totale' => number_format($stats['totale'], 0, ',', '.'),
'attivi' => number_format($stats['attivi'], 0, ',', '.'),
'importo' => 'β¬ ' . number_format($stats['importo'], 2, ',', '.'),
'percentuale' => number_format($stats['percentuale'], 1) . '%'
];
}
```
### **Template con Formattazione**:
```blade
@if(isset($stats['importo']))
β¬ {{ number_format($stats['importo'], 0, ',', '.') }}
@else
{{ number_format($stats['attivi'] ?? 0, 0, ',', '.') }}
@endif
Fatturato Attivo
```
---
## π― **CARDS CLICKABILI**
### **Template Card con Link**:
```blade
```
### **CSS per Links**:
```css
.small-box-link {
color: inherit;
text-decoration: none;
}
.small-box-link:hover {
color: inherit;
text-decoration: none;
}
.small-box-link:hover .small-box {
transform: translateY(-2px);
box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}
.small-box-footer {
background: rgba(0,0,0,0.1);
color: rgba(255,255,255,0.8);
display: block;
padding: 3px 0;
text-align: center;
text-decoration: none;
font-size: 12px;
}
```
---
## π **CARDS ADVANCED**
### **Card con Progress Bar**:
```blade
{{ $stats['completamento'] ?? 0 }}%
Completamento
```
### **Card con Badge**:
```blade
{{ $stats['pending'] ?? 0 }}
@if(($stats['pending'] ?? 0) > 10)
!
@endif
In Sospeso
```
---
## π **IMPLEMENTAZIONE VELOCE**
### **Steps per Cards**:
1. **Copia template** base 4 cards
2. **Personalizza labels** e icone per il modulo
3. **Configura colors** appropriati
4. **Implementa stats** nel controller
5. **Testa responsive** design
6. **Aggiungi links** se necessario
### **Controller Stats Method**:
```php
private function calculateStats()
{
return [
'totale' => Model::count(),
'attivi' => Model::where('stato', 'attivo')->count(),
'pending' => Model::where('stato', 'pending')->count(),
'questo_mese' => Model::whereMonth('created_at', now()->month)->count(),
];
}
```
---
**π Prossimo file: `04-controller-standard.md`**