feat(superadmin-stabili): add SuperAdmin Sposta Stabile action and fix comproprietari fallback matching for Stabile 0013 (task-d095b0e23b)
This commit is contained in:
parent
cf5b549eff
commit
11e19e882b
|
|
@ -8135,7 +8135,7 @@ private function loadLegacyComproprietariHistoryRows(object $row, ?string $legac
|
|||
return [];
|
||||
}
|
||||
|
||||
$startCondId = $stableCondId !== null && $stableCondId !== '' ? $stableCondId : ($codCond !== '' ? $codCond : null);
|
||||
$startCondId = $stableCondId !== null && $stableCondId !== '' ? $stableCondId : null;
|
||||
$linkedCondIds = [];
|
||||
if ($startCondId !== null) {
|
||||
$linkedCondIds = $this->resolveLinkedLegacyCondIds($codStabile, $startCondId);
|
||||
|
|
|
|||
|
|
@ -197,6 +197,39 @@ public function resetPasswordSelected(): void
|
|||
}
|
||||
}
|
||||
|
||||
public function spostaStabile(int $stabileId, int $nuovoAmministratoreId): void
|
||||
{
|
||||
/** @var User|null $user */
|
||||
$user = Auth::user();
|
||||
if (! $user || ! $user->hasRole('super-admin')) {
|
||||
throw new \RuntimeException('Azione riservata al SuperAdmin.');
|
||||
}
|
||||
|
||||
$stabile = Stabile::query()->find($stabileId);
|
||||
$nuovoAmm = Amministratore::query()->find($nuovoAmministratoreId);
|
||||
|
||||
if (! $stabile || ! $nuovoAmm) {
|
||||
\Filament\Notifications\Notification::make()
|
||||
->title('Errore Trasferimento')
|
||||
->body('Stabile o Amministratore di destinazione non trovato.')
|
||||
->danger()
|
||||
->send();
|
||||
return;
|
||||
}
|
||||
|
||||
$oldAmmId = $stabile->amministratore_id;
|
||||
$stabile->update([
|
||||
'amministratore_id' => $nuovoAmm->id,
|
||||
'cod_fisc_amministratore' => $nuovoAmm->codice_fiscale_studio ?? $nuovoAmm->partita_iva ?? $stabile->cod_fisc_amministratore,
|
||||
]);
|
||||
|
||||
\Filament\Notifications\Notification::make()
|
||||
->title('Stabile Trasferito')
|
||||
->body("Lo stabile '{$stabile->denominazione}' (Cod. {$stabile->codice_stabile}) è stato trasferito con successo dallo Studio #{$oldAmmId} allo Studio #{$nuovoAmm->id} ({$nuovoAmm->denominazione_studio}).")
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
|
||||
protected function getTableQuery(): Builder
|
||||
{
|
||||
return Amministratore::query()->withCount('stabili');
|
||||
|
|
|
|||
|
|
@ -232,20 +232,31 @@ class="inline-flex items-center gap-1 rounded-lg bg-amber-500 px-4 py-2 text-xs
|
|||
<th class="p-2.5">COD.</th>
|
||||
<th class="p-2.5">DENOMINAZIONE STABILE</th>
|
||||
<th class="p-2.5">CODICE FISCALE</th>
|
||||
<th class="p-2.5">STUDIO ASSEGNATO</th>
|
||||
<th class="p-2.5">BANCA PRINCIPALE & IBAN</th>
|
||||
<th class="p-2.5">CASSE (anagr_casse)</th>
|
||||
<th class="p-2.5 text-right">AZIONI SUPERADMIN</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y font-mono">
|
||||
@php
|
||||
$tuttiAmministratori = \App\Models\Amministratore::query()->orderBy('id')->get();
|
||||
@endphp
|
||||
@foreach($stabiliReal as $st)
|
||||
@php
|
||||
$adv = is_array($st->configurazione_avanzata) ? $st->configurazione_avanzata : [];
|
||||
$casse = $adv['conti_correnti']['anagr_casse'] ?? [];
|
||||
$currentAmm = $tuttiAmministratori->firstWhere('id', $st->amministratore_id);
|
||||
@endphp
|
||||
<tr class="hover:bg-slate-50">
|
||||
<td class="p-2.5 font-bold text-slate-900">{{ $st->codice_stabile }}</td>
|
||||
<td class="p-2.5 font-sans font-semibold text-slate-800">{{ $st->denominazione }}</td>
|
||||
<td class="p-2.5 text-slate-700">{{ $st->codice_fiscale ?: '-' }}</td>
|
||||
<td class="p-2.5 font-sans">
|
||||
<span class="inline-flex items-center rounded bg-slate-900 px-2 py-0.5 text-[11px] font-bold text-white">
|
||||
#{{ $st->amministratore_id ?? 'N/A' }} — {{ $currentAmm?->denominazione_studio ?: ($currentAmm?->nome . ' ' . $currentAmm?->cognome ?: 'Studio Non Assegnato') }}
|
||||
</span>
|
||||
</td>
|
||||
<td class="p-2.5 text-slate-700">
|
||||
@if($st->iban_principale)
|
||||
<span class="font-bold text-slate-900">{{ $st->banca_principale ?: 'Banca' }}:</span> {{ $st->iban_principale }}
|
||||
|
|
@ -266,6 +277,19 @@ class="inline-flex items-center gap-1 rounded-lg bg-amber-500 px-4 py-2 text-xs
|
|||
<span class="text-slate-400 text-[11px]">-</span>
|
||||
@endif
|
||||
</td>
|
||||
<td class="p-2.5 font-sans text-right">
|
||||
<select
|
||||
wire:change="spostaStabile({{ $st->id }}, $event.target.value)"
|
||||
class="rounded-md border border-slate-300 bg-amber-50 text-slate-900 font-bold text-xs py-1 px-2 focus:ring-2 focus:ring-amber-500 shadow-xs"
|
||||
>
|
||||
<option value="">🔄 Sposta Stabile a...</option>
|
||||
@foreach($tuttiAmministratori as $ammOption)
|
||||
<option value="{{ $ammOption->id }}" {{ $st->amministratore_id == $ammOption->id ? 'selected' : '' }}>
|
||||
Studio #{{ $ammOption->id }} - {{ $ammOption->denominazione_studio ?: ($ammOption->nome . ' ' . $ammOption->cognome) }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user