diff --git a/app/Enums/ShippingType.php b/app/Enums/ShippingType.php index b7ddfdc..7e7ed10 100644 --- a/app/Enums/ShippingType.php +++ b/app/Enums/ShippingType.php @@ -2,9 +2,28 @@ namespace App\Enums; -enum ShippingType: string +use Filament\Support\Contracts\HasIcon; +use Filament\Support\Contracts\HasLabel; + +enum ShippingType: string implements HasIcon, HasLabel { case THEY_SHIP = 'They ship'; case WE_SHIP = 'We ship'; case PICKUP = 'Pickup'; + case OTHER = 'Other'; + + public function getLabel(): ?string + { + return $this->value; + } + + public function getIcon(): ?string + { + return match ($this) { + self::THEY_SHIP => 'lucide-truck', + self::WE_SHIP => 'lucide-house', + self::PICKUP => 'lucide-handshake', + self::OTHER => 'lucide-ellipsis' + }; + } } diff --git a/app/Filament/Resources/ShippingEntryResource.php b/app/Filament/Resources/ShippingEntryResource.php index 92ddf0a..7e0d818 100644 --- a/app/Filament/Resources/ShippingEntryResource.php +++ b/app/Filament/Resources/ShippingEntryResource.php @@ -2,12 +2,22 @@ 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\Tables; +use Filament\Tables\Grouping\Group; use Filament\Tables\Table; +use Illuminate\Database\Eloquent\Builder; class ShippingEntryResource extends Resource { @@ -23,7 +33,65 @@ class ShippingEntryResource extends Resource { 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), ]); } @@ -31,16 +99,20 @@ class ShippingEntryResource extends Resource { return $table ->columns([ - Tables\Columns\TextColumn::make('customer.company_name') - ->searchable(), + // Tables\Columns\TextColumn::make('customer.company_name') + // ->searchable(), Tables\Columns\TextColumn::make('shipping_type') ->label('Type') ->sortable(), - Tables\Columns\TextColumn::make('courier'), - // Tables\Columns\TextColumn::make('contact'), + Tables\Columns\TextColumn::make('courier') + ->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}%"); + }); + }), Tables\Columns\TextColumn::make('account_title'), - // Tables\Columns\TextColumn::make('account_username'), - // Tables\Columns\TextColumn::make('account_password'), Tables\Columns\TextColumn::make('info_needed'), Tables\Columns\TextColumn::make('notify'), @@ -55,11 +127,11 @@ class ShippingEntryResource extends Resource // Tables\Actions\BulkActionGroup::make([ // Tables\Actions\DeleteBulkAction::make(), // ]), - ]); - // ->defaultGroup( - // Group::make('customer.company_name') - // ->titlePrefixedWithLabel(false) - // ); + ]) + ->defaultGroup( + Group::make('customer.company_name') + ->titlePrefixedWithLabel(false) + ); } public static function getRelations(): array diff --git a/app/Models/ShippingEntry.php b/app/Models/ShippingEntry.php index a4386a7..1205e57 100644 --- a/app/Models/ShippingEntry.php +++ b/app/Models/ShippingEntry.php @@ -24,6 +24,7 @@ class ShippingEntry extends Model 'courier', 'contact', 'account_title', + 'account_url', 'account_username', 'account_password', 'info_needed', diff --git a/database/factories/ShippingEntryFactory.php b/database/factories/ShippingEntryFactory.php index 6b793d3..b886de4 100644 --- a/database/factories/ShippingEntryFactory.php +++ b/database/factories/ShippingEntryFactory.php @@ -18,6 +18,7 @@ class ShippingEntryFactory extends Factory 'courier' => $this->faker->randomElement(['UPS', 'Purolator', 'FreightCom', 'E-Shipper', 'ACE']), 'contact' => $this->faker->randomElement(['courier.com', '+1 604 123 4567']), 'account_title' => $this->faker->word, + 'account_url' => 'https://www.example.com', 'account_username' => 'username', 'account_password' => 'password', 'info_needed' => $this->faker->words(3, true), diff --git a/database/migrations/2024_09_06_213725_create_shipping_entries_table.php b/database/migrations/2024_09_06_213725_create_shipping_entries_table.php index 81cb84f..8f9e9d1 100644 --- a/database/migrations/2024_09_06_213725_create_shipping_entries_table.php +++ b/database/migrations/2024_09_06_213725_create_shipping_entries_table.php @@ -15,6 +15,7 @@ return new class extends Migration $table->string('courier')->nullable(); $table->string('contact')->nullable(); $table->string('account_title')->nullable(); + $table->string('account_url')->nullable(); $table->string('account_username')->nullable(); $table->string('account_password')->nullable(); $table->string('info_needed')->nullable();