Compare commits
2 Commits
554212fd0b
...
7dd54f3a6f
| Author | SHA1 | Date | |
|---|---|---|---|
| 7dd54f3a6f | |||
| d95fba5740 |
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
|
|
@ -138,4 +137,4 @@ private function writeProgress(int $percent, string $message, string $status, ?i
|
|||
'exit_code' => $exitCode,
|
||||
], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,9 @@
|
|||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use UnitEnum;
|
||||
|
||||
class LettureServiziArchivio extends Page implements HasTable
|
||||
|
|
@ -37,9 +39,9 @@ class LettureServiziArchivio extends Page implements HasTable
|
|||
public ?int $servizioFilter = null;
|
||||
public string $archivioScope = 'active';
|
||||
|
||||
protected static ?string $navigationLabel = 'Letture servizi';
|
||||
protected static ?string $navigationLabel = 'Letture servizi / contatori';
|
||||
|
||||
protected static ?string $title = 'Letture servizi';
|
||||
protected static ?string $title = 'Letture servizi / contatori';
|
||||
|
||||
protected static BackedEnum|string|null $navigationIcon = 'heroicon-o-clipboard-document-list';
|
||||
|
||||
|
|
@ -127,7 +129,7 @@ protected function getTableQuery(): Builder
|
|||
->when($this->servizioFilter, fn(Builder $q) => $q->where('stabile_servizio_id', (int) $this->servizioFilter))
|
||||
->with([
|
||||
'stabile:id,codice_stabile,denominazione',
|
||||
'servizio:id,stabile_id,tipo,nome,contatore_matricola',
|
||||
'servizio:id,stabile_id,tipo,nome,contatore_matricola,meta',
|
||||
'fornitore:id,ragione_sociale',
|
||||
'voceSpesa:id,descrizione,tipo_gestione',
|
||||
'unitaImmobiliare:id,codice_unita,denominazione,interno,scala,piano',
|
||||
|
|
@ -168,6 +170,11 @@ public function table(Table $table): Table
|
|||
'assicurazione' => 'Assicurazione',
|
||||
'privacy' => 'Privacy',
|
||||
'antenna' => 'Antenna',
|
||||
'antincendio' => 'Antincendio',
|
||||
'citofonia' => 'Citofonia',
|
||||
'locale_comune' => 'Locale comune',
|
||||
'spazio_comune' => 'Spazio / area comune',
|
||||
'impianto' => 'Impianto comune',
|
||||
'altro' => 'Altro',
|
||||
])
|
||||
->query(function (Builder $query, array $data): Builder {
|
||||
|
|
@ -241,24 +248,19 @@ public function table(Table $table): Table
|
|||
TextColumn::make('servizio.contatore_matricola')->label('Matricola')->toggleable(isToggledHiddenByDefault: true),
|
||||
|
||||
TextColumn::make('unitaImmobiliare.denominazione')
|
||||
->label('Unità immobiliare')
|
||||
->label('Attribuzione')
|
||||
->formatStateUsing(function ($state, StabileServizioLettura $record): string {
|
||||
$ui = $record->unitaImmobiliare;
|
||||
if (! $ui) {
|
||||
return '—';
|
||||
}
|
||||
|
||||
$cod = trim((string) ($ui->codice_unita ?? ''));
|
||||
$den = trim((string) ($ui->denominazione ?? ''));
|
||||
if ($cod !== '' && $den !== '') {
|
||||
return $cod . ' - ' . $den;
|
||||
}
|
||||
|
||||
return $cod !== '' ? $cod : ($den !== '' ? $den : ('UI #' . $ui->id));
|
||||
return $this->resolveReadingAssignmentLabel($record);
|
||||
})
|
||||
->wrap()
|
||||
->toggleable(),
|
||||
|
||||
TextColumn::make('rilevatore_nome')
|
||||
->label('Letturista / nominativo')
|
||||
->formatStateUsing(fn($state): string => trim((string) $state) !== '' ? trim((string) $state) : '—')
|
||||
->wrap()
|
||||
->toggleable(),
|
||||
|
||||
TextColumn::make('consumo_valore')
|
||||
->label('Consumo')
|
||||
->formatStateUsing(function ($state, StabileServizioLettura $record): string {
|
||||
|
|
@ -301,6 +303,35 @@ public function table(Table $table): Table
|
|||
->badge()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
|
||||
TextColumn::make('raw.consistency_check.summary')
|
||||
->label('Check lettura')
|
||||
->formatStateUsing(function ($state, StabileServizioLettura $record): string {
|
||||
$summary = trim((string) data_get($record->raw, 'consistency_check.summary', ''));
|
||||
return $summary !== '' ? $summary : '—';
|
||||
})
|
||||
->badge()
|
||||
->color(function ($state, StabileServizioLettura $record): string {
|
||||
return match ((string) data_get($record->raw, 'consistency_check.status', '')) {
|
||||
'warning' => 'warning',
|
||||
'danger' => 'danger',
|
||||
default => 'gray',
|
||||
};
|
||||
})
|
||||
->wrap()
|
||||
->toggleable(),
|
||||
|
||||
TextColumn::make('lettura_foto_original_name')
|
||||
->label('Foto')
|
||||
->formatStateUsing(function ($state, StabileServizioLettura $record): string {
|
||||
$photos = is_array(data_get($record->lettura_foto_metadata, 'photos')) ? data_get($record->lettura_foto_metadata, 'photos') : [];
|
||||
if ($photos !== []) {
|
||||
return count($photos) . ' foto';
|
||||
}
|
||||
|
||||
return filled($record->lettura_foto_path) ? '1 foto' : '—';
|
||||
})
|
||||
->toggleable(),
|
||||
|
||||
TextColumn::make('protocollo_numero')
|
||||
->label('Protocollo')
|
||||
->formatStateUsing(function ($state, StabileServizioLettura $record): string {
|
||||
|
|
@ -528,6 +559,78 @@ public function table(Table $table): Table
|
|||
}),
|
||||
])
|
||||
->actions([
|
||||
Action::make('apriFoto')
|
||||
->label('Foto')
|
||||
->icon('heroicon-o-photo')
|
||||
->url(fn(StabileServizioLettura $record): ?string => $this->resolveReadingPrimaryPhotoUrl($record))
|
||||
->openUrlInNewTab()
|
||||
->visible(fn(StabileServizioLettura $record): bool => $this->resolveReadingPrimaryPhotoUrl($record) !== null),
|
||||
|
||||
Action::make('mappaFoto')
|
||||
->label('Mappa')
|
||||
->icon('heroicon-o-map')
|
||||
->url(fn(StabileServizioLettura $record): ?string => $this->resolveReadingMapUrl($record))
|
||||
->openUrlInNewTab()
|
||||
->visible(fn(StabileServizioLettura $record): bool => $this->resolveReadingMapUrl($record) !== null),
|
||||
|
||||
Action::make('riattribuisci')
|
||||
->label('Riattribuisci')
|
||||
->icon('heroicon-o-user-circle')
|
||||
->form([
|
||||
Select::make('unita_immobiliare_id')
|
||||
->label('Unità / nominativo')
|
||||
->options(fn() => $this->getUnitaOptions())
|
||||
->searchable()
|
||||
->placeholder('Contatore generale / bene comune dello stabile'),
|
||||
Select::make('rilevatore_tipo')
|
||||
->label('Tipo rilevatore')
|
||||
->options($this->getReaderTypeOptions()),
|
||||
TextInput::make('rilevatore_nome')->label('Nominativo rilevatore')->maxLength(191),
|
||||
Textarea::make('motivo')->label('Nota riassegnazione')->rows(3)->maxLength(1000),
|
||||
])
|
||||
->fillForm(fn(StabileServizioLettura $record): array => [
|
||||
'unita_immobiliare_id' => $record->unita_immobiliare_id,
|
||||
'rilevatore_tipo' => (string) ($record->rilevatore_tipo ?? ''),
|
||||
'rilevatore_nome' => (string) ($record->rilevatore_nome ?? ''),
|
||||
'motivo' => '',
|
||||
])
|
||||
->action(function (StabileServizioLettura $record, array $data): void {
|
||||
$raw = is_array($record->raw ?? null) ? $record->raw : [];
|
||||
$reassignments = is_array($raw['reassignments'] ?? null) ? $raw['reassignments'] : [];
|
||||
$reassignments[] = [
|
||||
'from_unita_immobiliare_id' => (int) ($record->getOriginal('unita_immobiliare_id') ?? 0) ?: null,
|
||||
'to_unita_immobiliare_id' => (int) ($data['unita_immobiliare_id'] ?? 0) ?: null,
|
||||
'from_reader_name' => (string) ($record->getOriginal('rilevatore_nome') ?? ''),
|
||||
'to_reader_name' => trim((string) ($data['rilevatore_nome'] ?? '')),
|
||||
'note' => trim((string) ($data['motivo'] ?? '')),
|
||||
'changed_by' => Auth::id(),
|
||||
'changed_at' => now()->toIso8601String(),
|
||||
];
|
||||
$raw['reassignments'] = $reassignments;
|
||||
$raw['reader_assignment'] = [
|
||||
'user_id' => null,
|
||||
'name' => trim((string) ($data['rilevatore_nome'] ?? '')) ?: null,
|
||||
'type' => trim((string) ($data['rilevatore_tipo'] ?? '')) ?: null,
|
||||
];
|
||||
|
||||
$record->fill([
|
||||
'unita_immobiliare_id' => (int) ($data['unita_immobiliare_id'] ?? 0) ?: null,
|
||||
'rilevatore_tipo' => trim((string) ($data['rilevatore_tipo'] ?? '')) ?: null,
|
||||
'rilevatore_nome' => trim((string) ($data['rilevatore_nome'] ?? '')) ?: null,
|
||||
'lettura_precedente_valore' => null,
|
||||
'lettura_precedente_foto_path' => null,
|
||||
'raw' => $raw,
|
||||
]);
|
||||
$record->save();
|
||||
$this->hydrateReadingWithPreviousData($record);
|
||||
|
||||
Notification::make()
|
||||
->title('Attribuzione aggiornata')
|
||||
->body('La lettura è stata riallineata al nuovo nominativo/unità.')
|
||||
->success()
|
||||
->send();
|
||||
}),
|
||||
|
||||
Action::make('edit')
|
||||
->label('Modifica')
|
||||
->icon('heroicon-o-pencil-square')
|
||||
|
|
@ -675,13 +778,17 @@ private function getServiziOptions(): array
|
|||
->where('stabile_id', (int) $stabileId)
|
||||
->orderBy('tipo')
|
||||
->orderBy('nome')
|
||||
->get(['id', 'tipo', 'nome', 'contatore_matricola'])
|
||||
->get(['id', 'tipo', 'nome', 'contatore_matricola', 'meta'])
|
||||
->mapWithKeys(function (StabileServizio $s): array {
|
||||
$tipo = strtoupper(trim((string) ($s->tipo ?? '')));
|
||||
$nome = trim((string) ($s->nome ?? ''));
|
||||
$matr = trim((string) ($s->contatore_matricola ?? ''));
|
||||
$asset = trim((string) data_get($s->meta, 'common_asset_label', ''));
|
||||
|
||||
$label = $nome !== '' ? $nome : ($tipo !== '' ? $tipo : ('Servizio #' . $s->id));
|
||||
if ($asset !== '' && ! str_contains(mb_strtolower($label), mb_strtolower($asset))) {
|
||||
$label .= ' - ' . $asset;
|
||||
}
|
||||
if ($matr !== '') {
|
||||
$label .= ' (' . $matr . ')';
|
||||
}
|
||||
|
|
@ -782,16 +889,36 @@ private function getUnitaOptions(): array
|
|||
return [];
|
||||
}
|
||||
|
||||
return UnitaImmobiliare::query()
|
||||
$units = UnitaImmobiliare::query()
|
||||
->where('stabile_id', (int) $stabileId)
|
||||
->orderBy('codice_unita')
|
||||
->orderBy('interno')
|
||||
->orderBy('id')
|
||||
->get(['id', 'codice_unita', 'denominazione', 'interno'])
|
||||
->mapWithKeys(function (UnitaImmobiliare $u): array {
|
||||
->all();
|
||||
|
||||
$latestNominativi = [];
|
||||
if ($units !== [] && Schema::hasTable('unita_immobiliare_nominativi')) {
|
||||
$rows = DB::table('unita_immobiliare_nominativi')
|
||||
->whereIn('unita_immobiliare_id', array_map(fn(UnitaImmobiliare $unit): int => (int) $unit->id, $units))
|
||||
->orderByDesc('updated_at')
|
||||
->orderByDesc('id')
|
||||
->get(['unita_immobiliare_id', 'nominativo']);
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$unitId = (int) ($row->unita_immobiliare_id ?? 0);
|
||||
if ($unitId > 0 && ! isset($latestNominativi[$unitId])) {
|
||||
$latestNominativi[$unitId] = trim((string) ($row->nominativo ?? ''));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$options = collect($units)
|
||||
->mapWithKeys(function (UnitaImmobiliare $u) use ($latestNominativi): array {
|
||||
$cod = trim((string) ($u->codice_unita ?? ''));
|
||||
$den = trim((string) ($u->denominazione ?? ''));
|
||||
$int = trim((string) ($u->interno ?? ''));
|
||||
$nom = trim((string) ($latestNominativi[(int) $u->id] ?? ''));
|
||||
|
||||
$label = $cod !== '' ? $cod : ('UI #' . $u->id);
|
||||
if ($den !== '') {
|
||||
|
|
@ -800,10 +927,33 @@ private function getUnitaOptions(): array
|
|||
if ($int !== '') {
|
||||
$label .= ' (Int. ' . $int . ')';
|
||||
}
|
||||
if ($nom !== '') {
|
||||
$label .= ' · ' . $nom;
|
||||
}
|
||||
|
||||
return [(int) $u->id => $label];
|
||||
})
|
||||
->all();
|
||||
|
||||
uasort($options, static fn(string $left, string $right): int => strnatcasecmp($left, $right));
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function getReaderTypeOptions(): array
|
||||
{
|
||||
return [
|
||||
'condomino' => 'Condomino',
|
||||
'inquilino' => 'Inquilino',
|
||||
'letturista' => 'Letturista',
|
||||
'collaboratore' => 'Collaboratore',
|
||||
'amministrazione' => 'Amministrazione',
|
||||
'operatore_filament' => 'Operatore Filament',
|
||||
'link_pubblico' => 'Link pubblico',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -921,13 +1071,13 @@ private function markOverdueWaterReminders(): int
|
|||
|
||||
private function hydrateReadingWithPreviousData(StabileServizioLettura $record): void
|
||||
{
|
||||
if ($record->unita_immobiliare_id === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$previous = StabileServizioLettura::query()
|
||||
->where('stabile_servizio_id', (int) $record->stabile_servizio_id)
|
||||
->where('unita_immobiliare_id', (int) $record->unita_immobiliare_id)
|
||||
->when(
|
||||
$record->unita_immobiliare_id === null,
|
||||
fn(Builder $query) => $query->whereNull('unita_immobiliare_id'),
|
||||
fn(Builder $query) => $query->where('unita_immobiliare_id', (int) $record->unita_immobiliare_id)
|
||||
)
|
||||
->where('id', '!=', (int) $record->id)
|
||||
->latest('periodo_al')
|
||||
->latest('id')
|
||||
|
|
@ -1045,4 +1195,76 @@ private function extractImageMetadata(string $path): array
|
|||
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
private function resolveReadingAssignmentLabel(StabileServizioLettura $record): string
|
||||
{
|
||||
$ui = $record->unitaImmobiliare;
|
||||
if ($ui instanceof UnitaImmobiliare) {
|
||||
$cod = trim((string) ($ui->codice_unita ?? ''));
|
||||
$den = trim((string) ($ui->denominazione ?? ''));
|
||||
|
||||
return trim(($cod !== '' ? $cod : ('UI #' . $ui->id)) . ($den !== '' ? (' - ' . $den) : ''));
|
||||
}
|
||||
|
||||
$commonAsset = trim((string) data_get($record->servizio?->meta, 'common_asset_label', ''));
|
||||
$servedArea = trim((string) data_get($record->servizio?->meta, 'served_area_label', ''));
|
||||
$counterType = trim((string) data_get($record->servizio?->meta, 'counter_scope', ''));
|
||||
|
||||
$parts = array_filter([
|
||||
$commonAsset,
|
||||
$servedArea,
|
||||
$counterType !== '' ? 'Contatore ' . $counterType : null,
|
||||
]);
|
||||
|
||||
return $parts !== [] ? implode(' - ', $parts) : 'Contatore generale / bene comune';
|
||||
}
|
||||
|
||||
private function resolveReadingPrimaryPhotoPath(StabileServizioLettura $record): ?string
|
||||
{
|
||||
if (filled($record->lettura_foto_path)) {
|
||||
return (string) $record->lettura_foto_path;
|
||||
}
|
||||
|
||||
$photos = is_array(data_get($record->lettura_foto_metadata, 'photos')) ? data_get($record->lettura_foto_metadata, 'photos') : [];
|
||||
foreach ($photos as $photo) {
|
||||
$path = trim((string) ($photo['path'] ?? ''));
|
||||
if ($path !== '') {
|
||||
return $path;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function resolveReadingPrimaryPhotoUrl(StabileServizioLettura $record): ?string
|
||||
{
|
||||
$path = $this->resolveReadingPrimaryPhotoPath($record);
|
||||
if ($path === null || ! Storage::disk('public')->exists($path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Storage::disk('public')->url($path);
|
||||
}
|
||||
|
||||
private function resolveReadingMapUrl(StabileServizioLettura $record): ?string
|
||||
{
|
||||
$lat = data_get($record->lettura_foto_metadata, 'gps_decimal.lat');
|
||||
$lng = data_get($record->lettura_foto_metadata, 'gps_decimal.lng');
|
||||
|
||||
if (is_numeric($lat) && is_numeric($lng)) {
|
||||
return 'https://maps.google.com/?q=' . $lat . ',' . $lng;
|
||||
}
|
||||
|
||||
$photos = is_array(data_get($record->lettura_foto_metadata, 'photos')) ? data_get($record->lettura_foto_metadata, 'photos') : [];
|
||||
foreach ($photos as $photo) {
|
||||
$gpsLat = data_get($photo, 'metadata.gps_decimal.lat');
|
||||
$gpsLng = data_get($photo, 'metadata.gps_decimal.lng');
|
||||
|
||||
if (is_numeric($gpsLat) && is_numeric($gpsLng)) {
|
||||
return 'https://maps.google.com/?q=' . $gpsLat . ',' . $gpsLng;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -883,7 +883,7 @@ public function table(Table $table): Table
|
|||
|
||||
return RubricaUniversaleScheda::getUrl(['record' => $rubricaId], panel: 'admin-filament');
|
||||
}, shouldOpenInNewTab: true)
|
||||
->visible(fn($record): bool => (bool) $this->resolveRubricaIdForRow($record)),
|
||||
]);
|
||||
->visible(fn($record): bool => (bool) $this->resolveRubricaIdForRow($record)),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
use BackedEnum;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Notifications\Notification;
|
||||
|
|
@ -35,9 +36,9 @@ class ServiziStabileArchivio extends Page implements HasTable
|
|||
{
|
||||
use InteractsWithTable;
|
||||
|
||||
protected static ?string $navigationLabel = 'Servizi / Utenze';
|
||||
protected static ?string $navigationLabel = 'Servizi / Beni comuni';
|
||||
|
||||
protected static ?string $title = 'Servizi / Utenze';
|
||||
protected static ?string $title = 'Servizi / Beni comuni';
|
||||
|
||||
protected static BackedEnum|string|null $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
|
|
@ -94,7 +95,7 @@ public function prepareAcquaReadingCampaign(): void
|
|||
return;
|
||||
}
|
||||
|
||||
$year = $this->resolveActiveAnnoGestione();
|
||||
$year = $this->resolveActiveAnnoGestione();
|
||||
$created = 0;
|
||||
$updated = 0;
|
||||
|
||||
|
|
@ -130,7 +131,7 @@ public function prepareAcquaReadingCampaign(): void
|
|||
->first();
|
||||
|
||||
$requestReference = 'PUBREQ:' . (int) $servizio->id . ':' . (int) $unit->id . ':' . $year;
|
||||
$requestPayload = [
|
||||
$requestPayload = [
|
||||
'stabile_id' => $stabileId,
|
||||
'stabile_servizio_id' => (int) $servizio->id,
|
||||
'unita_immobiliare_id' => (int) $unit->id,
|
||||
|
|
@ -146,8 +147,8 @@ public function prepareAcquaReadingCampaign(): void
|
|||
'lettura_precedente_valore' => $previous?->lettura_fine,
|
||||
'lettura_inizio' => $previous?->lettura_fine,
|
||||
'raw' => [
|
||||
'source' => 'campagna_letture_acqua',
|
||||
'year' => $year,
|
||||
'source' => 'campagna_letture_acqua',
|
||||
'year' => $year,
|
||||
'unit_label' => trim((string) ($unit->codice_unita ?? '') . ' ' . (string) ($unit->interno ?? '')),
|
||||
],
|
||||
];
|
||||
|
|
@ -179,7 +180,7 @@ public function markAcquaReadingReminder(int $readingId): void
|
|||
|
||||
$reading->fill([
|
||||
'sollecito_inviato_at' => now(),
|
||||
'workflow_stato' => 'sollecito_inviato',
|
||||
'workflow_stato' => 'sollecito_inviato',
|
||||
]);
|
||||
$reading->save();
|
||||
|
||||
|
|
@ -268,18 +269,11 @@ protected function getTableQuery(): Builder
|
|||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
$tipoOptions = [
|
||||
'acqua' => 'Acqua',
|
||||
'energia' => 'Energia',
|
||||
'gas' => 'Gas',
|
||||
'riscaldamento' => 'Riscaldamento',
|
||||
'ascensore' => 'Ascensore',
|
||||
'pulizie' => 'Pulizie',
|
||||
'assicurazione' => 'Assicurazione',
|
||||
'privacy' => 'Privacy',
|
||||
'antenna' => 'Antenna',
|
||||
'altro' => 'Altro',
|
||||
];
|
||||
$tipoOptions = $this->getServiceTypeOptions();
|
||||
$commonScopeOptions = $this->getCommonAssetScopeOptions();
|
||||
$allocationOptions = $this->getAllocationScopeOptions();
|
||||
$fiscalScopeOptions = $this->getFiscalScopeOptions();
|
||||
$counterScopeOptions = $this->getCounterScopeOptions();
|
||||
|
||||
$gestioneOptions = [
|
||||
'ordinaria' => 'Ordinaria',
|
||||
|
|
@ -294,6 +288,30 @@ public function table(Table $table): Table
|
|||
->label('Tipo servizio')
|
||||
->options($tipoOptions),
|
||||
|
||||
SelectFilter::make('common_asset_scope')
|
||||
->label('Ambito bene comune')
|
||||
->options($commonScopeOptions)
|
||||
->query(function (Builder $query, array $data): Builder {
|
||||
$value = trim((string) ($data['value'] ?? ''));
|
||||
if ($value === '') {
|
||||
return $query;
|
||||
}
|
||||
|
||||
return $query->where('meta->common_asset_scope', $value);
|
||||
}),
|
||||
|
||||
SelectFilter::make('counter_scope')
|
||||
->label('Tipo contatore')
|
||||
->options($counterScopeOptions)
|
||||
->query(function (Builder $query, array $data): Builder {
|
||||
$value = trim((string) ($data['value'] ?? ''));
|
||||
if ($value === '') {
|
||||
return $query;
|
||||
}
|
||||
|
||||
return $query->where('meta->counter_scope', $value);
|
||||
}),
|
||||
|
||||
SelectFilter::make('tipo_gestione')
|
||||
->label('Gestione (O/R/S)')
|
||||
->options($gestioneOptions)
|
||||
|
|
@ -309,11 +327,35 @@ public function table(Table $table): Table
|
|||
->columns([
|
||||
TextColumn::make('tipo')
|
||||
->label('Tipo')
|
||||
->formatStateUsing(fn($state) => $tipoOptions[strtolower(trim((string) $state))] ?? (string) ($state ?? '—'))
|
||||
->formatStateUsing(fn($state) => $this->formatMetaOptionLabel($tipoOptions, $state))
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('nome')->label('Nome')->searchable()->wrap()->sortable(),
|
||||
|
||||
TextColumn::make('meta.common_asset_label')
|
||||
->label('Bene / locale')
|
||||
->formatStateUsing(fn($state): string => trim((string) $state) !== '' ? trim((string) $state) : '—')
|
||||
->searchable()
|
||||
->wrap()
|
||||
->toggleable(),
|
||||
|
||||
TextColumn::make('meta.common_asset_scope')
|
||||
->label('Ambito')
|
||||
->formatStateUsing(fn($state) => $this->formatMetaOptionLabel($commonScopeOptions, $state))
|
||||
->toggleable(),
|
||||
|
||||
TextColumn::make('meta.allocation_scope')
|
||||
->label('Addebito')
|
||||
->formatStateUsing(fn($state) => $this->formatMetaOptionLabel($allocationOptions, $state))
|
||||
->wrap()
|
||||
->toggleable(),
|
||||
|
||||
TextColumn::make('meta.fiscal_scope')
|
||||
->label('Trattamento')
|
||||
->formatStateUsing(fn($state) => $this->formatMetaOptionLabel($fiscalScopeOptions, $state))
|
||||
->wrap()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
|
||||
TextColumn::make('fornitore.ragione_sociale')->label('Fornitore')->searchable()->wrap()->toggleable(),
|
||||
|
||||
TextColumn::make('voceSpesa.descrizione')->label('Voce spesa')->searchable()->wrap()->toggleable(),
|
||||
|
|
@ -350,6 +392,21 @@ public function table(Table $table): Table
|
|||
TextColumn::make('codice_contratto')->label('Contratto')->searchable()->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('contatore_matricola')->label('Matricola')->searchable()->toggleable(),
|
||||
|
||||
TextColumn::make('meta.counter_scope')
|
||||
->label('Contatore')
|
||||
->formatStateUsing(fn($state) => $this->formatMetaOptionLabel($counterScopeOptions, $state))
|
||||
->toggleable(),
|
||||
|
||||
IconColumn::make('meta.has_dedicated_meter')
|
||||
->label('Ded.')
|
||||
->boolean()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
|
||||
TextColumn::make('meta.served_area_label')
|
||||
->label('Area servita')
|
||||
->wrap()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
|
||||
IconColumn::make('attivo')->label('Attivo')->boolean()->sortable(),
|
||||
TextColumn::make('updated_at')->label('Aggiornato')->dateTime('d/m/Y H:i')->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
|
|
@ -363,6 +420,16 @@ public function table(Table $table): Table
|
|||
->options($tipoOptions)
|
||||
->required(),
|
||||
TextInput::make('nome')->label('Nome')->maxLength(255),
|
||||
TextInput::make('common_asset_label')->label('Bene comune / locale / servizio')->maxLength(255),
|
||||
Select::make('common_asset_scope')
|
||||
->label('Ambito bene comune')
|
||||
->options($commonScopeOptions),
|
||||
Select::make('allocation_scope')
|
||||
->label('Ripartizione / addebito')
|
||||
->options($allocationOptions),
|
||||
Select::make('fiscal_scope')
|
||||
->label('Trattamento economico / fiscale')
|
||||
->options($fiscalScopeOptions),
|
||||
Select::make('fornitore_id')
|
||||
->label('Fornitore')
|
||||
->searchable()
|
||||
|
|
@ -375,6 +442,12 @@ public function table(Table $table): Table
|
|||
TextInput::make('codice_cliente')->label('Codice cliente')->maxLength(255),
|
||||
TextInput::make('codice_contratto')->label('Codice contratto')->maxLength(255),
|
||||
TextInput::make('contatore_matricola')->label('Matricola contatore')->maxLength(255),
|
||||
Toggle::make('has_dedicated_meter')->label('Contatore dedicato')->default(false),
|
||||
Select::make('counter_scope')
|
||||
->label('Tipo contatore')
|
||||
->options($counterScopeOptions)
|
||||
->default('assente'),
|
||||
TextInput::make('served_area_label')->label('Area servita / utilizzo')->maxLength(255),
|
||||
Select::make('canale_acquisizione')
|
||||
->label('Canale acquisizione letture')
|
||||
->options([
|
||||
|
|
@ -389,6 +462,7 @@ public function table(Table $table): Table
|
|||
TextInput::make('costo_lettura_unitario')->label('Costo lettura (unitario)')->numeric(),
|
||||
TextInput::make('costo_ripartizione')->label('Costo ripartizione')->numeric(),
|
||||
Toggle::make('ripartizione_esterna')->label('Ripartizione affidata a ditta esterna')->default(false),
|
||||
Textarea::make('operative_notes')->label('Note operative')->rows(3)->maxLength(2000),
|
||||
Toggle::make('attivo')->label('Attivo')->default(true),
|
||||
])
|
||||
->action(function (array $data): void {
|
||||
|
|
@ -405,7 +479,7 @@ public function table(Table $table): Table
|
|||
StabileServizio::query()->create([
|
||||
'stabile_id' => (int) $stabileId,
|
||||
'tipo' => strtolower(trim((string) ($data['tipo'] ?? ''))),
|
||||
'nome' => trim((string) ($data['nome'] ?? '')),
|
||||
'nome' => $this->resolveServiceDisplayName($data),
|
||||
'fornitore_id' => (int) ($data['fornitore_id'] ?? 0) ?: null,
|
||||
'voce_spesa_id' => (int) ($data['voce_spesa_id'] ?? 0) ?: null,
|
||||
'codice_utenza' => trim((string) ($data['codice_utenza'] ?? '')) ?: null,
|
||||
|
|
@ -413,14 +487,7 @@ public function table(Table $table): Table
|
|||
'codice_contratto' => trim((string) ($data['codice_contratto'] ?? '')) ?: null,
|
||||
'contatore_matricola' => trim((string) ($data['contatore_matricola'] ?? '')) ?: null,
|
||||
'attivo' => (bool) ($data['attivo'] ?? true),
|
||||
'meta' => [
|
||||
'canale_acquisizione' => trim((string) ($data['canale_acquisizione'] ?? '')) ?: null,
|
||||
'email_raccolta_letture' => trim((string) ($data['email_raccolta_letture'] ?? '')) ?: null,
|
||||
'whatsapp_raccolta_letture' => trim((string) ($data['whatsapp_raccolta_letture'] ?? '')) ?: null,
|
||||
'costo_lettura_unitario' => is_numeric($data['costo_lettura_unitario'] ?? null) ? (float) $data['costo_lettura_unitario'] : null,
|
||||
'costo_ripartizione' => is_numeric($data['costo_ripartizione'] ?? null) ? (float) $data['costo_ripartizione'] : null,
|
||||
'ripartizione_esterna' => (bool) ($data['ripartizione_esterna'] ?? false),
|
||||
],
|
||||
'meta' => $this->buildServiceMetaPayload([], $data),
|
||||
]);
|
||||
}),
|
||||
])
|
||||
|
|
@ -444,6 +511,16 @@ public function table(Table $table): Table
|
|||
->options($tipoOptions)
|
||||
->required(),
|
||||
TextInput::make('nome')->label('Nome')->maxLength(255),
|
||||
TextInput::make('common_asset_label')->label('Bene comune / locale / servizio')->maxLength(255),
|
||||
Select::make('common_asset_scope')
|
||||
->label('Ambito bene comune')
|
||||
->options($commonScopeOptions),
|
||||
Select::make('allocation_scope')
|
||||
->label('Ripartizione / addebito')
|
||||
->options($allocationOptions),
|
||||
Select::make('fiscal_scope')
|
||||
->label('Trattamento economico / fiscale')
|
||||
->options($fiscalScopeOptions),
|
||||
Select::make('fornitore_id')
|
||||
->label('Fornitore')
|
||||
->searchable()
|
||||
|
|
@ -456,6 +533,11 @@ public function table(Table $table): Table
|
|||
TextInput::make('codice_cliente')->label('Codice cliente')->maxLength(255),
|
||||
TextInput::make('codice_contratto')->label('Codice contratto')->maxLength(255),
|
||||
TextInput::make('contatore_matricola')->label('Matricola contatore')->maxLength(255),
|
||||
Toggle::make('has_dedicated_meter')->label('Contatore dedicato')->default(false),
|
||||
Select::make('counter_scope')
|
||||
->label('Tipo contatore')
|
||||
->options($counterScopeOptions),
|
||||
TextInput::make('served_area_label')->label('Area servita / utilizzo')->maxLength(255),
|
||||
Select::make('canale_acquisizione')
|
||||
->label('Canale acquisizione letture')
|
||||
->options([
|
||||
|
|
@ -470,37 +552,40 @@ public function table(Table $table): Table
|
|||
TextInput::make('costo_lettura_unitario')->label('Costo lettura (unitario)')->numeric(),
|
||||
TextInput::make('costo_ripartizione')->label('Costo ripartizione')->numeric(),
|
||||
Toggle::make('ripartizione_esterna')->label('Ripartizione affidata a ditta esterna')->default(false),
|
||||
Textarea::make('operative_notes')->label('Note operative')->rows(3)->maxLength(2000),
|
||||
Toggle::make('attivo')->label('Attivo')->default(true),
|
||||
])
|
||||
->fillForm(fn(StabileServizio $record): array=> [
|
||||
'tipo' => (string) ($record->tipo ?? ''),
|
||||
'nome' => (string) ($record->nome ?? ''),
|
||||
'common_asset_label' => (string) (($record->meta['common_asset_label'] ?? '') ?: ''),
|
||||
'common_asset_scope' => (string) (($record->meta['common_asset_scope'] ?? '') ?: ''),
|
||||
'allocation_scope' => (string) (($record->meta['allocation_scope'] ?? '') ?: ''),
|
||||
'fiscal_scope' => (string) (($record->meta['fiscal_scope'] ?? '') ?: ''),
|
||||
'fornitore_id' => $record->fornitore_id,
|
||||
'voce_spesa_id' => $record->voce_spesa_id,
|
||||
'codice_utenza' => (string) ($record->codice_utenza ?? ''),
|
||||
'codice_cliente' => (string) ($record->codice_cliente ?? ''),
|
||||
'codice_contratto' => (string) ($record->codice_contratto ?? ''),
|
||||
'contatore_matricola' => (string) ($record->contatore_matricola ?? ''),
|
||||
'has_dedicated_meter' => (bool) ($record->meta['has_dedicated_meter'] ?? false),
|
||||
'counter_scope' => (string) (($record->meta['counter_scope'] ?? '') ?: ''),
|
||||
'served_area_label' => (string) (($record->meta['served_area_label'] ?? '') ?: ''),
|
||||
'canale_acquisizione' => (string) (($record->meta['canale_acquisizione'] ?? '') ?: ''),
|
||||
'email_raccolta_letture' => (string) (($record->meta['email_raccolta_letture'] ?? '') ?: ''),
|
||||
'whatsapp_raccolta_letture' => (string) (($record->meta['whatsapp_raccolta_letture'] ?? '') ?: ''),
|
||||
'costo_lettura_unitario' => $record->meta['costo_lettura_unitario'] ?? null,
|
||||
'costo_ripartizione' => $record->meta['costo_ripartizione'] ?? null,
|
||||
'ripartizione_esterna' => (bool) ($record->meta['ripartizione_esterna'] ?? false),
|
||||
'operative_notes' => (string) (($record->meta['operative_notes'] ?? '') ?: ''),
|
||||
'attivo' => (bool) ($record->attivo ?? true),
|
||||
])
|
||||
->action(function (StabileServizio $record, array $data): void {
|
||||
$meta = is_array($record->meta ?? null) ? $record->meta : [];
|
||||
$meta['canale_acquisizione'] = trim((string) ($data['canale_acquisizione'] ?? '')) ?: null;
|
||||
$meta['email_raccolta_letture'] = trim((string) ($data['email_raccolta_letture'] ?? '')) ?: null;
|
||||
$meta['whatsapp_raccolta_letture'] = trim((string) ($data['whatsapp_raccolta_letture'] ?? '')) ?: null;
|
||||
$meta['costo_lettura_unitario'] = is_numeric($data['costo_lettura_unitario'] ?? null) ? (float) $data['costo_lettura_unitario'] : null;
|
||||
$meta['costo_ripartizione'] = is_numeric($data['costo_ripartizione'] ?? null) ? (float) $data['costo_ripartizione'] : null;
|
||||
$meta['ripartizione_esterna'] = (bool) ($data['ripartizione_esterna'] ?? false);
|
||||
$meta = $this->buildServiceMetaPayload(is_array($record->meta ?? null) ? $record->meta : [], $data);
|
||||
|
||||
$record->fill([
|
||||
'tipo' => strtolower(trim((string) ($data['tipo'] ?? ''))),
|
||||
'nome' => trim((string) ($data['nome'] ?? '')),
|
||||
'nome' => $this->resolveServiceDisplayName($data, (string) ($record->nome ?? '')),
|
||||
'fornitore_id' => (int) ($data['fornitore_id'] ?? 0) ?: null,
|
||||
'voce_spesa_id' => (int) ($data['voce_spesa_id'] ?? 0) ?: null,
|
||||
'codice_utenza' => trim((string) ($data['codice_utenza'] ?? '')) ?: null,
|
||||
|
|
@ -522,6 +607,142 @@ public function table(Table $table): Table
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function getServiceTypeOptions(): array
|
||||
{
|
||||
return [
|
||||
'acqua' => 'Acqua',
|
||||
'energia' => 'Energia',
|
||||
'gas' => 'Gas',
|
||||
'riscaldamento' => 'Riscaldamento',
|
||||
'ascensore' => 'Ascensore',
|
||||
'pulizie' => 'Pulizie',
|
||||
'assicurazione' => 'Assicurazione',
|
||||
'privacy' => 'Privacy',
|
||||
'antenna' => 'Antenna',
|
||||
'antincendio' => 'Antincendio',
|
||||
'citofonia' => 'Citofonia',
|
||||
'locale_comune' => 'Locale comune',
|
||||
'spazio_comune' => 'Spazio / area comune',
|
||||
'impianto' => 'Impianto comune',
|
||||
'altro' => 'Altro',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function getCommonAssetScopeOptions(): array
|
||||
{
|
||||
return [
|
||||
'locale' => 'Locale',
|
||||
'spazio' => 'Spazio comune',
|
||||
'impianto' => 'Impianto',
|
||||
'area_esterna' => 'Area esterna / giardino',
|
||||
'copertura' => 'Terrazzo / copertura',
|
||||
'accesso' => 'Portone / accesso',
|
||||
'servizio' => 'Servizio comune',
|
||||
'sicurezza' => 'Sicurezza / antincendio',
|
||||
'amministrativo'=> 'Privacy / assicurazione / studio',
|
||||
'altro' => 'Altro',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function getAllocationScopeOptions(): array
|
||||
{
|
||||
return [
|
||||
'tutti_millesimi' => 'Tutti per millesimi',
|
||||
'condomini_utilizzatori' => 'Condomini utilizzatori',
|
||||
'inquilini_utilizzatori' => 'Inquilini utilizzatori',
|
||||
'condomini_inquilini_utilizzatori'=> 'Condomini + inquilini utilizzatori',
|
||||
'rimborso_spese' => 'Rimborso spese uso bene comune',
|
||||
'gestione_studio' => 'Gestione studio / amministrazione',
|
||||
'altro' => 'Altro criterio',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function getFiscalScopeOptions(): array
|
||||
{
|
||||
return [
|
||||
'spesa_condominiale' => 'Spesa condominiale',
|
||||
'rimborso_non_fiscale' => 'Rimborso spese non fiscale',
|
||||
'da_fatturare' => 'Da fatturare',
|
||||
'polizza_o_servizio' => 'Polizza / servizio',
|
||||
'non_applicabile' => 'Non applicabile',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function getCounterScopeOptions(): array
|
||||
{
|
||||
return [
|
||||
'generale' => 'Generale',
|
||||
'particolare' => 'Particolare / dedicato',
|
||||
'assente' => 'Senza contatore',
|
||||
];
|
||||
}
|
||||
|
||||
private function formatMetaOptionLabel(array $options, mixed $state): string
|
||||
{
|
||||
$value = strtolower(trim((string) $state));
|
||||
|
||||
return $options[$value] ?? ($value !== '' ? (string) $state : '—');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $currentMeta
|
||||
* @param array<string, mixed> $data
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function buildServiceMetaPayload(array $currentMeta, array $data): array
|
||||
{
|
||||
$meta = $currentMeta;
|
||||
$meta['common_asset_label'] = trim((string) ($data['common_asset_label'] ?? '')) ?: null;
|
||||
$meta['common_asset_scope'] = trim((string) ($data['common_asset_scope'] ?? '')) ?: null;
|
||||
$meta['allocation_scope'] = trim((string) ($data['allocation_scope'] ?? '')) ?: null;
|
||||
$meta['fiscal_scope'] = trim((string) ($data['fiscal_scope'] ?? '')) ?: null;
|
||||
$meta['has_dedicated_meter'] = (bool) ($data['has_dedicated_meter'] ?? false);
|
||||
$meta['counter_scope'] = trim((string) ($data['counter_scope'] ?? '')) ?: (($meta['has_dedicated_meter'] ?? false) ? 'particolare' : 'assente');
|
||||
$meta['served_area_label'] = trim((string) ($data['served_area_label'] ?? '')) ?: null;
|
||||
$meta['canale_acquisizione'] = trim((string) ($data['canale_acquisizione'] ?? '')) ?: null;
|
||||
$meta['email_raccolta_letture'] = trim((string) ($data['email_raccolta_letture'] ?? '')) ?: null;
|
||||
$meta['whatsapp_raccolta_letture'] = trim((string) ($data['whatsapp_raccolta_letture'] ?? '')) ?: null;
|
||||
$meta['costo_lettura_unitario'] = is_numeric($data['costo_lettura_unitario'] ?? null) ? (float) $data['costo_lettura_unitario'] : null;
|
||||
$meta['costo_ripartizione'] = is_numeric($data['costo_ripartizione'] ?? null) ? (float) $data['costo_ripartizione'] : null;
|
||||
$meta['ripartizione_esterna'] = (bool) ($data['ripartizione_esterna'] ?? false);
|
||||
$meta['operative_notes'] = trim((string) ($data['operative_notes'] ?? '')) ?: null;
|
||||
|
||||
return $meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
private function resolveServiceDisplayName(array $data, string $fallback = ''): string
|
||||
{
|
||||
$name = trim((string) ($data['nome'] ?? ''));
|
||||
if ($name !== '') {
|
||||
return $name;
|
||||
}
|
||||
|
||||
$commonLabel = trim((string) ($data['common_asset_label'] ?? ''));
|
||||
if ($commonLabel !== '') {
|
||||
return $commonLabel;
|
||||
}
|
||||
|
||||
return trim($fallback);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
|
|
@ -617,9 +838,9 @@ private function buildPublicAcquaReadingUrl(int $servizioId, int $unitaId, ?int
|
|||
now()->addDays(30),
|
||||
array_filter([
|
||||
'servizio' => $servizioId,
|
||||
'unita' => $unitaId,
|
||||
'request' => $requestId,
|
||||
], fn ($value) => $value !== null)
|
||||
'unita' => $unitaId,
|
||||
'request' => $requestId,
|
||||
], fn($value) => $value !== null)
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -1352,10 +1573,10 @@ public function getAcquaCampagnaStatsProperty(): array
|
|||
$rows = $this->acquaCampagnaRows;
|
||||
|
||||
return [
|
||||
'totale' => count($rows),
|
||||
'completate' => count(array_filter($rows, fn (array $row): bool => $row['status'] === 'fatta')),
|
||||
'pendenti' => count(array_filter($rows, fn (array $row): bool => in_array($row['status'], ['richiesta', 'non_richiesta'], true))),
|
||||
'sollecitate' => count(array_filter($rows, fn (array $row): bool => $row['status'] === 'sollecito')),
|
||||
'totale' => count($rows),
|
||||
'completate' => count(array_filter($rows, fn(array $row): bool => $row['status'] === 'fatta')),
|
||||
'pendenti' => count(array_filter($rows, fn(array $row): bool => in_array($row['status'], ['richiesta', 'non_richiesta'], true))),
|
||||
'sollecitate' => count(array_filter($rows, fn(array $row): bool => $row['status'] === 'sollecito')),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -1363,7 +1584,7 @@ public function getAcquaCampagnaStatsProperty(): array
|
|||
public function getAcquaCampagnaRowsProperty(): array
|
||||
{
|
||||
$stabileId = $this->resolveActiveStabileId();
|
||||
$servizio = $this->resolveActiveAcquaServizio();
|
||||
$servizio = $this->resolveActiveAcquaServizio();
|
||||
if (! $stabileId || ! $servizio) {
|
||||
return [];
|
||||
}
|
||||
|
|
@ -1401,7 +1622,7 @@ public function getAcquaCampagnaRowsProperty(): array
|
|||
->get();
|
||||
|
||||
$currentYearByUnit = [];
|
||||
$latestRealByUnit = [];
|
||||
$latestRealByUnit = [];
|
||||
foreach ($readingRows as $row) {
|
||||
$unitId = (int) ($row->unita_immobiliare_id ?? 0);
|
||||
if ($unitId <= 0) {
|
||||
|
|
@ -1419,7 +1640,7 @@ public function getAcquaCampagnaRowsProperty(): array
|
|||
}
|
||||
|
||||
return $units->map(function (UnitaImmobiliare $unit) use ($currentYearByUnit, $latestRealByUnit, $nominativiByUnit, $servizio): array {
|
||||
$current = $currentYearByUnit[(int) $unit->id] ?? null;
|
||||
$current = $currentYearByUnit[(int) $unit->id] ?? null;
|
||||
$latestReal = $latestRealByUnit[(int) $unit->id] ?? null;
|
||||
|
||||
$status = 'non_richiesta';
|
||||
|
|
@ -1432,17 +1653,17 @@ public function getAcquaCampagnaRowsProperty(): array
|
|||
}
|
||||
|
||||
return [
|
||||
'unit_id' => (int) $unit->id,
|
||||
'unit_label' => trim((string) ($unit->codice_unita ?? '') . ' ' . (string) ($unit->interno ?? '')) ?: ('UI #' . (int) $unit->id),
|
||||
'nominativo' => $nominativiByUnit[(int) $unit->id] ?? (trim((string) ($unit->denominazione ?? '')) ?: 'Nominativo da completare'),
|
||||
'unit_id' => (int) $unit->id,
|
||||
'unit_label' => trim((string) ($unit->codice_unita ?? '') . ' ' . (string) ($unit->interno ?? '')) ?: ('UI #' . (int) $unit->id),
|
||||
'nominativo' => $nominativiByUnit[(int) $unit->id] ?? (trim((string) ($unit->denominazione ?? '')) ?: 'Nominativo da completare'),
|
||||
'previous_reading' => $latestReal?->lettura_fine,
|
||||
'request_id' => $current?->id,
|
||||
'status' => $status,
|
||||
'requested_at' => optional($current?->richiesta_lettura_inviata_at)->format('d/m/Y H:i'),
|
||||
'deadline_at' => optional($current?->deadline_lettura_at)->format('d/m/Y'),
|
||||
'completed_at' => optional($current?->created_at)->format('d/m/Y H:i'),
|
||||
'latest_value' => $current?->lettura_fine,
|
||||
'public_url' => $this->buildPublicAcquaReadingUrl((int) $servizio->id, (int) $unit->id, $current?->id ? (int) $current->id : null),
|
||||
'request_id' => $current?->id,
|
||||
'status' => $status,
|
||||
'requested_at' => optional($current?->richiesta_lettura_inviata_at)->format('d/m/Y H:i'),
|
||||
'deadline_at' => optional($current?->deadline_lettura_at)->format('d/m/Y'),
|
||||
'completed_at' => optional($current?->created_at)->format('d/m/Y H:i'),
|
||||
'latest_value' => $current?->lettura_fine,
|
||||
'public_url' => $this->buildPublicAcquaReadingUrl((int) $servizio->id, (int) $unit->id, $current?->id ? (int) $current->id : null),
|
||||
];
|
||||
})->all();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1227,7 +1227,7 @@ public function getStableGoogleConnectUrl(): string
|
|||
return route('oauth.google.redirect', [
|
||||
'account_key' => 'stabile-' . ($this->stabile?->id ?? 0) . '-pec',
|
||||
'label' => $label,
|
||||
'return_to' => request()->getRequestUri(),
|
||||
'return_to' => $this->getStabilePostaUrl(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -261,7 +261,7 @@ public function getStableGoogleConnectUrl(): string
|
|||
return route('oauth.google.redirect', [
|
||||
'account_key' => 'stabile-' . ($this->stabile?->id ?? 0) . '-pec',
|
||||
'label' => $label,
|
||||
'return_to' => request()->getRequestUri(),
|
||||
'return_to' => $this->getReturnUrl(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -270,7 +270,12 @@ public function getTestGoogleConnectUrl(): string
|
|||
return route('oauth.google.redirect', [
|
||||
'account_key' => 'gmail-test',
|
||||
'label' => 'Account Google test',
|
||||
'return_to' => request()->getRequestUri(),
|
||||
'return_to' => $this->getReturnUrl(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function getReturnUrl(): string
|
||||
{
|
||||
return static::getUrl(['stabile_id' => (int) ($this->stabile?->id ?? 0)], panel: 'admin-filament');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,6 +54,25 @@ class FatturaElettronicaScheda extends Page
|
|||
/** @var array<string,mixed> */
|
||||
public array $acquaPdfPreview = [];
|
||||
|
||||
public function getDocumentoProtocolloConAnnoProperty(): ?string
|
||||
{
|
||||
if (! $this->documento instanceof Documento) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$protocollo = trim((string) ($this->documento->numero_protocollo ?? ''));
|
||||
if ($protocollo === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$year = $this->documento->data_documento?->format('Y')
|
||||
?: $this->documento->created_at?->format('Y')
|
||||
?: $this->fattura->data_fattura?->format('Y')
|
||||
?: now()->format('Y');
|
||||
|
||||
return $year . ' · ' . $protocollo;
|
||||
}
|
||||
|
||||
public function getFornitoreAgganciatoLabel(): ?string
|
||||
{
|
||||
$f = $this->fattura->fornitore;
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ public function getGoogleConnectUrl(): string
|
|||
return route('oauth.google.redirect', [
|
||||
'account_key' => 'fornitore-' . (int) ($this->fornitore?->id ?? 0),
|
||||
'label' => trim((string) ($this->fornitore?->ragione_sociale ?? '')) ?: ('Fornitore #' . (int) ($this->fornitore?->id ?? 0)),
|
||||
'return_to' => request()->getRequestUri(),
|
||||
'return_to' => request()->getRequestUri(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -193,7 +193,7 @@ public function getGoogleDisconnectUrl(): string
|
|||
{
|
||||
return route('oauth.google.disconnect', [
|
||||
'account_key' => 'fornitore-' . (int) ($this->fornitore?->id ?? 0),
|
||||
'return_to' => request()->getRequestUri(),
|
||||
'return_to' => request()->getRequestUri(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -261,7 +261,7 @@ public function saveOperationalWorkflow(): void
|
|||
}
|
||||
|
||||
$normalizedAccessRows = collect($this->stabileAccessRows)
|
||||
->map(fn(array $row): ?array => $this->normalizeStabileAccessRow($row))
|
||||
->map(fn(array $row): ?array=> $this->normalizeStabileAccessRow($row))
|
||||
->filter()
|
||||
->values()
|
||||
->all();
|
||||
|
|
@ -282,11 +282,11 @@ public function saveOperationalWorkflow(): void
|
|||
'stabile_id' => (int) $row['stabile_id'],
|
||||
]);
|
||||
|
||||
$meta = is_array($setting->meta ?? null) ? $setting->meta : [];
|
||||
$meta['access_operativo'] = $row;
|
||||
$setting->fornitore_id = (int) $this->fornitore->id;
|
||||
$setting->stabile_id = (int) $row['stabile_id'];
|
||||
$setting->meta = $meta;
|
||||
$meta = is_array($setting->meta ?? null) ? $setting->meta : [];
|
||||
$meta['access_operativo'] = $row;
|
||||
$setting->fornitore_id = (int) $this->fornitore->id;
|
||||
$setting->stabile_id = (int) $row['stabile_id'];
|
||||
$setting->meta = $meta;
|
||||
$setting->save();
|
||||
}
|
||||
|
||||
|
|
@ -322,7 +322,7 @@ public function saveOperationalWorkflow(): void
|
|||
}
|
||||
|
||||
$config['preferred_materials'] = collect($this->preferredMaterialRows)
|
||||
->map(fn(array $row): ?array => $this->normalizePreferredMaterialRow($row))
|
||||
->map(fn(array $row): ?array=> $this->normalizePreferredMaterialRow($row))
|
||||
->filter()
|
||||
->values()
|
||||
->all();
|
||||
|
|
@ -336,16 +336,16 @@ public function saveOperationalWorkflow(): void
|
|||
Notification::make()
|
||||
->title('Workflow operativo aggiornato')
|
||||
->body($this->operationalConfigAvailable
|
||||
? 'Chiavi, reperibilità e memoria materiali sono stati salvati.'
|
||||
: 'Chiavi e reperibilità per stabile salvate. Esegui la migrazione per attivare anche i preferiti materiali.')
|
||||
? 'Chiavi, reperibilità e memoria materiali sono stati salvati.'
|
||||
: 'Chiavi e reperibilità per stabile salvate. Esegui la migrazione per attivare anche i preferiti materiali.')
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
|
||||
private function refreshArchiveSummary(): void
|
||||
{
|
||||
$relativeBase = $this->getArchiveRelativeBase();
|
||||
$absoluteBase = $relativeBase ? storage_path('app/' . $relativeBase) : null;
|
||||
$relativeBase = $this->getArchiveRelativeBase();
|
||||
$absoluteBase = $relativeBase ? storage_path('app/' . $relativeBase) : null;
|
||||
$this->operationalConfigAvailable = Schema::hasColumn('fornitori', 'operational_config');
|
||||
|
||||
if ($relativeBase !== null) {
|
||||
|
|
@ -388,7 +388,7 @@ private function refreshArchiveSummary(): void
|
|||
$stats = $this->fornitore?->tecnorepair_stats ?? ['total' => 0, 'open' => 0, 'closed' => 0, 'serials' => 0];
|
||||
$this->googleWorkspaceStatus = $this->resolveGoogleWorkspaceStatus();
|
||||
$this->loadOperationalWorkflowSettings();
|
||||
$this->moduleRows = [
|
||||
$this->moduleRows = [
|
||||
['module' => 'Rubrica fornitore', 'status' => 'pronto', 'note' => 'Vista fornitore filtrata ma agganciata all\'anagrafica unica.'],
|
||||
['module' => 'Google Workspace', 'status' => data_get($this->googleWorkspaceStatus, 'connected', false) ? 'collegato' : 'da collegare', 'note' => 'Rubrica e sincronizzazioni smartphone riusano l\'account Google del contesto amministratore.'],
|
||||
['module' => 'TecnoRepair MDB', 'status' => ((int) ($stats['total'] ?? 0) > 0) ? 'importato' : 'da importare', 'note' => 'Schede: ' . (int) ($stats['total'] ?? 0) . ' · aperte: ' . (int) ($stats['open'] ?? 0) . ' · chiuse: ' . (int) ($stats['closed'] ?? 0)],
|
||||
|
|
@ -420,7 +420,7 @@ private function loadOperationalWorkflowSettings(): void
|
|||
->get(['id', 'codice_stabile', 'denominazione']);
|
||||
|
||||
$this->stabileOptions = $stabili
|
||||
->mapWithKeys(fn(Stabile $stabile): array => [
|
||||
->mapWithKeys(fn(Stabile $stabile): array=> [
|
||||
(int) $stabile->id => trim((string) ($stabile->codice_stabile ?: ('#' . $stabile->id)) . ' - ' . (string) ($stabile->denominazione ?: 'Stabile')),
|
||||
])
|
||||
->all();
|
||||
|
|
@ -459,7 +459,7 @@ private function loadOperationalWorkflowSettings(): void
|
|||
|
||||
$config = $this->operationalConfigAvailable ? $this->fornitore->operational_config_safe : [];
|
||||
|
||||
$this->dispatchBoardNote = trim((string) ($config['dispatch_board_note'] ?? ''));
|
||||
$this->dispatchBoardNote = trim((string) ($config['dispatch_board_note'] ?? ''));
|
||||
$this->preferredMaterialRows = collect((array) ($config['preferred_materials'] ?? []))
|
||||
->map(function ($row): ?array {
|
||||
if (! is_array($row)) {
|
||||
|
|
@ -512,8 +512,8 @@ private function normalizeStabileAccessRow(array $row): ?array
|
|||
|
||||
private function normalizePreferredMaterialRow(array $row): ?array
|
||||
{
|
||||
$label = trim((string) ($row['label'] ?? ''));
|
||||
$brandModel = trim((string) ($row['brand_model'] ?? ''));
|
||||
$label = trim((string) ($row['label'] ?? ''));
|
||||
$brandModel = trim((string) ($row['brand_model'] ?? ''));
|
||||
$barcode = trim((string) ($row['barcode'] ?? ''));
|
||||
$internalCode = trim((string) ($row['internal_code'] ?? ''));
|
||||
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ public function getGoogleConnectUrl(): string
|
|||
return route('oauth.google.redirect', [
|
||||
'account_key' => 'fornitore-' . (int) ($this->fornitoreId ?? 0),
|
||||
'label' => trim((string) ($this->fornitoreLabel ?? '')) ?: ('Fornitore #' . (int) ($this->fornitoreId ?? 0)),
|
||||
'return_to' => request()->getRequestUri(),
|
||||
'return_to' => request()->getRequestUri(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -157,7 +157,7 @@ public function getGoogleDisconnectUrl(): string
|
|||
{
|
||||
return route('oauth.google.disconnect', [
|
||||
'account_key' => 'fornitore-' . (int) ($this->fornitoreId ?? 0),
|
||||
'return_to' => request()->getRequestUri(),
|
||||
'return_to' => request()->getRequestUri(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -784,7 +784,7 @@ public function getGoogleConnectUrl(): string
|
|||
return route('oauth.google.redirect', [
|
||||
'account_key' => 'fornitore-' . (int) $this->fornitore->id,
|
||||
'label' => trim((string) ($this->fornitore->ragione_sociale ?? '')) ?: ('Fornitore #' . (int) $this->fornitore->id),
|
||||
'return_to' => request()->getRequestUri(),
|
||||
'return_to' => request()->getRequestUri(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -792,7 +792,7 @@ public function getGoogleDisconnectUrl(): string
|
|||
{
|
||||
return route('oauth.google.disconnect', [
|
||||
'account_key' => 'fornitore-' . (int) $this->fornitore->id,
|
||||
'return_to' => request()->getRequestUri(),
|
||||
'return_to' => request()->getRequestUri(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -891,7 +891,7 @@ protected function buildStoredUploadDisplayName(int $index, bool $isImage, strin
|
|||
|
||||
protected function reloadIntervento(): void
|
||||
{
|
||||
$this->sessionTrackingAvailable = Schema::hasTable('ticket_intervento_sessioni');
|
||||
$this->sessionTrackingAvailable = Schema::hasTable('ticket_intervento_sessioni');
|
||||
$this->operationalConfigAvailable = Schema::hasColumn('fornitori', 'operational_config');
|
||||
|
||||
$relations = [
|
||||
|
|
@ -999,7 +999,7 @@ protected function reloadIntervento(): void
|
|||
$this->googleWorkspaceStatus = $this->resolveGoogleWorkspaceStatus();
|
||||
$this->loadAccessSummary();
|
||||
$this->loadMaterialMemory();
|
||||
$this->qrToken = '';
|
||||
$this->qrToken = '';
|
||||
}
|
||||
|
||||
protected function getActiveSession(): ?TicketInterventoSessione
|
||||
|
|
@ -1151,7 +1151,7 @@ protected function loadAccessSummary(): void
|
|||
return;
|
||||
}
|
||||
|
||||
$config = $this->operationalConfigAvailable ? $this->fornitore->operational_config_safe : [];
|
||||
$config = $this->operationalConfigAvailable ? $this->fornitore->operational_config_safe : [];
|
||||
$this->dispatchBoardNote = trim((string) ($config['dispatch_board_note'] ?? ''));
|
||||
|
||||
$stabileId = (int) ($this->intervento->ticket?->stabile_id ?? 0);
|
||||
|
|
@ -1199,7 +1199,7 @@ protected function loadMaterialMemory(): void
|
|||
: collect();
|
||||
|
||||
$this->preferredMaterialRows = $preferredRows
|
||||
->map(fn($row): ?array => is_array($row) ? $this->normalizePreferredMaterialConfig($row) : null)
|
||||
->map(fn($row): ?array=> is_array($row) ? $this->normalizePreferredMaterialConfig($row) : null)
|
||||
->filter()
|
||||
->filter(fn(array $row): bool => $this->matchesMaterialSearch($row, $term, $normalized))
|
||||
->values()
|
||||
|
|
@ -1298,11 +1298,11 @@ protected function persistPreferredMaterial(array $row): void
|
|||
|
||||
$config = $this->fornitore->operational_config_safe;
|
||||
$rows = collect((array) ($config['preferred_materials'] ?? []))
|
||||
->map(fn($item): ?array => is_array($item) ? $this->normalizePreferredMaterialConfig($item) : null)
|
||||
->map(fn($item): ?array=> is_array($item) ? $this->normalizePreferredMaterialConfig($item) : null)
|
||||
->filter()
|
||||
->values();
|
||||
|
||||
$key = $this->buildMaterialMemoryKey($row);
|
||||
$key = $this->buildMaterialMemoryKey($row);
|
||||
$updatedRows = $rows
|
||||
->reject(fn(array $item): bool => $this->buildMaterialMemoryKey($item) === $key)
|
||||
->prepend($row)
|
||||
|
|
@ -1310,7 +1310,7 @@ protected function persistPreferredMaterial(array $row): void
|
|||
->values()
|
||||
->all();
|
||||
|
||||
$config['preferred_materials'] = $updatedRows;
|
||||
$config['preferred_materials'] = $updatedRows;
|
||||
$this->fornitore->operational_config = $config;
|
||||
$this->fornitore->save();
|
||||
$this->fornitore->refresh();
|
||||
|
|
@ -1318,8 +1318,8 @@ protected function persistPreferredMaterial(array $row): void
|
|||
|
||||
protected function normalizePreferredMaterialConfig(array $row): ?array
|
||||
{
|
||||
$label = trim((string) ($row['label'] ?? ''));
|
||||
$brandModel = trim((string) ($row['brand_model'] ?? ''));
|
||||
$label = trim((string) ($row['label'] ?? ''));
|
||||
$brandModel = trim((string) ($row['brand_model'] ?? ''));
|
||||
$barcode = trim((string) ($row['barcode'] ?? ''));
|
||||
$internalCode = trim((string) ($row['internal_code'] ?? ''));
|
||||
|
||||
|
|
|
|||
|
|
@ -946,7 +946,7 @@ private function scoreFornitoreMatch(Fornitore $fornitore, string $raw, string $
|
|||
}
|
||||
}
|
||||
|
||||
$rowTags = array_map(fn(string $tag): string => mb_strtolower($tag), $tags);
|
||||
$rowTags = array_map(fn(string $tag): string => mb_strtolower($tag), $tags);
|
||||
foreach ($canonicalNeedles as $canonicalNeedle) {
|
||||
foreach ($rowTags as $rowTag) {
|
||||
if ($rowTag === $canonicalNeedle) {
|
||||
|
|
|
|||
|
|
@ -1271,7 +1271,7 @@ private function loadAttachmentMetadataStatus(): void
|
|||
{
|
||||
try {
|
||||
$this->ticketAttachmentMetadataReady = Schema::hasTable('ticket_attachments')
|
||||
&& Schema::hasColumn('ticket_attachments', 'metadata');
|
||||
&& Schema::hasColumn('ticket_attachments', 'metadata');
|
||||
} catch (Throwable) {
|
||||
$this->ticketAttachmentMetadataReady = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,13 +91,13 @@ public static function canAccess(): bool
|
|||
$user = Auth::user();
|
||||
|
||||
return $user instanceof User
|
||||
&& $user->hasAnyRole(['super-admin', 'admin', 'amministratore', 'collaboratore']);
|
||||
&& $user->hasAnyRole(['super-admin', 'admin', 'amministratore', 'collaboratore']);
|
||||
}
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$user = Auth::user();
|
||||
$this->dataLettura = now()->toDateString();
|
||||
$user = Auth::user();
|
||||
$this->dataLettura = now()->toDateString();
|
||||
$this->rilevatoreNome = $user instanceof User ? trim((string) $user->name) : null;
|
||||
$this->resetWaterDraftUploadState();
|
||||
$this->loadStabileOptions();
|
||||
|
|
@ -193,7 +193,7 @@ public function getSelectedWaterUploadsProperty(): array
|
|||
app(TicketAttachmentUploadService::class)->inspectUpload($file),
|
||||
$this->resolveClientCaptureMetadata($name, (int) (method_exists($file, 'getSize') ? $file->getSize() : 0)),
|
||||
);
|
||||
$preview = null;
|
||||
$preview = null;
|
||||
|
||||
if (method_exists($file, 'temporaryUrl')) {
|
||||
try {
|
||||
|
|
@ -242,14 +242,14 @@ public function registraLetturaAcqua(): void
|
|||
'noteGenerali' => ['nullable', 'string', 'max:2000'],
|
||||
'newWaterPhotos.*' => ['nullable', 'image', 'max:8192'],
|
||||
], [
|
||||
'stabileId.required' => 'Seleziona lo stabile.',
|
||||
'servizioId.required' => 'Seleziona il servizio acqua.',
|
||||
'unitaId.required' => 'Seleziona o cerca l\'unità immobiliare.',
|
||||
'letturaAttuale.required' => 'Inserisci la lettura attuale del contatore.',
|
||||
'letturaAttuale.numeric' => 'La lettura attuale deve essere numerica.',
|
||||
'rilevatoreNome.required' => 'Inserisci il nominativo del letturista.',
|
||||
'newWaterPhotos.*.image' => 'Ogni allegato deve essere una foto valida.',
|
||||
'newWaterPhotos.*.max' => 'Ogni foto può pesare al massimo 8 MB.',
|
||||
'stabileId.required' => 'Seleziona lo stabile.',
|
||||
'servizioId.required' => 'Seleziona il servizio acqua.',
|
||||
'unitaId.required' => 'Seleziona o cerca l\'unità immobiliare.',
|
||||
'letturaAttuale.required' => 'Inserisci la lettura attuale del contatore.',
|
||||
'letturaAttuale.numeric' => 'La lettura attuale deve essere numerica.',
|
||||
'rilevatoreNome.required' => 'Inserisci il nominativo del letturista.',
|
||||
'newWaterPhotos.*.image' => 'Ogni allegato deve essere una foto valida.',
|
||||
'newWaterPhotos.*.max' => 'Ogni foto può pesare al massimo 8 MB.',
|
||||
], [
|
||||
'stabileId' => 'stabile',
|
||||
'servizioId' => 'servizio acqua',
|
||||
|
|
@ -294,6 +294,7 @@ public function registraLetturaAcqua(): void
|
|||
$letturaFine = round((float) $validated['letturaAttuale'], 3);
|
||||
$consumo = $letturaInizio !== null ? round($letturaFine - $letturaInizio, 3) : null;
|
||||
$readerName = trim((string) ($validated['rilevatoreNome'] ?? ''));
|
||||
$consistency = $this->buildReadingConsistencyCheck((int) $servizio->id, (int) $unita->id, $letturaFine, $letturaInizio);
|
||||
$readingDate = filled($validated['dataLettura'] ?? null)
|
||||
? Carbon::parse((string) $validated['dataLettura'])
|
||||
: now();
|
||||
|
|
@ -325,7 +326,7 @@ public function registraLetturaAcqua(): void
|
|||
(string) $file->getClientOriginalName(),
|
||||
$readingDate,
|
||||
);
|
||||
$stored = app(TicketAttachmentUploadService::class)->store(
|
||||
$stored = app(TicketAttachmentUploadService::class)->store(
|
||||
$file,
|
||||
$storageDirectory,
|
||||
[
|
||||
|
|
@ -342,56 +343,57 @@ public function registraLetturaAcqua(): void
|
|||
);
|
||||
|
||||
$photoAssets[] = [
|
||||
'index' => $index,
|
||||
'protocol' => $protocol,
|
||||
'path' => $stored['path'],
|
||||
'original_name' => $stored['original_name'] ?? null,
|
||||
'source_original_name' => $stored['source_original_name'] ?? null,
|
||||
'mime' => $stored['mime'] ?? null,
|
||||
'size' => $stored['size'] ?? null,
|
||||
'metadata' => $storedMetadata,
|
||||
'description' => trim((string) ($this->waterPhotoDescriptions[$index] ?? '')),
|
||||
'index' => $index,
|
||||
'protocol' => $protocol,
|
||||
'path' => $stored['path'],
|
||||
'original_name' => $stored['original_name'] ?? null,
|
||||
'source_original_name' => $stored['source_original_name'] ?? null,
|
||||
'mime' => $stored['mime'] ?? null,
|
||||
'size' => $stored['size'] ?? null,
|
||||
'metadata' => $storedMetadata,
|
||||
'description' => trim((string) ($this->waterPhotoDescriptions[$index] ?? '')),
|
||||
'drive_relative_directory' => $naming['drive_relative_directory'],
|
||||
'drive_display_name' => $naming['display_name'],
|
||||
'stored_basename' => $naming['stored_basename'],
|
||||
'drive_display_name' => $naming['display_name'],
|
||||
'stored_basename' => $naming['stored_basename'],
|
||||
];
|
||||
}
|
||||
|
||||
$row = StabileServizioLettura::query()->create([
|
||||
'stabile_id' => (int) $servizio->stabile_id,
|
||||
'stabile_servizio_id' => (int) $servizio->id,
|
||||
'unita_immobiliare_id' => (int) $unita->id,
|
||||
'fornitore_id' => $servizio->fornitore_id,
|
||||
'periodo_dal' => $previous?->periodo_al,
|
||||
'periodo_al' => $readingDate->toDateString(),
|
||||
'tipologia_lettura' => 'ticket_acqua_mobile',
|
||||
'canale_acquisizione' => 'filament_ticket_acqua',
|
||||
'workflow_stato' => 'ricevuta',
|
||||
'riferimento_acquisizione' => 'TICKET-ACQUA:' . (int) $servizio->id . ':' . (int) $unita->id . ':' . now()->format('YmdHis'),
|
||||
'rilevatore_tipo' => 'operatore_filament',
|
||||
'rilevatore_nome' => $readerName,
|
||||
'lettura_precedente_valore' => $letturaInizio,
|
||||
'lettura_inizio' => $letturaInizio,
|
||||
'lettura_fine' => $letturaFine,
|
||||
'lettura_foto_path' => $photoAssets[0]['path'] ?? null,
|
||||
'lettura_foto_original_name'=> $photoAssets[0]['original_name'] ?? null,
|
||||
'lettura_foto_metadata' => [
|
||||
'photos' => $photoAssets,
|
||||
'contact' => trim((string) ($validated['rilevatoreContatto'] ?? '')),
|
||||
'note' => trim((string) ($validated['noteGenerali'] ?? '')),
|
||||
'stabile_id' => (int) $servizio->stabile_id,
|
||||
'stabile_servizio_id' => (int) $servizio->id,
|
||||
'unita_immobiliare_id' => (int) $unita->id,
|
||||
'fornitore_id' => $servizio->fornitore_id,
|
||||
'periodo_dal' => $previous?->periodo_al,
|
||||
'periodo_al' => $readingDate->toDateString(),
|
||||
'tipologia_lettura' => 'ticket_acqua_mobile',
|
||||
'canale_acquisizione' => 'filament_ticket_acqua',
|
||||
'workflow_stato' => 'ricevuta',
|
||||
'riferimento_acquisizione' => 'TICKET-ACQUA:' . (int) $servizio->id . ':' . (int) $unita->id . ':' . now()->format('YmdHis'),
|
||||
'rilevatore_tipo' => 'operatore_filament',
|
||||
'rilevatore_nome' => $readerName,
|
||||
'lettura_precedente_valore' => $letturaInizio,
|
||||
'lettura_inizio' => $letturaInizio,
|
||||
'lettura_fine' => $letturaFine,
|
||||
'lettura_foto_path' => $photoAssets[0]['path'] ?? null,
|
||||
'lettura_foto_original_name' => $photoAssets[0]['original_name'] ?? null,
|
||||
'lettura_foto_metadata' => [
|
||||
'photos' => $photoAssets,
|
||||
'contact' => trim((string) ($validated['rilevatoreContatto'] ?? '')),
|
||||
'note' => trim((string) ($validated['noteGenerali'] ?? '')),
|
||||
'drive_relative_directory' => $storageDirectory,
|
||||
],
|
||||
'consumo_valore' => $consumo,
|
||||
'consumo_unita' => 'mc',
|
||||
'raw' => [
|
||||
'source' => 'ticket_acqua_filament',
|
||||
'contact' => trim((string) ($validated['rilevatoreContatto'] ?? '')),
|
||||
'note' => trim((string) ($validated['noteGenerali'] ?? '')),
|
||||
'photo_assets' => $photoAssets,
|
||||
'consumo_valore' => $consumo,
|
||||
'consumo_unita' => 'mc',
|
||||
'raw' => [
|
||||
'source' => 'ticket_acqua_filament',
|
||||
'contact' => trim((string) ($validated['rilevatoreContatto'] ?? '')),
|
||||
'note' => trim((string) ($validated['noteGenerali'] ?? '')),
|
||||
'photo_assets' => $photoAssets,
|
||||
'drive_relative_directory' => $storageDirectory,
|
||||
'reader_label' => $this->resolveUnitReaderLabel($unita),
|
||||
'reader_label' => $this->resolveUnitReaderLabel($unita),
|
||||
'consistency_check' => $consistency,
|
||||
],
|
||||
'created_by' => (int) $user->id,
|
||||
'created_by' => (int) $user->id,
|
||||
]);
|
||||
|
||||
$this->letturaAttuale = null;
|
||||
|
|
@ -407,6 +409,14 @@ public function registraLetturaAcqua(): void
|
|||
->body('Lettura salvata per unità ' . ((string) ($unita->codice_unita ?: ('#' . $unita->id))) . ' con riferimento #' . $row->id . '.')
|
||||
->success()
|
||||
->send();
|
||||
|
||||
if (($consistency['status'] ?? 'ok') !== 'ok') {
|
||||
Notification::make()
|
||||
->title('Controllo coerenza lettura')
|
||||
->body((string) ($consistency['summary'] ?? 'La lettura va verificata rispetto allo storico.'))
|
||||
->warning()
|
||||
->send();
|
||||
}
|
||||
}
|
||||
|
||||
private function loadStabileOptions(): void
|
||||
|
|
@ -419,11 +429,11 @@ private function loadStabileOptions(): void
|
|||
|
||||
$this->stabileOptions = StabileContext::accessibleStabili($user)
|
||||
->sortBy(fn($stabile) => mb_strtolower((string) ($stabile->denominazione ?? '')))
|
||||
->map(fn($stabile): array => [
|
||||
->map(fn($stabile): array=> [
|
||||
'id' => (int) $stabile->id,
|
||||
'label' => trim((string) (($stabile->codice_stabile ?? '') !== ''
|
||||
? ($stabile->codice_stabile . ' - ' . $stabile->denominazione)
|
||||
: ($stabile->denominazione ?? ('Stabile #' . $stabile->id)))),
|
||||
? ($stabile->codice_stabile . ' - ' . $stabile->denominazione)
|
||||
: ($stabile->denominazione ?? ('Stabile #' . $stabile->id)))),
|
||||
])
|
||||
->values()
|
||||
->all();
|
||||
|
|
@ -436,7 +446,7 @@ private function bootstrapDefaultSelection(): void
|
|||
return;
|
||||
}
|
||||
|
||||
$activeId = StabileContext::resolveActiveStabileId($user);
|
||||
$activeId = StabileContext::resolveActiveStabileId($user);
|
||||
$optionIds = array_column($this->stabileOptions, 'id');
|
||||
|
||||
if ($activeId && in_array((int) $activeId, $optionIds, true)) {
|
||||
|
|
@ -451,10 +461,12 @@ private function loadServiceOptions(): void
|
|||
{
|
||||
if (! $this->stabileId) {
|
||||
$this->servizioOptions = [];
|
||||
$this->servizioId = null;
|
||||
$this->servizioId = null;
|
||||
return;
|
||||
}
|
||||
|
||||
$this->ensureWaterServiceBucket();
|
||||
|
||||
$this->servizioOptions = StabileServizio::query()
|
||||
->where('stabile_id', (int) $this->stabileId)
|
||||
->where('tipo', 'acqua')
|
||||
|
|
@ -487,7 +499,7 @@ private function loadUnitOptions(): void
|
|||
{
|
||||
if (! $this->stabileId) {
|
||||
$this->unitaOptions = [];
|
||||
$this->unitaId = null;
|
||||
$this->unitaId = null;
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -497,8 +509,6 @@ private function loadUnitOptions(): void
|
|||
->where(function ($query): void {
|
||||
$query->whereNull('attiva')->orWhere('attiva', true);
|
||||
})
|
||||
->orderBy('codice_unita')
|
||||
->orderBy('id')
|
||||
->get(['id', 'codice_unita', 'denominazione', 'scala', 'piano', 'interno'])
|
||||
->map(function (UnitaImmobiliare $unita): array {
|
||||
$bits = [trim((string) ($unita->codice_unita ?: ('UI #' . $unita->id)))];
|
||||
|
|
@ -517,9 +527,10 @@ private function loadUnitOptions(): void
|
|||
}
|
||||
|
||||
$readerLabel = $this->resolveUnitReaderLabel($unita);
|
||||
$searchNames = $this->resolveUnitSearchNames($unita);
|
||||
$searchText = mb_strtolower(implode(' ', array_filter([
|
||||
implode(' ', array_filter($bits)),
|
||||
$readerLabel,
|
||||
...$searchNames,
|
||||
])));
|
||||
|
||||
return [
|
||||
|
|
@ -528,10 +539,15 @@ private function loadUnitOptions(): void
|
|||
'reader_label' => $readerLabel,
|
||||
'folder_prefix' => $this->buildUnitFolderPrefix($unita),
|
||||
'search_text' => $searchText,
|
||||
'sort_key' => $this->buildUnitNaturalSortKey($unita, $readerLabel),
|
||||
];
|
||||
})
|
||||
->all();
|
||||
|
||||
usort($this->unitaOptions, static function (array $left, array $right): int {
|
||||
return strnatcasecmp((string) ($left['sort_key'] ?? ''), (string) ($right['sort_key'] ?? ''));
|
||||
});
|
||||
|
||||
$unitIds = array_column($this->unitaOptions, 'id');
|
||||
if (! in_array((int) $this->unitaId, $unitIds, true)) {
|
||||
$this->unitaId = $unitIds[0] ?? null;
|
||||
|
|
@ -598,9 +614,9 @@ private function appendPendingWaterPhotos(): void
|
|||
return;
|
||||
}
|
||||
|
||||
$accepted = array_slice($pending, 0, $available);
|
||||
$currentTotal = count($this->newWaterPhotos);
|
||||
$this->newWaterPhotos = array_values(array_merge($this->newWaterPhotos, $accepted));
|
||||
$accepted = array_slice($pending, 0, $available);
|
||||
$currentTotal = count($this->newWaterPhotos);
|
||||
$this->newWaterPhotos = array_values(array_merge($this->newWaterPhotos, $accepted));
|
||||
$this->pendingWaterPhotos = [];
|
||||
$this->assignDraftUploadCodes($accepted, $currentTotal);
|
||||
$this->syncWaterDescriptionSlots();
|
||||
|
|
@ -608,13 +624,13 @@ private function appendPendingWaterPhotos(): void
|
|||
|
||||
private function resetWaterDraftUploadState(): void
|
||||
{
|
||||
$this->newWaterPhotos = [];
|
||||
$this->pendingWaterPhotos = [];
|
||||
$this->newWaterPhotos = [];
|
||||
$this->pendingWaterPhotos = [];
|
||||
$this->waterPhotoDescriptions = [];
|
||||
$this->waterUploadCodes = [];
|
||||
$this->waterClientMetadata = [];
|
||||
$this->waterDraftProtocol = 'TA-' . now()->format('Ymd-His');
|
||||
$this->waterDraftSequence = 1;
|
||||
$this->waterUploadCodes = [];
|
||||
$this->waterClientMetadata = [];
|
||||
$this->waterDraftProtocol = 'TA-' . now()->format('Ymd-His');
|
||||
$this->waterDraftSequence = 1;
|
||||
}
|
||||
|
||||
private function syncWaterDescriptionSlots(): void
|
||||
|
|
@ -696,6 +712,38 @@ private function syncSuggestedReaderName(): void
|
|||
}
|
||||
}
|
||||
|
||||
private function ensureWaterServiceBucket(): void
|
||||
{
|
||||
if (! $this->stabileId) {
|
||||
return;
|
||||
}
|
||||
|
||||
$hasActiveWaterService = StabileServizio::query()
|
||||
->where('stabile_id', (int) $this->stabileId)
|
||||
->where('tipo', 'acqua')
|
||||
->where('attivo', true)
|
||||
->exists();
|
||||
|
||||
if ($hasActiveWaterService) {
|
||||
return;
|
||||
}
|
||||
|
||||
StabileServizio::query()->firstOrCreate(
|
||||
[
|
||||
'stabile_id' => (int) $this->stabileId,
|
||||
'tipo' => 'acqua',
|
||||
'nome' => 'Archivio letture acqua',
|
||||
],
|
||||
[
|
||||
'attivo' => true,
|
||||
'meta' => [
|
||||
'auto_created_by' => 'ticket-acqua',
|
||||
'purpose' => 'reading-bucket',
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
private function ensureDefaultSelections(): void
|
||||
{
|
||||
if (! $this->stabileId && $this->stabileOptions !== []) {
|
||||
|
|
@ -726,10 +774,98 @@ private function resolveCurrentUnitOption(): ?array
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{status:string,summary:string,delta:?float,average:?float,rule:?string}
|
||||
*/
|
||||
private function buildReadingConsistencyCheck(int $servizioId, int $unitaId, float $letturaFine, ?float $letturaInizio): array
|
||||
{
|
||||
if ($letturaInizio === null) {
|
||||
return [
|
||||
'status' => 'ok',
|
||||
'summary' => 'Prima lettura utile disponibile per questa unità.',
|
||||
'delta' => null,
|
||||
'average' => null,
|
||||
'rule' => 'first_reading',
|
||||
];
|
||||
}
|
||||
|
||||
$delta = round($letturaFine - $letturaInizio, 3);
|
||||
if ($delta < 0) {
|
||||
return [
|
||||
'status' => 'danger',
|
||||
'summary' => 'La lettura inserita è inferiore alla precedente.',
|
||||
'delta' => $delta,
|
||||
'average' => null,
|
||||
'rule' => 'lower_than_previous',
|
||||
];
|
||||
}
|
||||
|
||||
if ($delta === 0.0) {
|
||||
return [
|
||||
'status' => 'warning',
|
||||
'summary' => 'La lettura coincide con la precedente: verificare se il contatore è fermo o se serve un controllo.',
|
||||
'delta' => $delta,
|
||||
'average' => 0.0,
|
||||
'rule' => 'same_as_previous',
|
||||
];
|
||||
}
|
||||
|
||||
$history = StabileServizioLettura::query()
|
||||
->where('stabile_servizio_id', $servizioId)
|
||||
->where('unita_immobiliare_id', $unitaId)
|
||||
->whereNotNull('consumo_valore')
|
||||
->where('consumo_valore', '>', 0)
|
||||
->orderByDesc('periodo_al')
|
||||
->orderByDesc('id')
|
||||
->limit(5)
|
||||
->pluck('consumo_valore')
|
||||
->map(fn($value): float => (float) $value)
|
||||
->all();
|
||||
|
||||
if ($history === []) {
|
||||
return [
|
||||
'status' => 'ok',
|
||||
'summary' => 'Lettura registrata: manca ancora uno storico sufficiente per confronti automatici.',
|
||||
'delta' => $delta,
|
||||
'average' => null,
|
||||
'rule' => 'no_history',
|
||||
];
|
||||
}
|
||||
|
||||
$average = round(array_sum($history) / count($history), 3);
|
||||
if ($average > 0 && $delta > max(30.0, $average * 3)) {
|
||||
return [
|
||||
'status' => 'warning',
|
||||
'summary' => 'La lettura produce un consumo molto più alto della media storica (' . number_format($delta, 3, ',', '.') . ' mc contro media ' . number_format($average, 3, ',', '.') . ' mc).',
|
||||
'delta' => $delta,
|
||||
'average' => $average,
|
||||
'rule' => 'much_higher_than_average',
|
||||
];
|
||||
}
|
||||
|
||||
if ($average >= 1 && $delta < max(0.5, $average * 0.2)) {
|
||||
return [
|
||||
'status' => 'warning',
|
||||
'summary' => 'La lettura produce un consumo molto basso rispetto alla media storica (' . number_format($delta, 3, ',', '.') . ' mc contro media ' . number_format($average, 3, ',', '.') . ' mc).',
|
||||
'delta' => $delta,
|
||||
'average' => $average,
|
||||
'rule' => 'much_lower_than_average',
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => 'ok',
|
||||
'summary' => 'Lettura coerente con lo storico recente.',
|
||||
'delta' => $delta,
|
||||
'average' => $average,
|
||||
'rule' => 'within_expected_range',
|
||||
];
|
||||
}
|
||||
|
||||
private function resolveUnitReaderLabel(UnitaImmobiliare $unita): string
|
||||
{
|
||||
$role = $unita->rubricaRuoliAttivi
|
||||
?->sortByDesc(fn($item) => (bool) ($item->is_preferito ?? false))
|
||||
?->sortByDesc(fn($item) => (bool) ($item->is_preferito ?? false))
|
||||
->first();
|
||||
|
||||
if ($role?->contatto) {
|
||||
|
|
@ -740,7 +876,7 @@ private function resolveUnitReaderLabel(UnitaImmobiliare $unita): string
|
|||
}
|
||||
|
||||
$historic = $unita->nominativiStorici
|
||||
?->sortByDesc(fn($item) => (string) ($item->data_fine ?? '9999-12-31'))
|
||||
?->sortByDesc(fn($item) => (string) ($item->data_fine ?? '9999-12-31'))
|
||||
->sortByDesc(fn($item) => (string) ($item->data_inizio ?? ''))
|
||||
->first();
|
||||
|
||||
|
|
@ -752,6 +888,54 @@ private function resolveUnitReaderLabel(UnitaImmobiliare $unita): string
|
|||
return trim((string) ($unita->denominazione ?? ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int,string>
|
||||
*/
|
||||
private function resolveUnitSearchNames(UnitaImmobiliare $unita): array
|
||||
{
|
||||
$names = [];
|
||||
|
||||
foreach (($unita->rubricaRuoliAttivi ?? collect()) as $role) {
|
||||
$contact = $role->contatto;
|
||||
if (! $contact) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$label = trim((string) ($contact->nome_completo ?: $contact->ragione_sociale));
|
||||
if ($label !== '') {
|
||||
$names[] = $label;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (($unita->nominativiStorici ?? collect()) as $historic) {
|
||||
$label = trim((string) ($historic->nominativo ?? ''));
|
||||
if ($label !== '') {
|
||||
$names[] = $label;
|
||||
}
|
||||
}
|
||||
|
||||
$fallback = trim((string) ($unita->denominazione ?? ''));
|
||||
if ($fallback !== '') {
|
||||
$names[] = $fallback;
|
||||
}
|
||||
|
||||
return array_values(array_unique(array_filter($names)));
|
||||
}
|
||||
|
||||
private function buildUnitNaturalSortKey(UnitaImmobiliare $unita, string $readerLabel): string
|
||||
{
|
||||
$parts = array_filter([
|
||||
trim((string) ($unita->scala ?? '')),
|
||||
trim((string) ($unita->interno ?? '')),
|
||||
trim((string) ($unita->codice_unita ?? '')),
|
||||
trim((string) ($unita->piano ?? '')),
|
||||
trim($readerLabel),
|
||||
(string) $unita->id,
|
||||
]);
|
||||
|
||||
return implode(' ', $parts);
|
||||
}
|
||||
|
||||
private function buildUnitFolderPrefix(UnitaImmobiliare $unita): string
|
||||
{
|
||||
$parts = array_filter([
|
||||
|
|
@ -760,7 +944,7 @@ private function buildUnitFolderPrefix(UnitaImmobiliare $unita): string
|
|||
! filled($unita->interno) && filled($unita->codice_unita) ? trim((string) $unita->codice_unita) : null,
|
||||
]);
|
||||
|
||||
$raw = implode('_', $parts);
|
||||
$raw = implode('_', $parts);
|
||||
$normalized = preg_replace('/[^A-Za-z0-9_\-]+/', '_', $raw) ?? '';
|
||||
|
||||
return trim($normalized, '_-') !== '' ? trim($normalized, '_-') : ('UI_' . (int) $unita->id);
|
||||
|
|
@ -783,11 +967,11 @@ private function buildWaterPhotoNaming(UnitaImmobiliare $unita, string $readerLa
|
|||
{
|
||||
$unita->loadMissing('stabile:id,denominazione,codice_stabile');
|
||||
|
||||
$extension = strtolower((string) pathinfo($originalName, PATHINFO_EXTENSION));
|
||||
$suffix = $extension !== '' ? '.' . $extension : '';
|
||||
$readerSafe = $this->normalizeLinuxPathSegment($readerLabel !== '' ? $readerLabel : ('ui-' . $unita->id));
|
||||
$extension = strtolower((string) pathinfo($originalName, PATHINFO_EXTENSION));
|
||||
$suffix = $extension !== '' ? '.' . $extension : '';
|
||||
$readerSafe = $this->normalizeLinuxPathSegment($readerLabel !== '' ? $readerLabel : ('ui-' . $unita->id));
|
||||
$folderPrefix = Str::lower($this->buildUnitFolderPrefix($unita));
|
||||
$storedBase = trim($folderPrefix . '_' . $readerSafe . '_' . Str::lower(str_replace(['.', ' '], '-', $protocol)), '_');
|
||||
$storedBase = trim($folderPrefix . '_' . $readerSafe . '_' . Str::lower(str_replace(['.', ' '], '-', $protocol)), '_');
|
||||
|
||||
$displayParts = array_filter([
|
||||
filled($unita->interno) ? 'Int. ' . trim((string) $unita->interno) : null,
|
||||
|
|
@ -799,15 +983,15 @@ private function buildWaterPhotoNaming(UnitaImmobiliare $unita, string $readerLa
|
|||
}
|
||||
|
||||
return [
|
||||
'stored_basename' => trim($storedBase, '_-') !== '' ? trim($storedBase, '_-') : ('water-photo-' . $unita->id . '-' . $readingDate->format('YmdHis')),
|
||||
'display_name' => $displayName . $suffix,
|
||||
'stored_basename' => trim($storedBase, '_-') !== '' ? trim($storedBase, '_-') : ('water-photo-' . $unita->id . '-' . $readingDate->format('YmdHis')),
|
||||
'display_name' => $displayName . $suffix,
|
||||
'drive_relative_directory' => 'condomini/' . $this->normalizeLinuxPathSegment((string) ($unita->stabile?->denominazione ?? 'stabile')) . '/utenze/acqua/letture/' . $readingDate->format('Y'),
|
||||
];
|
||||
}
|
||||
|
||||
private function normalizeLinuxPathSegment(string $value): string
|
||||
{
|
||||
$ascii = (string) Str::of($value)->ascii()->lower();
|
||||
$ascii = (string) Str::of($value)->ascii()->lower();
|
||||
$normalized = preg_replace('/[^a-z0-9]+/', '_', $ascii) ?? '';
|
||||
|
||||
return trim($normalized, '_') !== '' ? trim($normalized, '_') : 'n_d';
|
||||
|
|
@ -845,4 +1029,4 @@ private function resolveAccessibleStabileIds(User $user): array
|
|||
->values()
|
||||
->all();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
1007
app/Filament/Pages/Supporto/TicketAcquaGenerale.php
Normal file
1007
app/Filament/Pages/Supporto/TicketAcquaGenerale.php
Normal file
File diff suppressed because it is too large
Load Diff
|
|
@ -19,4 +19,4 @@ class TicketAcquaLight extends TicketAcqua
|
|||
protected static ?string $slug = 'supporto/ticket-acqua-light';
|
||||
|
||||
protected string $view = 'filament.pages.supporto.ticket-acqua-light';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -448,8 +448,8 @@ private function shouldHydrateAttachmentMetadata(TicketAttachment $attachment, a
|
|||
}
|
||||
|
||||
return empty($details['gps'])
|
||||
|| empty($details['exif_datetime'])
|
||||
|| empty($details['device']);
|
||||
|| empty($details['exif_datetime'])
|
||||
|| empty($details['device']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -695,7 +695,7 @@ public function caricaAllegati(): void
|
|||
return;
|
||||
}
|
||||
|
||||
$saved = 0;
|
||||
$saved = 0;
|
||||
$supportsAttachmentMetadata = Schema::hasColumn('ticket_attachments', 'metadata');
|
||||
foreach ($files as $file) {
|
||||
if (! is_object($file) || ! method_exists($file, 'store')) {
|
||||
|
|
|
|||
|
|
@ -739,9 +739,9 @@ public function getSelectedUploadsProperty(): array
|
|||
: [];
|
||||
$metadata = $isImage
|
||||
? app(TicketAttachmentUploadService::class)->mergeClientCaptureMetadata(
|
||||
is_array($metadata) ? $metadata : [],
|
||||
$clientMetadata,
|
||||
)
|
||||
is_array($metadata) ? $metadata : [],
|
||||
$clientMetadata,
|
||||
)
|
||||
: [];
|
||||
|
||||
$previewUrl = null;
|
||||
|
|
@ -789,7 +789,7 @@ private function salvaAllegatiTicket(Ticket $ticket, int $userId): int
|
|||
return 0;
|
||||
}
|
||||
|
||||
$saved = 0;
|
||||
$saved = 0;
|
||||
$supportsAttachmentMetadata = Schema::hasColumn('ticket_attachments', 'metadata');
|
||||
|
||||
$files = array_merge($this->newTicketCameraShots, $this->newTicketAttachments);
|
||||
|
|
|
|||
|
|
@ -60,13 +60,13 @@ public function store(Request $request)
|
|||
}
|
||||
|
||||
$request->validate([
|
||||
'unita_immobiliare_id' => 'required|integer',
|
||||
'categoria_ticket_id' => 'nullable|exists:categorie_ticket,id',
|
||||
'titolo' => 'required|string|max:255',
|
||||
'descrizione' => 'required|string',
|
||||
'luogo_intervento' => 'nullable|string|max:255',
|
||||
'priorita' => 'required|in:Bassa,Media,Alta,Urgente',
|
||||
'allegati.*' => 'nullable|file|max:20480', // 20MB per file
|
||||
'unita_immobiliare_id' => 'required|integer',
|
||||
'categoria_ticket_id' => 'nullable|exists:categorie_ticket,id',
|
||||
'titolo' => 'required|string|max:255',
|
||||
'descrizione' => 'required|string',
|
||||
'luogo_intervento' => 'nullable|string|max:255',
|
||||
'priorita' => 'required|in:Bassa,Media,Alta,Urgente',
|
||||
'allegati.*' => 'nullable|file|max:20480', // 20MB per file
|
||||
'attachment_descriptions' => 'nullable|array',
|
||||
'attachment_descriptions.*' => 'nullable|string|max:255',
|
||||
]);
|
||||
|
|
@ -230,11 +230,11 @@ private function archiveTicketAttachmentDocument(Ticket $ticket, TicketAttachmen
|
|||
return;
|
||||
}
|
||||
|
||||
$localPath = Storage::disk('public')->path($publicPath);
|
||||
$contents = (string) Storage::disk('public')->get($publicPath);
|
||||
$extension = strtolower((string) pathinfo($localPath, PATHINFO_EXTENSION));
|
||||
$archiveReference = 'ticket-' . (int) $ticket->id . '-attachment-' . (int) $attachment->id;
|
||||
$attachmentMeta = is_array($attachment->metadata ?? null) ? $attachment->metadata : [];
|
||||
$localPath = Storage::disk('public')->path($publicPath);
|
||||
$contents = (string) Storage::disk('public')->get($publicPath);
|
||||
$extension = strtolower((string) pathinfo($localPath, PATHINFO_EXTENSION));
|
||||
$archiveReference = 'ticket-' . (int) $ticket->id . '-attachment-' . (int) $attachment->id;
|
||||
$attachmentMeta = is_array($attachment->metadata ?? null) ? $attachment->metadata : [];
|
||||
|
||||
$payload = [
|
||||
'documentable_type' => Ticket::class,
|
||||
|
|
|
|||
|
|
@ -150,38 +150,38 @@ public function store(Request $request): RedirectResponse
|
|||
)));
|
||||
|
||||
$payload = [
|
||||
'stabile_id' => (int) $servizio->stabile_id,
|
||||
'stabile_servizio_id' => (int) $servizio->id,
|
||||
'unita_immobiliare_id' => (int) $unita->id,
|
||||
'fornitore_id' => $servizio->fornitore_id,
|
||||
'periodo_dal' => $previous?->periodo_al,
|
||||
'periodo_al' => isset($validated['data_lettura']) ? Carbon::parse((string) $validated['data_lettura'])->toDateString() : now()->toDateString(),
|
||||
'tipologia_lettura' => 'autolettura_link_pubblico',
|
||||
'canale_acquisizione' => 'portale_pubblico',
|
||||
'workflow_stato' => 'ricevuta',
|
||||
'riferimento_acquisizione' => $pendingRequest?->riferimento_acquisizione ?: ('PUBREAD:' . (int) $servizio->id . ':' . (int) $unita->id . ':' . now()->format('YmdHis')),
|
||||
'rilevatore_tipo' => 'link_pubblico',
|
||||
'rilevatore_nome' => trim((string) $validated['rilevatore_nome']),
|
||||
'lettura_precedente_valore' => $letturaInizio,
|
||||
'lettura_inizio' => $letturaInizio,
|
||||
'lettura_fine' => $letturaFine,
|
||||
'lettura_foto_path' => $photoPaths[0] ?? null,
|
||||
'lettura_foto_original_name'=> $photoAssets[0]['original_name'] ?? null,
|
||||
'lettura_foto_metadata' => [
|
||||
'stabile_id' => (int) $servizio->stabile_id,
|
||||
'stabile_servizio_id' => (int) $servizio->id,
|
||||
'unita_immobiliare_id' => (int) $unita->id,
|
||||
'fornitore_id' => $servizio->fornitore_id,
|
||||
'periodo_dal' => $previous?->periodo_al,
|
||||
'periodo_al' => isset($validated['data_lettura']) ? Carbon::parse((string) $validated['data_lettura'])->toDateString() : now()->toDateString(),
|
||||
'tipologia_lettura' => 'autolettura_link_pubblico',
|
||||
'canale_acquisizione' => 'portale_pubblico',
|
||||
'workflow_stato' => 'ricevuta',
|
||||
'riferimento_acquisizione' => $pendingRequest?->riferimento_acquisizione ?: ('PUBREAD:' . (int) $servizio->id . ':' . (int) $unita->id . ':' . now()->format('YmdHis')),
|
||||
'rilevatore_tipo' => 'link_pubblico',
|
||||
'rilevatore_nome' => trim((string) $validated['rilevatore_nome']),
|
||||
'lettura_precedente_valore' => $letturaInizio,
|
||||
'lettura_inizio' => $letturaInizio,
|
||||
'lettura_fine' => $letturaFine,
|
||||
'lettura_foto_path' => $photoPaths[0] ?? null,
|
||||
'lettura_foto_original_name' => $photoAssets[0]['original_name'] ?? null,
|
||||
'lettura_foto_metadata' => [
|
||||
'photos' => $photoAssets,
|
||||
'paths' => $photoPaths,
|
||||
'contact' => trim((string) ($validated['rilevatore_contatto'] ?? '')),
|
||||
'note' => trim((string) ($validated['note'] ?? '')),
|
||||
],
|
||||
'consumo_valore' => $consumo,
|
||||
'consumo_unita' => 'mc',
|
||||
'raw' => [
|
||||
'source' => 'public_water_reading_link',
|
||||
'contact' => trim((string) ($validated['rilevatore_contatto'] ?? '')),
|
||||
'note' => trim((string) ($validated['note'] ?? '')),
|
||||
'photo_assets'=> $photoAssets,
|
||||
'photo_paths' => $photoPaths,
|
||||
'request_id' => $pendingRequest?->id,
|
||||
'consumo_valore' => $consumo,
|
||||
'consumo_unita' => 'mc',
|
||||
'raw' => [
|
||||
'source' => 'public_water_reading_link',
|
||||
'contact' => trim((string) ($validated['rilevatore_contatto'] ?? '')),
|
||||
'note' => trim((string) ($validated['note'] ?? '')),
|
||||
'photo_assets' => $photoAssets,
|
||||
'photo_paths' => $photoPaths,
|
||||
'request_id' => $pendingRequest?->id,
|
||||
],
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -23,4 +23,4 @@ public function down(): void
|
|||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -27,4 +27,4 @@ public function down(): void
|
|||
$table->dropColumn('metadata');
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -107,4 +107,4 @@ ## Prossimo slice: ticket-lettura acqua semplificato
|
|||
1. risolvere i `5` match mancanti tra `acqua_dett` e `unita_immobiliari`
|
||||
2. creare token/link pubblico per singola unita e singola campagna lettura
|
||||
3. aggiungere tab stabile con lista letture richieste, ricevute e mancanti
|
||||
4. riusare il workflow ticket solo per stato, note e immagini, senza allegati generici
|
||||
4. riusare il workflow ticket solo per stato, note e immagini, senza allegati generici
|
||||
|
|
|
|||
|
|
@ -17,9 +17,9 @@
|
|||
|
||||
<div class="space-y-6">
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold text-gray-900 dark:text-gray-100">Servizi / Utenze - ACQUA</h1>
|
||||
<h1 class="text-2xl font-bold text-gray-900 dark:text-gray-100">Servizi / Beni comuni - ACQUA</h1>
|
||||
<p class="mt-1 text-sm text-gray-600 dark:text-gray-400">
|
||||
Cruscotto operativo acqua con controllo fatture, versamenti/letture condomini e tariffe storicizzate. I dati mostrati seguono lo stabile attivo e l'anno gestione del topbar.
|
||||
Cruscotto operativo per utenze, beni comuni, locali condivisi e contatori acqua dello stabile. Qui convivono contratti, servizi ad uso comune, rimborsi spesa, contatori generali e contatori particolari con storico e tariffe.
|
||||
</p>
|
||||
<div class="mt-2 inline-flex items-center rounded-full border border-blue-200 bg-blue-50 px-3 py-1 text-xs font-medium text-blue-700 dark:border-blue-700/50 dark:bg-blue-900/20 dark:text-blue-200">
|
||||
Anno gestione attivo: {{ $annoGestioneAttivo }}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
<form method="POST" action="{{ route('oauth.google.disconnect') }}">
|
||||
@csrf
|
||||
<input type="hidden" name="account_key" value="{{ $account['key'] }}" />
|
||||
<input type="hidden" name="return_to" value="{{ request()->getRequestUri() }}" />
|
||||
<input type="hidden" name="return_to" value="{{ $this->getReturnUrl() }}" />
|
||||
<button type="submit" class="rounded-md bg-rose-100 px-2 py-1 text-[11px] font-medium text-rose-700 hover:bg-rose-200">Disconnetti</button>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -172,7 +172,7 @@
|
|||
<div class="text-xs text-gray-500 dark:text-gray-400">PDF allegato (se presente) oppure prospetto generato</div>
|
||||
@if($this->documento)
|
||||
<div class="mt-1 text-xs text-gray-500 dark:text-gray-400">
|
||||
Protocollo: <span class="font-medium">{{ $this->documento->numero_protocollo }}</span>
|
||||
Protocollo: <span class="font-medium">{{ $this->documentoProtocolloConAnno ?: $this->documento->numero_protocollo }}</span>
|
||||
·
|
||||
<button
|
||||
type="button"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,378 @@
|
|||
<x-filament-panels::page>
|
||||
<div class="space-y-4">
|
||||
@if ($errors->any())
|
||||
<div class="rounded-xl border border-rose-300 bg-rose-50 p-3 text-sm text-rose-800">
|
||||
<div class="font-semibold">Controlla i dati prima di salvare</div>
|
||||
<ul class="mt-2 list-disc pl-5">
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="rounded-2xl border bg-white p-4 shadow-sm">
|
||||
<div class="flex flex-wrap items-start justify-between gap-3">
|
||||
<div>
|
||||
<h2 class="text-lg font-semibold text-slate-900">Lettura contatori comuni acqua</h2>
|
||||
<div class="mt-1 text-sm text-slate-600">Pagina operativa per contatore generale e contatori particolari dei beni comuni dello stabile, con foto geolocalizzate, storico per contratto e scadenze da calendario per amministrazione o collaboratori.</div>
|
||||
</div>
|
||||
<div class="rounded-full bg-sky-50 px-3 py-1 text-xs font-semibold text-sky-800">Bozza {{ $generalWaterDraftProtocol }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 xl:grid-cols-[1.05fr_0.95fr]">
|
||||
<div class="space-y-4">
|
||||
<div class="rounded-2xl border bg-white p-4 shadow-sm">
|
||||
<div class="grid gap-4 md:grid-cols-2">
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block font-medium">Stabile</span>
|
||||
<select wire:model.live="stabileId" class="w-full rounded-lg border-gray-300">
|
||||
<option value="">Seleziona stabile</option>
|
||||
@foreach($stabileOptions as $option)
|
||||
<option value="{{ $option['id'] }}">{{ $option['label'] }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block font-medium">Contratto / servizio acqua</span>
|
||||
<select wire:model.live="servizioId" class="w-full rounded-lg border-gray-300">
|
||||
<option value="">Seleziona contratto</option>
|
||||
@foreach($servizioOptions as $option)
|
||||
<option value="{{ $option['id'] }}">{{ $option['label'] }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<div class="mt-1 text-[11px] text-slate-500">Se lo stabile ha piu contratti o contatori dedicati a giardino, locale caldaia o altri beni comuni, aggancia la lettura al servizio corretto.</div>
|
||||
</label>
|
||||
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block font-medium">Letturista</span>
|
||||
<select wire:model.live="rilevatoreUserId" class="w-full rounded-lg border-gray-300">
|
||||
<option value="">Seleziona letturista</option>
|
||||
@foreach($readerOptions as $option)
|
||||
<option value="{{ $option['id'] }}">{{ $option['label'] }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</label>
|
||||
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block font-medium">Nominativo che invia la lettura</span>
|
||||
<input type="text" wire:model.defer="rilevatoreNome" class="w-full rounded-lg border-gray-300" placeholder="Nome e cognome" />
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@php($service = $this->selectedServiceSnapshot)
|
||||
@if($service)
|
||||
<div class="rounded-2xl border border-emerald-200 bg-emerald-50 p-4 shadow-sm">
|
||||
<div class="text-sm font-semibold text-emerald-900">Riferimenti contratto selezionato</div>
|
||||
<div class="mt-3 grid gap-3 md:grid-cols-2 text-sm text-emerald-900">
|
||||
<div><span class="font-medium">Servizio:</span> {{ $service['nome'] ?: 'n/d' }}</div>
|
||||
<div><span class="font-medium">Bene comune:</span> {{ $service['common_asset'] ?: 'n/d' }}</div>
|
||||
<div><span class="font-medium">Fornitore:</span> {{ $service['fornitore'] ?: 'n/d' }}</div>
|
||||
<div><span class="font-medium">Tipo contatore:</span> {{ $service['counter_scope'] ?: 'n/d' }}</div>
|
||||
<div><span class="font-medium">Codice utenza:</span> {{ $service['codice_utenza'] ?: 'n/d' }}</div>
|
||||
<div><span class="font-medium">Codice cliente:</span> {{ $service['codice_cliente'] ?: 'n/d' }}</div>
|
||||
<div><span class="font-medium">Codice contratto:</span> {{ $service['codice_contratto'] ?: 'n/d' }}</div>
|
||||
<div><span class="font-medium">Matricola contatore:</span> {{ $service['matricola'] ?: 'n/d' }}</div>
|
||||
<div><span class="font-medium">Area servita:</span> {{ $service['served_area'] ?: 'n/d' }}</div>
|
||||
</div>
|
||||
<div class="mt-3 rounded-xl border border-emerald-300 bg-white p-3 text-xs text-slate-700">
|
||||
<div class="font-semibold text-slate-900">Formato rapido Acea</div>
|
||||
<div class="mt-1">SMS a 3399941808: <span class="font-mono">{{ $service['acea_sms_preview'] !== '' ? $service['acea_sms_preview'] : 'codiceutenza#codicecliente#autolettura' }}</span></div>
|
||||
<div class="mt-1">Numero verde: <span class="font-medium">800 130 331</span></div>
|
||||
<div class="mt-1">Area clienti: <span class="font-medium">www.aceaato2.it</span></div>
|
||||
<div class="mt-1">Cartella archivio anno: <span class="font-medium">{{ $service['year_folder'] }}</span></div>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="rounded-2xl border border-sky-200 bg-sky-50 p-4 shadow-sm">
|
||||
<div class="grid gap-4 md:grid-cols-2">
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block font-medium text-slate-900">Lettura effettiva</span>
|
||||
<input type="number" step="0.001" min="0" wire:model.defer="letturaAttuale" class="w-full rounded-lg border-sky-300 bg-white text-2xl font-semibold text-slate-900" placeholder="Es. 1284.350" />
|
||||
</label>
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block font-medium text-slate-900">Data lettura</span>
|
||||
<input type="date" wire:model.defer="dataLettura" class="w-full rounded-lg border-sky-300 bg-white text-slate-900" />
|
||||
</label>
|
||||
</div>
|
||||
<div class="mt-2 text-xs text-slate-600">La lettura viene salvata nello storico del contratto selezionato, separata dalle singole unita ma con lo stesso standard foto e metadati. Se il valore e fuori linea rispetto allo storico recente compare subito un avviso.</div>
|
||||
</div>
|
||||
|
||||
<div class="rounded-2xl border bg-white p-4 shadow-sm">
|
||||
<div class="text-sm font-semibold text-slate-900">Finestra Acea e calendario operativo</div>
|
||||
<div class="mt-3 grid gap-4 md:grid-cols-2">
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block font-medium">Inizio finestra autolettura</span>
|
||||
<input type="date" wire:model.defer="aceaWindowStart" class="w-full rounded-lg border-gray-300" />
|
||||
</label>
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block font-medium">Fine finestra autolettura</span>
|
||||
<input type="date" wire:model.defer="aceaWindowEnd" class="w-full rounded-lg border-gray-300" />
|
||||
</label>
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block font-medium">Data passaggio incaricato Acea</span>
|
||||
<input type="date" wire:model.defer="aceaVisitDate" class="w-full rounded-lg border-gray-300" />
|
||||
</label>
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block font-medium">Canale previsto invio lettura</span>
|
||||
<select wire:model.defer="aceaAutoSendChannel" class="w-full rounded-lg border-gray-300">
|
||||
<option value="manuale">Manuale studio</option>
|
||||
<option value="sms">SMS Acea</option>
|
||||
<option value="myacea">MyAcea Acqua</option>
|
||||
<option value="telefono">Numero verde</option>
|
||||
<option value="api_futura">Invio automatico futuro</option>
|
||||
</select>
|
||||
</label>
|
||||
<div class="grid gap-4 md:grid-cols-2">
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block font-medium">Fascia da</span>
|
||||
<input type="time" wire:model.defer="aceaVisitTimeFrom" class="w-full rounded-lg border-gray-300" />
|
||||
</label>
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block font-medium">Fascia a</span>
|
||||
<input type="time" wire:model.defer="aceaVisitTimeTo" class="w-full rounded-lg border-gray-300" />
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-2 text-xs text-slate-500">Quando salvi la lettura, creo anche le scadenze operative per la finestra Acea e per il passaggio dell'incaricato se hai compilato le date.</div>
|
||||
</div>
|
||||
|
||||
<div class="rounded-2xl border bg-white p-4 shadow-sm">
|
||||
<label class="block text-sm">
|
||||
<span class="mb-1 block font-medium">Note operative</span>
|
||||
<textarea rows="4" wire:model.defer="noteGenerali" class="w-full rounded-lg border-gray-300" placeholder="Es. accesso locale contatori, due contratti nello stabile, lettura inviata via MyAcea oppure da confermare via SMS..."></textarea>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-4">
|
||||
<div class="rounded-2xl border bg-white p-4 shadow-sm">
|
||||
<div class="text-sm font-semibold text-slate-900">Ultima lettura generale nota</div>
|
||||
@if($lastGeneralReading)
|
||||
<div class="mt-3 space-y-1 text-sm text-slate-700">
|
||||
<div><span class="font-medium">Valore:</span> {{ number_format((float) $lastGeneralReading['value'], 3, ',', '.') }}</div>
|
||||
<div><span class="font-medium">Data:</span> {{ $lastGeneralReading['date'] ?: 'n/d' }}</div>
|
||||
<div><span class="font-medium">Letturista:</span> {{ $lastGeneralReading['reader'] ?: 'n/d' }}</div>
|
||||
<div><span class="font-medium">Protocollo:</span> {{ $lastGeneralReading['protocol'] ?: 'n/d' }}</div>
|
||||
</div>
|
||||
@else
|
||||
<div class="mt-3 text-sm text-slate-500">Nessuna lettura generale ancora registrata per questo contratto.</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="rounded-2xl border bg-white p-4 shadow-sm">
|
||||
<label class="block text-sm"
|
||||
x-data="{
|
||||
localPreviews: [],
|
||||
localClientMetadata: [],
|
||||
init() {
|
||||
window.__ticketAcquaGeneralePreviewState = window.__ticketAcquaGeneralePreviewState || [];
|
||||
window.__ticketAcquaGeneraleClientMetadataState = window.__ticketAcquaGeneraleClientMetadataState || [];
|
||||
this.localPreviews = [...window.__ticketAcquaGeneralePreviewState];
|
||||
this.localClientMetadata = [...window.__ticketAcquaGeneraleClientMetadataState];
|
||||
this.syncClientMetadataToWire();
|
||||
},
|
||||
persist() {
|
||||
window.__ticketAcquaGeneralePreviewState = [...this.localPreviews];
|
||||
},
|
||||
persistClientMetadata() {
|
||||
window.__ticketAcquaGeneraleClientMetadataState = [...this.localClientMetadata];
|
||||
this.syncClientMetadataToWire();
|
||||
},
|
||||
revoke(items) {
|
||||
items.forEach((item) => {
|
||||
if (item.url) {
|
||||
URL.revokeObjectURL(item.url);
|
||||
}
|
||||
});
|
||||
},
|
||||
syncClientMetadataToWire() {
|
||||
$wire.set('generalWaterClientMetadata', this.localClientMetadata.map((item) => ({
|
||||
source: item.source,
|
||||
name: item.name,
|
||||
size: item.size,
|
||||
captured_at: item.captured_at || null,
|
||||
device: item.device || null,
|
||||
gps_decimal: item.gps_decimal || null,
|
||||
gps_accuracy_meters: item.gps_accuracy_meters || null,
|
||||
})), false);
|
||||
},
|
||||
getDeviceLabel() {
|
||||
if (navigator.userAgentData?.platform) {
|
||||
return navigator.userAgentData.platform;
|
||||
}
|
||||
|
||||
return navigator.platform || navigator.userAgent || '';
|
||||
},
|
||||
async readGeolocation() {
|
||||
if (!navigator.geolocation) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return await new Promise((resolve) => {
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
(position) => resolve({
|
||||
gps_decimal: {
|
||||
lat: position.coords.latitude,
|
||||
lng: position.coords.longitude,
|
||||
},
|
||||
gps_accuracy_meters: position.coords.accuracy || null,
|
||||
}),
|
||||
() => resolve(null),
|
||||
{
|
||||
enableHighAccuracy: true,
|
||||
maximumAge: 30000,
|
||||
timeout: 8000,
|
||||
},
|
||||
);
|
||||
});
|
||||
},
|
||||
async buildClientMetadata(file) {
|
||||
const base = {
|
||||
source: 'camera',
|
||||
name: file?.name || '',
|
||||
size: file?.size || 0,
|
||||
captured_at: new Date(file?.lastModified || Date.now()).toISOString(),
|
||||
device: this.getDeviceLabel(),
|
||||
};
|
||||
|
||||
const geo = await this.readGeolocation();
|
||||
|
||||
return geo ? { ...base, ...geo } : base;
|
||||
},
|
||||
mergeClientMetadata(items) {
|
||||
const existing = new Map(this.localClientMetadata.map((item) => [`${item.name}|${item.size}`, item]));
|
||||
items.forEach((item) => {
|
||||
if (!item?.name) {
|
||||
return;
|
||||
}
|
||||
|
||||
existing.set(`${item.name}|${item.size}`, item);
|
||||
});
|
||||
this.localClientMetadata = Array.from(existing.values());
|
||||
this.persistClientMetadata();
|
||||
},
|
||||
async addFiles(event) {
|
||||
const batchId = Date.now();
|
||||
const files = Array.from(event?.target?.files || []);
|
||||
const mapped = files.map((file, index) => ({
|
||||
key: `${batchId}-${index}-${file.name}-${file.size}`,
|
||||
name: file.name,
|
||||
size: file.size || 0,
|
||||
url: (file.type || '').startsWith('image/') ? URL.createObjectURL(file) : null,
|
||||
}));
|
||||
|
||||
const existing = new Map(this.localPreviews.map((item) => [item.key, item]));
|
||||
mapped.forEach((item) => existing.set(item.key, item));
|
||||
this.localPreviews = Array.from(existing.values());
|
||||
this.mergeClientMetadata(await Promise.all(files.map((file) => this.buildClientMetadata(file))));
|
||||
this.persist();
|
||||
|
||||
if (event?.target) {
|
||||
event.target.value = null;
|
||||
}
|
||||
},
|
||||
previewFor(name, size = 0) {
|
||||
const exact = this.localPreviews.find((item) => item.name === name && Number(item.size || 0) === Number(size || 0));
|
||||
return exact?.url || null;
|
||||
},
|
||||
clearAll() {
|
||||
this.revoke(this.localPreviews);
|
||||
this.localPreviews = [];
|
||||
this.localClientMetadata = [];
|
||||
this.persist();
|
||||
this.persistClientMetadata();
|
||||
},
|
||||
}"
|
||||
x-on:ticket-acqua-generale-draft-reset.window="clearAll()"
|
||||
>
|
||||
<span class="mb-2 block font-medium">Foto contatore comune</span>
|
||||
<label class="inline-flex cursor-pointer items-center rounded-md bg-emerald-600 px-3 py-2 text-xs font-medium text-white hover:bg-emerald-500">
|
||||
Scatta o aggiungi foto
|
||||
<input type="file" wire:model="pendingGeneralWaterPhotos" multiple accept="image/*" capture="environment" class="hidden" x-on:change="addFiles($event)" />
|
||||
</label>
|
||||
<div class="mt-1 text-xs text-gray-500">Puoi accodare fino a 4 immagini del contatore generale o particolare e della targhetta matricola.</div>
|
||||
<div wire:loading wire:target="pendingGeneralWaterPhotos" class="mt-2 text-xs font-medium text-amber-700">Caricamento foto in corso.</div>
|
||||
|
||||
@if(count($this->selectedGeneralWaterUploads) > 0)
|
||||
<div class="mt-4 grid gap-3 sm:grid-cols-2">
|
||||
@foreach($this->selectedGeneralWaterUploads as $upload)
|
||||
<div class="rounded-xl border bg-slate-50 p-3 text-xs shadow-sm">
|
||||
<div class="mb-2 aspect-[4/3] overflow-hidden rounded-lg border bg-white" x-show="Boolean(@js($upload['preview_url']) || previewFor(@js($upload['original_name']), @js($upload['size'] ?? 0)))">
|
||||
<img x-bind:src="@js($upload['preview_url']) || previewFor(@js($upload['original_name']), @js($upload['size'] ?? 0))" alt="{{ $upload['name'] }}" class="h-full w-full object-cover" />
|
||||
</div>
|
||||
<div class="rounded-lg border bg-white px-3 py-2 text-[11px] text-slate-700">
|
||||
<div class="font-medium">{{ $upload['name'] }}</div>
|
||||
<div class="mt-1 text-emerald-700">Protocollo bozza: {{ $upload['protocol'] }}</div>
|
||||
<div class="mt-1 text-slate-500">Origine: {{ $upload['original_name'] }}</div>
|
||||
</div>
|
||||
@php
|
||||
$metadata = is_array($upload['metadata'] ?? null) ? $upload['metadata'] : [];
|
||||
$gpsLat = data_get($metadata, 'gps_decimal.lat');
|
||||
$gpsLng = data_get($metadata, 'gps_decimal.lng');
|
||||
$hasGps = is_numeric($gpsLat) && is_numeric($gpsLng);
|
||||
$device = trim((string) data_get($metadata, 'device', ''));
|
||||
@endphp
|
||||
@if($hasGps || $device !== '')
|
||||
<div class="mt-2 rounded-lg border border-slate-200 bg-white p-2 text-[11px] text-slate-700">
|
||||
@if($hasGps)
|
||||
<div><span class="font-medium">Coordinate:</span> {{ number_format((float) $gpsLat, 5, '.', '') }}, {{ number_format((float) $gpsLng, 5, '.', '') }}</div>
|
||||
@endif
|
||||
@if($device !== '')
|
||||
<div><span class="font-medium">Dispositivo:</span> {{ $device }}</div>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
<label class="mt-2 block">
|
||||
<span class="mb-1 block text-[11px] font-medium">Nota foto</span>
|
||||
<input type="text" wire:model.defer="generalWaterPhotoDescriptions.{{ $upload['index'] }}" class="w-full rounded-lg border-gray-300" placeholder="Es. display principale, targhetta matricola, quadro contatori" />
|
||||
</label>
|
||||
<button type="button" wire:click="removeGeneralWaterPhoto({{ (int) $upload['index'] }})" class="mt-2 inline-flex items-center rounded-md bg-rose-600 px-2 py-1 text-[11px] font-medium text-white hover:bg-rose-500">Rimuovi</button>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@else
|
||||
<div class="mt-3 rounded-xl border border-dashed border-slate-300 bg-slate-50 px-4 py-6 text-center text-sm text-slate-500">Nessuna foto in coda. Aggiungi almeno la foto display e, se possibile, matricola/contratto esposto vicino al contatore.</div>
|
||||
@endif
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="rounded-2xl border bg-white p-4 shadow-sm">
|
||||
<div class="text-sm font-semibold text-slate-900">Storico rapido contratto</div>
|
||||
@if(count($this->recentGeneralReadings) > 0)
|
||||
<div class="mt-3 space-y-2">
|
||||
@foreach($this->recentGeneralReadings as $row)
|
||||
<div class="rounded-xl border bg-slate-50 px-3 py-2 text-xs text-slate-700">
|
||||
<div class="flex flex-wrap items-center justify-between gap-2">
|
||||
<div class="font-medium">{{ $row['date'] ?: 'n/d' }} · {{ $row['protocollo'] ?: 'senza protocollo' }}</div>
|
||||
<div>{{ $row['workflow'] ?: 'n/d' }}</div>
|
||||
</div>
|
||||
<div class="mt-1">Valore: <span class="font-medium">{{ $row['value'] !== null ? number_format((float) $row['value'], 3, ',', '.') . ' mc' : 'n/d' }}</span></div>
|
||||
@if($row['consumo'] !== null)
|
||||
<div class="mt-1">Consumo: {{ number_format((float) $row['consumo'], 3, ',', '.') }} mc</div>
|
||||
@endif
|
||||
@if($row['reader'] !== '')
|
||||
<div class="mt-1">Letturista: {{ $row['reader'] }}</div>
|
||||
@endif
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@else
|
||||
<div class="mt-3 text-sm text-slate-500">Storico ancora vuoto per questo contratto.</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div class="rounded-2xl border bg-white p-4 shadow-sm">
|
||||
<x-filament::button wire:click="registraLetturaGenerale" wire:loading.attr="disabled" wire:target="registraLetturaGenerale,pendingGeneralWaterPhotos">
|
||||
<span wire:loading.remove wire:target="registraLetturaGenerale">Salva lettura generale</span>
|
||||
<span wire:loading wire:target="registraLetturaGenerale">Salvataggio...</span>
|
||||
</x-filament::button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</x-filament-panels::page>
|
||||
|
|
@ -43,6 +43,7 @@
|
|||
<option value="{{ $option['id'] }}">{{ $option['label'] }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<div class="mt-1 text-[11px] text-slate-500">Se lo stabile non ha ancora un servizio acqua attivo, preparo automaticamente un archivio letture dedicato.</div>
|
||||
</label>
|
||||
|
||||
<label class="block text-sm md:col-span-2">
|
||||
|
|
|
|||
|
|
@ -378,6 +378,7 @@
|
|||
}));
|
||||
this.appendPreviews(target, mapped);
|
||||
this.mergeClientMetadata(await Promise.all(files.map((file) => this.buildClientMetadata(file, kind))));
|
||||
this.draftSequence += files.length;
|
||||
this.persist();
|
||||
if (event?.target) {
|
||||
event.target.value = null;
|
||||
|
|
@ -401,14 +402,34 @@
|
|||
this.persist();
|
||||
this.persistClientMetadata();
|
||||
},
|
||||
previewFor(draftName, originalName, size = 0) {
|
||||
previewFor(draftName, originalName, size = 0, source = null) {
|
||||
const pool = [...this.localCameraPreviews, ...this.localAttachmentPreviews];
|
||||
const exact = pool.find((item) => item.name === originalName && Number(item.size || 0) === Number(size || 0));
|
||||
const exact = pool.find((item) => {
|
||||
if (source === 'camera' && !String(item.key || '').startsWith('camera-')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (source === 'attachment' && !String(item.key || '').startsWith('attachment-')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return item.name === originalName && Number(item.size || 0) === Number(size || 0);
|
||||
});
|
||||
if (exact?.url) {
|
||||
return exact.url;
|
||||
}
|
||||
|
||||
const match = pool.find((item) => item.draftName === draftName || item.name === originalName);
|
||||
const match = pool.find((item) => {
|
||||
if (source === 'camera' && !String(item.key || '').startsWith('camera-')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (source === 'attachment' && !String(item.key || '').startsWith('attachment-')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return item.draftName === draftName || item.name === originalName;
|
||||
});
|
||||
|
||||
return match?.url || null;
|
||||
},
|
||||
|
|
@ -465,8 +486,8 @@
|
|||
@foreach($this->selectedUploads as $upload)
|
||||
<div class="rounded-xl border bg-white p-3 text-xs shadow-sm">
|
||||
@if($upload['is_image'])
|
||||
<div class="mb-2 aspect-[4/3] overflow-hidden rounded-lg border bg-slate-50" x-show="Boolean(@js($upload['preview_url']) || previewFor(@js($upload['name']), @js($upload['original_name']), @js($upload['size'] ?? 0)))">
|
||||
<img x-bind:src="@js($upload['preview_url']) || previewFor(@js($upload['name']), @js($upload['original_name']), @js($upload['size'] ?? 0))" alt="{{ $upload['name'] }}" class="h-full w-full object-cover" />
|
||||
<div class="mb-2 aspect-[4/3] overflow-hidden rounded-lg border bg-slate-50" x-show="Boolean(@js($upload['preview_url']) || previewFor(@js($upload['name']), @js($upload['original_name']), @js($upload['size'] ?? 0), @js($upload['metadata']['capture_source'] ?? null)))">
|
||||
<img x-bind:src="@js($upload['preview_url']) || previewFor(@js($upload['name']), @js($upload['original_name']), @js($upload['size'] ?? 0), @js($upload['metadata']['capture_source'] ?? null))" alt="{{ $upload['name'] }}" class="h-full w-full object-cover" />
|
||||
</div>
|
||||
@endif
|
||||
<div class="flex flex-wrap items-center gap-2 rounded-lg border bg-gray-50 px-3 py-2">
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user