backoffice first commit
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\ClienteResource\Pages;
|
||||
use App\Models\Cliente;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class ClienteResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Cliente::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-users';
|
||||
|
||||
protected static ?string $navigationLabel = 'Clienti';
|
||||
|
||||
protected static ?string $modelLabel = 'cliente';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'clienti';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form->schema([
|
||||
Forms\Components\TextInput::make('nome')->label('Nome')->required(),
|
||||
Forms\Components\TextInput::make('cognome')->label('Cognome'),
|
||||
Forms\Components\TextInput::make('ragione_sociale')->label('Ragione sociale'),
|
||||
Forms\Components\TextInput::make('email')->label('Email')->email()->required(),
|
||||
Forms\Components\TextInput::make('telefono')->label('Telefono')->tel(),
|
||||
Forms\Components\TextInput::make('indirizzo')->label('Indirizzo'),
|
||||
Forms\Components\TextInput::make('cap')->label('CAP')->maxLength(10),
|
||||
Forms\Components\TextInput::make('citta')->label('Città'),
|
||||
Forms\Components\TextInput::make('provincia')->label('Provincia')->maxLength(5),
|
||||
Forms\Components\Textarea::make('note')->label('Note')->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('created_at', 'desc')
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('nominativo')->label('Nominativo')->searchable(['nome', 'cognome', 'ragione_sociale']),
|
||||
Tables\Columns\TextColumn::make('email')->label('Email')->searchable()->copyable(),
|
||||
Tables\Columns\TextColumn::make('telefono')->label('Telefono')->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('citta')->label('Città')->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('preventivi_count')->label('Preventivi')->counts('preventivi'),
|
||||
Tables\Columns\TextColumn::make('created_at')->label('Registrato')->dateTime('d/m/Y')->sortable(),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListClientes::route('/'),
|
||||
'edit' => Pages\EditCliente::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ClienteResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ClienteResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateCliente extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ClienteResource::class;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ClienteResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ClienteResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditCliente extends EditRecord
|
||||
{
|
||||
protected static string $resource = ClienteResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\ViewAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ClienteResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ClienteResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListClientes extends ListRecords
|
||||
{
|
||||
protected static string $resource = ClienteResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\ClienteResource\Pages;
|
||||
|
||||
use App\Filament\Resources\ClienteResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewCliente extends ViewRecord
|
||||
{
|
||||
protected static string $resource = ClienteResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\EditAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,170 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\PreventivoResource\Pages;
|
||||
use App\Filament\Resources\PreventivoResource\RelationManagers\ItemsRelationManager;
|
||||
use App\Models\Preventivo;
|
||||
use App\Support\PreventivoPdf;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Infolists;
|
||||
use Filament\Infolists\Infolist;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class PreventivoResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Preventivo::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-document-text';
|
||||
|
||||
protected static ?string $navigationLabel = 'Preventivi';
|
||||
|
||||
protected static ?string $modelLabel = 'preventivo';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'preventivi';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
public static function getNavigationBadge(): ?string
|
||||
{
|
||||
return (string) static::getModel()::where('stato', 'inviato')->count();
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form->schema([
|
||||
Forms\Components\Select::make('stato')
|
||||
->label('Stato')
|
||||
->options(Preventivo::STATI)
|
||||
->required(),
|
||||
Forms\Components\Select::make('cliente_id')
|
||||
->label('Cliente')
|
||||
->relationship('cliente', 'nome')
|
||||
->searchable()
|
||||
->preload(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('created_at', 'desc')
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('numero')
|
||||
->label('N.')
|
||||
->sortable()
|
||||
->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('cliente.nominativo')
|
||||
->label('Cliente')
|
||||
->searchable(['nome', 'cognome', 'ragione_sociale'])
|
||||
->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('cliente.email')
|
||||
->label('Email')
|
||||
->searchable()
|
||||
->toggleable()
|
||||
->placeholder('—'),
|
||||
Tables\Columns\TextColumn::make('items_count')
|
||||
->label('Prodotti')
|
||||
->counts('items'),
|
||||
Tables\Columns\TextColumn::make('totale')
|
||||
->label('Totale')
|
||||
->money('EUR')
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('stato')
|
||||
->label('Stato')
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state) => Preventivo::STATI[$state] ?? $state)
|
||||
->color(fn (string $state) => match ($state) {
|
||||
'bozza' => 'gray',
|
||||
'inviato' => 'warning',
|
||||
'in_lavorazione' => 'info',
|
||||
'chiuso' => 'success',
|
||||
default => 'gray',
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Data')
|
||||
->dateTime('d/m/Y H:i')
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
Tables\Filters\SelectFilter::make('stato')
|
||||
->label('Stato')
|
||||
->options(Preventivo::STATI),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\ViewAction::make(),
|
||||
Tables\Actions\Action::make('pdf')
|
||||
->label('PDF')
|
||||
->icon('heroicon-o-arrow-down-tray')
|
||||
->visible(fn (Preventivo $record) => $record->stato !== 'bozza')
|
||||
->action(function (Preventivo $record) {
|
||||
if (! $record->pdf_path || ! Storage::disk('local')->exists($record->pdf_path)) {
|
||||
$record->pdf_path = PreventivoPdf::genera($record);
|
||||
$record->save();
|
||||
}
|
||||
|
||||
return Storage::disk('local')->download(
|
||||
$record->pdf_path,
|
||||
'preventivo-'.$record->numero.'.pdf'
|
||||
);
|
||||
}),
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function infolist(Infolist $infolist): Infolist
|
||||
{
|
||||
return $infolist->schema([
|
||||
Infolists\Components\Section::make('Preventivo')
|
||||
->columns(3)
|
||||
->schema([
|
||||
Infolists\Components\TextEntry::make('numero')->label('Numero')->placeholder('—'),
|
||||
Infolists\Components\TextEntry::make('stato')
|
||||
->label('Stato')
|
||||
->badge()
|
||||
->formatStateUsing(fn (string $state) => Preventivo::STATI[$state] ?? $state),
|
||||
Infolists\Components\TextEntry::make('totale')->label('Totale')->money('EUR'),
|
||||
Infolists\Components\TextEntry::make('confirmed_at')->label('Confermato il')->dateTime('d/m/Y H:i')->placeholder('—'),
|
||||
Infolists\Components\TextEntry::make('created_at')->label('Creato il')->dateTime('d/m/Y H:i'),
|
||||
]),
|
||||
Infolists\Components\Section::make('Cliente')
|
||||
->columns(3)
|
||||
->visible(fn (Preventivo $record) => $record->cliente !== null)
|
||||
->schema([
|
||||
Infolists\Components\TextEntry::make('cliente.nominativo')->label('Nominativo'),
|
||||
Infolists\Components\TextEntry::make('cliente.email')->label('Email')->copyable(),
|
||||
Infolists\Components\TextEntry::make('cliente.telefono')->label('Telefono')->placeholder('—'),
|
||||
Infolists\Components\TextEntry::make('cliente.indirizzo')->label('Indirizzo')->placeholder('—'),
|
||||
Infolists\Components\TextEntry::make('cliente.cap')->label('CAP')->placeholder('—'),
|
||||
Infolists\Components\TextEntry::make('cliente.citta')->label('Città')->placeholder('—'),
|
||||
Infolists\Components\TextEntry::make('cliente.provincia')->label('Provincia')->placeholder('—'),
|
||||
Infolists\Components\TextEntry::make('cliente.note')->label('Note')->columnSpanFull()->placeholder('—'),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
ItemsRelationManager::class,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListPreventivos::route('/'),
|
||||
'view' => Pages\ViewPreventivo::route('/{record}'),
|
||||
'edit' => Pages\EditPreventivo::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PreventivoResource\Pages;
|
||||
|
||||
use App\Filament\Resources\PreventivoResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreatePreventivo extends CreateRecord
|
||||
{
|
||||
protected static string $resource = PreventivoResource::class;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PreventivoResource\Pages;
|
||||
|
||||
use App\Filament\Resources\PreventivoResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditPreventivo extends EditRecord
|
||||
{
|
||||
protected static string $resource = PreventivoResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\ViewAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PreventivoResource\Pages;
|
||||
|
||||
use App\Filament\Resources\PreventivoResource;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListPreventivos extends ListRecords
|
||||
{
|
||||
protected static string $resource = PreventivoResource::class;
|
||||
|
||||
// Nessuna azione di creazione: i preventivi nascono dal configuratore.
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PreventivoResource\Pages;
|
||||
|
||||
use App\Filament\Resources\PreventivoResource;
|
||||
use App\Support\PreventivoPdf;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ViewPreventivo extends ViewRecord
|
||||
{
|
||||
protected static string $resource = PreventivoResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\Action::make('visualizzaPdf')
|
||||
->label('Visualizza PDF')
|
||||
->icon('heroicon-o-eye')
|
||||
->color('gray')
|
||||
->visible(fn () => $this->record->stato !== 'bozza')
|
||||
->url(fn () => route('preventivi.pdf.show', $this->record))
|
||||
->openUrlInNewTab(),
|
||||
Actions\Action::make('scaricaPdf')
|
||||
->label('Scarica PDF')
|
||||
->icon('heroicon-o-arrow-down-tray')
|
||||
->color('gray')
|
||||
->visible(fn () => $this->record->stato !== 'bozza')
|
||||
->action(function () {
|
||||
if (! $this->record->pdf_path || ! Storage::disk('local')->exists($this->record->pdf_path)) {
|
||||
$this->record->pdf_path = PreventivoPdf::genera($this->record);
|
||||
$this->record->save();
|
||||
}
|
||||
|
||||
return Storage::disk('local')->download(
|
||||
$this->record->pdf_path,
|
||||
'preventivo-'.$this->record->numero.'.pdf'
|
||||
);
|
||||
}),
|
||||
Actions\EditAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PreventivoResource\RelationManagers;
|
||||
|
||||
use App\Support\ConfigurazioneFormatter;
|
||||
use Filament\Resources\RelationManagers\RelationManager;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ItemsRelationManager extends RelationManager
|
||||
{
|
||||
protected static string $relationship = 'items';
|
||||
|
||||
protected static ?string $title = 'Prodotti configurati';
|
||||
|
||||
protected static ?string $modelLabel = 'prodotto';
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->recordTitleAttribute('nome_modello')
|
||||
->columns([
|
||||
Tables\Columns\ImageColumn::make('immagine_path')
|
||||
->label('Anteprima')
|
||||
->disk('public')
|
||||
->height(60)
|
||||
->square(),
|
||||
Tables\Columns\TextColumn::make('nome_modello')
|
||||
->label('Modello')
|
||||
->description(fn (Model $record) => trim(($record->sistema ? ucfirst($record->sistema) : '').' '.($record->type ?? ''))),
|
||||
Tables\Columns\TextColumn::make('dimensioni')
|
||||
->label('Dimensioni')
|
||||
->state(fn (Model $record) => $record->larghezza && $record->altezza
|
||||
? "{$record->larghezza} × {$record->altezza} cm" : '—'),
|
||||
Tables\Columns\TextColumn::make('quantita')->label('Q.tà'),
|
||||
Tables\Columns\TextColumn::make('prezzo_unitario')->label('Prezzo un.')->money('EUR'),
|
||||
Tables\Columns\TextColumn::make('prezzo_totale')->label('Totale')->money('EUR'),
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\ViewAction::make()
|
||||
->infolist(fn ($infolist) => $infolist->schema([
|
||||
\Filament\Infolists\Components\ImageEntry::make('immagine_path')
|
||||
->label('Anteprima')
|
||||
->disk('public')
|
||||
->height(220),
|
||||
\Filament\Infolists\Components\KeyValueEntry::make('configurazione_display')
|
||||
->label('Configurazione selezionata')
|
||||
->state(fn (Model $record) => collect(ConfigurazioneFormatter::toRows($record->payload))
|
||||
->mapWithKeys(fn ($row) => [$row['label'] => $row['value']])
|
||||
->all())
|
||||
->columnSpanFull(),
|
||||
])),
|
||||
])
|
||||
->paginated(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user