108 lines
3.3 KiB
PHP
Raw Normal View History

2024-10-10 15:15:30 -07:00
<?php
2024-12-10 15:28:14 -08:00
namespace App\Filament\Admin\Resources;
2024-10-10 15:15:30 -07:00
2025-01-16 17:37:32 -05:00
use App\Enums\IconEnum;
use App\Models\Customer;
use App\Models\Order;
2024-10-10 15:15:30 -07:00
use App\Models\Quote;
2024-12-10 15:28:14 -08:00
use Filament\Forms\Components\RichEditor;
2024-11-05 11:35:23 -05:00
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Split;
2024-10-10 15:15:30 -07:00
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
class QuoteResource extends Resource
{
protected static ?string $model = Quote::class;
2025-01-16 17:37:32 -05:00
protected static ?string $navigationIcon = IconEnum::QUOTE->value;
2024-10-10 15:15:30 -07:00
protected static ?string $navigationGroup = 'Production';
2024-10-10 15:15:30 -07:00
protected static ?int $navigationSort = 1;
public static function form(Form $form): Form
{
return $form
->schema([
2024-11-05 11:35:23 -05:00
Section::make([
Split::make([
Select::make('customer_id')
->required()
->label('Customer')
->options(Customer::all()->pluck('company_name', 'id'))
->reactive()
->searchable(),
Select::make('order_id')
->label('Order')
->options(fn ($get): array => Order::where('customer_id', $get('customer_id') ?? null)
->get()
->pluck('customer_po', 'id')
->toArray())
->searchable(),
])->columnSpan(2),
2024-12-10 15:28:14 -08:00
RichEditor::make('body')
->columnSpan(2),
// ->rows(8),
2024-11-05 11:35:23 -05:00
]),
])->columns(3);
2024-10-10 15:15:30 -07:00
}
public static function table(Table $table): Table
{
return $table
->columns([
2024-10-30 19:28:03 -04:00
Tables\Columns\TextColumn::make('order.customer.company_name')
->searchable(),
Tables\Columns\TextColumn::make('order.customer_po')
->searchable()
->weight('bold')
->color('code'),
Tables\Columns\TextColumn::make('body')
2024-10-30 19:28:03 -04:00
->searchable()
->limit(100),
2024-10-30 19:28:03 -04:00
Tables\Columns\TextColumn::make('created_at')
->date('Y-m-d')
->sortable(),
])
->defaultSort('created_at', 'desc')
->groups([
'order.customer.company_name',
2024-10-10 15:15:30 -07:00
])
->filters([
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
]);
}
2025-01-04 16:41:24 -05:00
public static function canAccess(): bool
{
return auth()->user()->is_admin;
}
2024-10-10 15:15:30 -07:00
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
2024-12-10 15:28:14 -08:00
'index' => \App\Filament\Admin\Resources\QuoteResource\Pages\ListQuotes::route('/'),
'create' => \App\Filament\Admin\Resources\QuoteResource\Pages\CreateQuote::route('/create'),
'edit' => \App\Filament\Admin\Resources\QuoteResource\Pages\EditQuote::route('/{record}/edit'),
2024-10-10 15:15:30 -07:00
];
}
}