151 lines
5.1 KiB
PHP
151 lines
5.1 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Filament\Resources;
|
||
|
|
||
|
use App\Enums\OrderStatus;
|
||
|
use App\Enums\OrderType;
|
||
|
use App\Filament\Resources\OrderResource\Pages;
|
||
|
use App\Models\Customer;
|
||
|
use App\Models\Order;
|
||
|
use Filament\Forms\Components\CheckboxList;
|
||
|
use Filament\Forms\Components\DatePicker;
|
||
|
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\Form;
|
||
|
use Filament\Resources\Resource;
|
||
|
use Filament\Tables;
|
||
|
use Filament\Tables\Columns\TextColumn;
|
||
|
use Filament\Tables\Table;
|
||
|
|
||
|
class OrderResource extends Resource
|
||
|
{
|
||
|
protected static ?string $model = Order::class;
|
||
|
|
||
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||
|
|
||
|
public static function form(Form $form): Form
|
||
|
{
|
||
|
return $form
|
||
|
->schema([
|
||
|
Split::make([
|
||
|
Section::make([
|
||
|
Select::make('customer_id')
|
||
|
->label('Customer')
|
||
|
->options(Customer::all()->pluck('company_name', 'id'))
|
||
|
->searchable(),
|
||
|
Select::make('contact_id')
|
||
|
->label('Contact'),
|
||
|
]),
|
||
|
]),
|
||
|
|
||
|
Split::make([
|
||
|
Section::Make([
|
||
|
Select::make('order_type')
|
||
|
->options(OrderType::class)
|
||
|
->searchable(),
|
||
|
Select::make('order_status')
|
||
|
->options(OrderStatus::class)
|
||
|
->searchable(),
|
||
|
]),
|
||
|
]),
|
||
|
|
||
|
Section::Make([
|
||
|
TextInput::make('customer_po'),
|
||
|
]),
|
||
|
Section::make([
|
||
|
DatePicker::make('order_date'),
|
||
|
DatePicker::make('due_date'),
|
||
|
])->columns(2),
|
||
|
Section::make([
|
||
|
CheckboxList::make('Attributes')
|
||
|
->options([
|
||
|
'new_art' => 'New Art',
|
||
|
'repeat' => 'Repeat',
|
||
|
'rush' => 'Rush',
|
||
|
'event' => 'Event',
|
||
|
'digitizing' => 'Digitizing',
|
||
|
'purchased_garments' => 'Purchased Garments',
|
||
|
'customer_supplied_file' => 'Customer Supplied File',
|
||
|
])
|
||
|
->columns(2),
|
||
|
]),
|
||
|
Textarea::make('note'),
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
public static function table(Table $table): Table
|
||
|
{
|
||
|
return $table
|
||
|
// ->recordClasses(fn (Order $order) => match ($order->rush) {
|
||
|
// 1 => 'border-8 bg-black border-orange-600 dark:border-orange-300',
|
||
|
// 0 => 'border-2 border-orange-600 dark:border-orange-300',
|
||
|
// default => null,
|
||
|
// })
|
||
|
->columns([
|
||
|
TextColumn::make('internal_po')
|
||
|
->label('Internal PO')
|
||
|
->copyable()
|
||
|
->fontFamily('mono')
|
||
|
->color('info')
|
||
|
->searchable()
|
||
|
->sortable(),
|
||
|
TextColumn::make('customer.company_name')
|
||
|
->searchable()
|
||
|
->sortable(),
|
||
|
TextColumn::make('customer_po')
|
||
|
->label('PO')
|
||
|
->wrap()
|
||
|
->copyable()
|
||
|
->weight('bold')
|
||
|
->color('code')
|
||
|
->searchable()
|
||
|
->sortable(),
|
||
|
TextColumn::make('order_date')
|
||
|
->searchable()
|
||
|
->sortable(),
|
||
|
TextColumn::make('due_date')
|
||
|
->searchable()
|
||
|
->sortable(),
|
||
|
TextColumn::make('status')
|
||
|
->badge()
|
||
|
->searchable()
|
||
|
->sortable(),
|
||
|
TextColumn::make('rush')
|
||
|
->searchable()
|
||
|
->sortable(),
|
||
|
])
|
||
|
->filters([
|
||
|
Tables\Filters\SelectFilter::make('status')
|
||
|
->multiple()
|
||
|
->options(OrderStatus::class),
|
||
|
])
|
||
|
->actions([
|
||
|
Tables\Actions\EditAction::make(),
|
||
|
])
|
||
|
->bulkActions([
|
||
|
Tables\Actions\BulkActionGroup::make([
|
||
|
Tables\Actions\DeleteBulkAction::make(),
|
||
|
]),
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
public static function getRelations(): array
|
||
|
{
|
||
|
return [
|
||
|
//
|
||
|
];
|
||
|
}
|
||
|
|
||
|
public static function getPages(): array
|
||
|
{
|
||
|
return [
|
||
|
'index' => Pages\ListOrders::route('/'),
|
||
|
'create' => Pages\CreateOrder::route('/create'),
|
||
|
'edit' => Pages\EditOrder::route('/{record}/edit'),
|
||
|
];
|
||
|
}
|
||
|
}
|