You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
topnotch_website/app/Filament/Resources/ShippingEntryResource.php

156 lines
6.1 KiB
PHTML

<?php
namespace App\Filament\Resources;
use App\Enums\ShippingType;
use App\Filament\Resources\ShippingEntryResource\Pages;
use App\Models\ShippingEntry;
use Filament\Forms\Components\Fieldset;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Split;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\ToggleButtons;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Support\Enums\IconPosition;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Grouping\Group;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
class ShippingEntryResource extends Resource
{
protected static ?string $model = ShippingEntry::class;
protected static ?string $navigationIcon = 'lucide-truck';
protected static ?string $navigationGroup = 'Management';
protected static ?int $navigationSort = 3;
public static function form(Form $form): Form
{
return $form
->schema([
Section::make([
Fieldset::make('Primary information')
->schema([
Select::make('customer')
->relationship('customer', 'company_name')
->searchable()
->required(),
ToggleButtons::make('shipping_type')
->options(ShippingType::class)
->inline()
->required(),
TextInput::make('courier')
->placeholder('UPS, Purolator...'),
]),
Split::make([
Fieldset::make('Account Details')
->schema([
TextInput::make('account_title')
->label('Title')
->prefixIcon('lucide-folder-pen')
->placeholder('What is this account used for?')
->columnSpan(2),
TextInput::make('account_url')
->label('URL')
->prefixIcon('lucide-globe')
->placeholder('Shipping website')
->url()
->columnSpan(2),
TextInput::make('account_username')
->label('Username')
->prefixIcon('lucide-circle-user')
->placeholder('...'),
TextInput::make('account_password')
->label('Password')
->prefixIcon('lucide-key-round')
->placeholder('...'),
])->columnSpan(1),
Fieldset::make('Shipping Instructions')
->schema([
TextInput::make('info_needed')
->label('Instructions')
->prefixIcon('lucide-pencil')
->placeholder('Example: put PO on box')
->columnSpan(2),
TextInput::make('notify')
->placeholder('Who to email and CC?')
->prefixIcon('lucide-users-round')
->columnSpan(2),
TextArea::make('notes')
->placeholder('Any additional information...')
->rows(2)
->columnSpan(2),
]),
])->columnSpan(2),
])->columns(2),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('shipping_type')
->label('Type')
->sortable(),
TextColumn::make('courier')
->url(fn ($record) => $record->account_url ?? null, shouldOpenInNewTab: true)
->icon(fn ($record) => $record->account_url ? 'lucide-external-link' : null)
->iconPosition(IconPosition::After)
->searchable(query: function (Builder $query, $search) {
return $query
->where('courier', 'like', "%{$search}%")
->orWhereHas('customer', function (Builder $query) use ($search) {
return $query->where('company_name', 'like', "%{$search}%");
});
}),
TextColumn::make('account_title'),
TextColumn::make('info_needed'),
TextColumn::make('notify'),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
// Tables\Actions\BulkActionGroup::make([
// Tables\Actions\DeleteBulkAction::make(),
// ]),
])
->defaultGroup(
Group::make('customer.company_name')
->titlePrefixedWithLabel(false)
);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListShippingEntries::route('/'),
'create' => Pages\CreateShippingEntry::route('/create'),
'edit' => Pages\EditShippingEntry::route('/{record}/edit'),
];
}
}