getRecord()->assignment_number}: Immobili"; } public static function getNavigationLabel(): string { return 'Immobili'; } public function form(Form $form): Form { return $form ->schema([ Forms\Components\TextInput::make('sale_price') ->label('Valore conferimento incarico') ->prefix('€') ->formatStateUsing(function (?string $state): ?string { if ($state === null) { return null; } if (str_contains($state, ',')) { [$int, $dec] = explode(',', $state, 2); $intClean = str_replace('.', '', $int); $value = (float) ($intClean . '.' . $dec); } else { $value = (float) $state; } return number_format($value, 2, ',', '.'); }) ->dehydrateStateUsing(function (?string $state): ?float { if ($state === null) { return null; } if (str_contains($state, ',')) { [$int, $dec] = explode(',', $state, 2); $intClean = str_replace('.', '', $int); return (float) ($intClean . '.' . $dec); } return (float) $state; }) ->default(fn ($record) => $record?->pivot?->sale_price) ->saveRelationshipsUsing(fn ($record, $state) => $record->pivot->sale_price = $state) ->columnSpan(4), Forms\Components\TextInput::make('advertising_price') ->label('Prezzo pubblicità') ->prefix('€') ->formatStateUsing(function (?string $state): ?string { if ($state === null) { return null; } if (str_contains($state, ',')) { [$int, $dec] = explode(',', $state, 2); $intClean = str_replace('.', '', $int); $value = (float) ($intClean . '.' . $dec); } else { $value = (float) $state; } return number_format($value, 2, ',', '.'); }) ->dehydrateStateUsing(function (?string $state): ?float { if ($state === null) { return null; } if (str_contains($state, ',')) { [$int, $dec] = explode(',', $state, 2); $intClean = str_replace('.', '', $int); return (float) ($intClean . '.' . $dec); } return (float) $state; }) ->default(fn ($record) => $record?->pivot?->advertising_price) ->saveRelationshipsUsing(fn ($record, $state) => $record->pivot->advertising_price = $state) ->columnSpan(4), ]); } public function table(Table $table): Table { $propertyUrl = auth()->user()->can('update_property') ? fn (Property $record): string => "/properties/{$record->id}/edit" : fn (Property $record): string => "/properties/{$record->id}"; return $table ->recordTitleAttribute('property_code') ->columns([ Tables\Columns\TextColumn::make('property_code') ->label('Codice Immobile') ->url($propertyUrl) ->extraAttributes(['style' => 'text-decoration: underline;']), Tables\Columns\TextColumn::make('propertyType.name') ->label('Tipologia Immobile'), Tables\Columns\TextColumn::make('propertySubtype.name') ->label('Sub tipologia Immobile'), Tables\Columns\TextColumn::make('branch.name') ->label('Sede Mediawall'), Tables\Columns\TextColumn::make('pivot.sale_price') ->label('Valore conferimento incarico') ->money('EUR', true) ->sortable(), Tables\Columns\TextColumn::make('pivot.advertising_price') ->label('Prezzo pubblicità') ->money('EUR', true) ->sortable(), ]) ->filters([ // ]) ->headerActions([ Tables\Actions\AttachAction::make() ->visible(function (): bool { return auth()->user()->can('attach_assignment::property'); }) ->form(fn (AttachAction $action): array => [ $action->getRecordSelect(), Forms\Components\TextInput::make('sale_price') ->label('Valore conferimento incarico') ->prefix('€') ->numeric() ->rule('decimal:0,2') ->default(fn ($record) => $record?->pivot?->sale_price) ->saveRelationshipsUsing(fn ($record, $state) => $record->pivot->sale_price = $state) ->columnSpan(6), Forms\Components\TextInput::make('advertising_price') ->label('Prezzo pubblicità') ->prefix('€') ->numeric() ->rule('decimal:0,2') ->default(fn ($record) => $record?->pivot?->advertising_price) ->saveRelationshipsUsing(fn ($record, $state) => $record->pivot->advertising_price = $state) ->columnSpan(6), ]) ->label('Aggiungi Immobile') ->color('primary') ->preloadRecordSelect() ->successNotification( Notification::make() ->success() ->title('Salvato') ) ->after(fn () => $this->resetTable()) ->modalHeading('Aggiungi Immobile') ->modalSubmitActionLabel('Salva') ->extraModalFooterActions(function (): array { return [ Tables\Actions\Action::make('attachAnother') ->makeModalSubmitAction('attachAnother', ['another' => true]) ->label('Salva e aggiungi un altro') // Etichetta personalizzata ->color('gray') // Colore simile al pulsante "Annulla" ->extraAttributes([ 'class' => 'bg-white text-gray-950 hover:bg-gray-50 dark:bg-white/5 dark:text-white dark:hover:bg-white/10 ring-1 ring-gray-950/10 dark:ring-white/20' ]), // Personalizza ulteriormente con classi CSS ]; }), ]) ->actions([ ActionGroup::make([ Tables\Actions\EditAction::make() ->visible(fn () => auth()->user()->can('attach_assignment::property')) ->modalHeading('Modifica Relazione') ->after(fn () => $this->resetTable()), Tables\Actions\DetachAction::make() ->visible(function (): bool { return auth()->user()->can('detach_assignment::property'); }) ->successNotification( Notification::make() ->success() ->title('Eliminato') ) ->after(fn () => $this->resetTable()) ->icon('heroicon-m-trash') // Icona del bottone ->label('Elimina'), ]) ], position: ActionsPosition::BeforeColumns) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ ExportBulkAction::make('exportCsv') ->exports([ ExcelExport::make()->withWriterType(\Maatwebsite\Excel\Excel::CSV) ->label('Esporta CSV') ->fromTable() ->withFilename( now()->format('Y-m-d_H-i') . ' - Incarico ' . str_replace(['/', '\\'], '-', $this->getRecord()->assignment_number) . ' - Immobilli' ), ExcelExport::make()->withWriterType(Excel::XLSX) ->label('Esporta XLSX') ->fromTable() ->withFilename( now()->format('Y-m-d_H-i') . ' - Incarico ' . str_replace(['/', '\\'], '-', $this->getRecord()->assignment_number) . ' - Immobilli' ), ]), Tables\Actions\DetachBulkAction::make() ->visible(function (): bool { return auth()->user()->can('detach_assignment::property'); }) ->successNotification( Notification::make() ->success() ->title('Eliminati') ) ->icon('heroicon-m-trash') // Icona del bottone ->label('Elimina selezionati'), ]), ]) ->persistSortInSession() ->persistSearchInSession() ->emptyStateDescription(''); } }