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.
226 lines
7.2 KiB
PHP
226 lines
7.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Enums\OrderAttributes;
|
|
use App\Enums\OrderStatus;
|
|
use App\Enums\OrderType;
|
|
use App\Filament\Resources\OrderResource\Pages;
|
|
use App\Models\Contact;
|
|
use App\Models\Customer;
|
|
use App\Models\Order;
|
|
use Filament\Forms\Components\DatePicker;
|
|
use Filament\Forms\Components\Repeater;
|
|
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\Components\Wizard;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
use Guava\FilamentClusters\Forms\Cluster;
|
|
use Illuminate\Support\Facades\Blade;
|
|
use Illuminate\Support\HtmlString;
|
|
|
|
class OrderResource extends Resource
|
|
{
|
|
protected static ?string $model = Order::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-shopping-bag';
|
|
|
|
protected static ?string $navigationGroup = 'Production';
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form->schema([
|
|
Wizard::make([
|
|
Wizard\Step::make('Order Details')
|
|
->schema(self::getOrderDetails())
|
|
->columns(2),
|
|
Wizard\Step::make('Garment Details')
|
|
->schema(self::getGarmentDetails()),
|
|
Wizard\Step::make('Production Details')
|
|
->schema(self::getProductionDetails()),
|
|
])
|
|
->skippable()
|
|
->submitAction(new HtmlString(Blade::render(<<<'BLADE'
|
|
<x-filament::button
|
|
type="submit"
|
|
size="sm"
|
|
>
|
|
Submit
|
|
</x-filament::button>
|
|
BLADE))),
|
|
])->columns(1);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->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(),
|
|
])
|
|
->defaultSort('order_date', 'desc')
|
|
->groups([
|
|
'status',
|
|
])
|
|
->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'),
|
|
];
|
|
}
|
|
|
|
private static function getOrderDetails(): array
|
|
{
|
|
return [
|
|
Section::make([
|
|
Select::make('order_type')
|
|
->required()
|
|
->options(OrderType::class)
|
|
->searchable(),
|
|
|
|
Split::make([
|
|
Select::make('customer_id')
|
|
->required()
|
|
->label('Customer')
|
|
->options(Customer::all()->pluck('company_name', 'id'))
|
|
->reactive()
|
|
->searchable(),
|
|
|
|
Select::make('contact_id')
|
|
->label('Contact')
|
|
->options(fn ($get): array => Contact::where('customer_id', $get('customer_id') ?? null)->get()->pluck('full_name', 'id')->toArray())
|
|
->searchable(),
|
|
]),
|
|
|
|
TextInput::make('customer_po')
|
|
->required()
|
|
->label('Customer PO'),
|
|
|
|
Split::make([
|
|
DatePicker::make('order_date')
|
|
->required()
|
|
->default(today()),
|
|
DatePicker::make('due_date')
|
|
->required()
|
|
->default(today()->add('10 days')),
|
|
]),
|
|
])->columnSpan(1),
|
|
|
|
Section::make([
|
|
ToggleButtons::make('status')
|
|
->required()
|
|
->options(OrderStatus::class)
|
|
->inline(),
|
|
|
|
ToggleButtons::make('order_attributes')
|
|
->options(OrderAttributes::class)
|
|
->multiple()
|
|
->inline(),
|
|
|
|
Textarea::make('notes')
|
|
->rows(3),
|
|
|
|
])->columnSpan(1),
|
|
];
|
|
}
|
|
|
|
private static function getGarmentDetails(): array
|
|
{
|
|
return [
|
|
Repeater::make('Garments')->schema([
|
|
Split::make([
|
|
TextInput::make('sku')->grow(true),
|
|
TextInput::make('name')->grow(false),
|
|
TextInput::make('color')->grow(true),
|
|
]),
|
|
Split::make([
|
|
Cluster::make([
|
|
TextInput::make('xs')
|
|
->placeholder('xs'),
|
|
TextInput::make('s')
|
|
->placeholder('s'),
|
|
TextInput::make('m')
|
|
->placeholder('m'),
|
|
TextInput::make('l')
|
|
->placeholder('l'),
|
|
TextInput::make('xl')
|
|
->placeholder('xl'),
|
|
TextInput::make('2xl')
|
|
->placeholder('2xl'),
|
|
TextInput::make('3xl')
|
|
->placeholder('3xl'),
|
|
TextInput::make('osfa')
|
|
->placeholder('osfa'),
|
|
])->label('Sizes'),
|
|
]),
|
|
])->grid(2),
|
|
];
|
|
}
|
|
|
|
private static function getProductionDetails(): array
|
|
{
|
|
return [
|
|
Repeater::make('Production Details')
|
|
->schema([]),
|
|
];
|
|
}
|
|
}
|