Files
termanager2/app/Livewire/Proclamatori/ProclamatoreShow.php
Francesco Picone 701f479b7f Primo commit
2026-04-05 19:26:04 +02:00

43 lines
1.3 KiB
PHP

<?php
namespace App\Livewire\Proclamatori;
use Livewire\Component;
use App\Models\Proclamatore;
use App\Models\Assegnazione;
class ProclamatoreShow extends Component
{
public Proclamatore $proclamatore;
public function mount(Proclamatore $proclamatore)
{
$this->proclamatore = $proclamatore;
}
public function render()
{
$assegnazioni = Assegnazione::where('proclamatore_id', $this->proclamatore->id)
->with(['territorio', 'annoTeocratico', 'campagna'])
->orderByDesc('assigned_at')
->get()
->groupBy(fn($a) => $a->annoTeocratico->label);
$stats = [
'totale_assegnazioni' => Assegnazione::where('proclamatore_id', $this->proclamatore->id)->count(),
'attualmente_assegnati' => Assegnazione::where('proclamatore_id', $this->proclamatore->id)->aperte()->count(),
'media_giorni' => round(
Assegnazione::where('proclamatore_id', $this->proclamatore->id)
->chiuse()
->get()
->avg(fn($a) => $a->giorni) ?? 0
),
];
return view('livewire.proclamatori.proclamatore-show', [
'assegnazioniPerAnno' => $assegnazioni,
'stats' => $stats,
]);
}
}