topnotch_website/app/Filament/Admin/Resources/PackingSlipResource.php

121 lines
4.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;
2024-10-21 16:05:57 -04:00
use App\Models\Customer;
use App\Models\Order;
2024-10-10 15:15:30 -07:00
use App\Models\PackingSlip;
2024-10-21 16:05:57 -04:00
use Filament\Forms\Components\DatePicker;
2025-01-21 21:28:41 -05:00
use Filament\Forms\Components\Grid;
2024-12-10 15:28:14 -08:00
use Filament\Forms\Components\Section;
2024-10-21 16:05:57 -04:00
use Filament\Forms\Components\Select;
2025-01-21 21:28:41 -05:00
use Filament\Forms\Components\Split;
2024-10-21 16:05:57 -04:00
use Filament\Forms\Components\Textarea;
2024-10-10 15:15:30 -07:00
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
class PackingSlipResource extends Resource
{
protected static ?string $model = PackingSlip::class;
2025-01-16 17:37:32 -05:00
protected static ?string $navigationIcon = IconEnum::PACKING_SLIP->value;
2024-10-10 15:15:30 -07:00
2025-01-24 21:37:05 -05:00
protected static ?string $navigationGroup = 'Production';
2024-10-10 15:15:30 -07:00
2024-10-30 19:28:03 -04:00
protected static ?int $navigationSort = 2;
2024-10-10 15:15:30 -07:00
public static function form(Form $form): Form
{
return $form
->schema([
2024-12-10 15:28:14 -08:00
Section::make([
2025-01-21 21:28:41 -05:00
Split::make([
Grid::make(1)
->schema([
DatePicker::make('date_received')
->default(today())
->required(),
Select::make('customer_id')
->label('Customer')
->options(Customer::all()->pluck('company_name', 'id'))
->reactive()
->searchable(),
Select::make('order_id')
->label('Order')
->required()
->options(fn ($get): array => Order::where('customer_id', $get('customer_id') ?? null)
->get()
->pluck('customer_po', 'id')
->toArray())
->searchable(),
])
->columnSpan(1),
Grid::make(1)
->schema([
TextArea::make('contents')
->rows(9),
])
->columnSpan(1),
]),
]),
2024-10-10 15:15:30 -07:00
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('date_received')
->sortable()
->searchable(),
TextColumn::make('order.customer_po')
2025-01-21 21:28:41 -05:00
// ->url(fn ($record) => $record->to)
->url(fn ($record) => OrderResource::getUrl('edit', ['record' => $record->id]))
2024-10-10 15:15:30 -07:00
->weight('bold')
->color('code')
->sortable()
->searchable(),
2024-12-10 15:28:14 -08:00
TextColumn::make('contents')
->extraHeaderAttributes(['class' => 'w-full']),
// TextColumn::make('amount')
// ->label('Quantity'),
2024-10-10 15:15:30 -07:00
TextColumn::make('order.customer.company_name')
->sortable()
->searchable(),
])
->defaultSort('date_received', 'desc')
->filters([
//
])
->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 [
2025-01-24 21:37:05 -05:00
'index' => \App\Filament\Admin\Resources\PackingSlipResource\Pages\ListPackingSlips::route('/'),
// 'create' => \App\Filament\Admin\Resources\PackingSlipResource\Pages\CreatePackingSlip::route('/create'),
// 'edit' => \App\Filament\Admin\Resources\PackingSlipResource\Pages\EditPackingSlip::route('/{record}/edit'),
2024-10-10 15:15:30 -07:00
];
}
}