Introduce a template-based system for shipment checklists to automate the creation of required inspection items upon shipment approval. - Add `ShipmentChecklistTemplate` model and migration to define reusable checklist structures. - Extend `ShipmentChecklist` schema to support item titles, requirement flags, sorting, and attachment paths. - Implement `instantiateChecklist` in `ShipmentReviewService` to automatically generate checklist items from active templates based on shipment direction (import/export). - Refactor `ShipmentChecklistResource` and `ChecklistsRelationManager` in Filament to support the new data structure and improved UI. - Update `ShipmentChecklist` model with helper methods for completion tracking and improved relationship handling.
160 lines
5.8 KiB
PHP
160 lines
5.8 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\ShipmentChecklistTemplateResource\Pages;
|
|
use App\Models\ShipmentChecklistTemplate;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
|
|
/**
|
|
* قالبهای قابل تکرار چکلیست. فقط super_admin ویرایش میکند.
|
|
*/
|
|
class ShipmentChecklistTemplateResource extends Resource
|
|
{
|
|
protected static ?string $model = ShipmentChecklistTemplate::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-clipboard-document-list';
|
|
protected static ?string $navigationGroup = 'تنظیمات';
|
|
protected static ?string $navigationLabel = 'قالبهای چکلیست';
|
|
protected static ?string $modelLabel = 'قالب چکلیست';
|
|
protected static ?string $pluralModelLabel = 'قالبهای چکلیست';
|
|
protected static ?int $navigationSort = 9;
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form->schema([
|
|
Forms\Components\Section::make('اطلاعات قالب')->schema([
|
|
Forms\Components\TextInput::make('item_title')
|
|
->label('عنوان آیتم/مرحله')
|
|
->required()
|
|
->maxLength(255)
|
|
->placeholder('مثلاً: تماس با گیرنده، آمادهسازی بار، ارسال به انبار'),
|
|
|
|
Forms\Components\Toggle::make('is_required')
|
|
->label('الزامی')
|
|
->default(true)
|
|
->helperText('اگر الزامی باشد، ناقص ماندنش در گزارش «سفارشهای مشکلدار» ظاهر میشود.'),
|
|
|
|
Forms\Components\TextInput::make('sort_order')
|
|
->label('ترتیب نمایش')
|
|
->numeric()
|
|
->default(0)
|
|
->minValue(0),
|
|
|
|
Forms\Components\Select::make('direction')
|
|
->label('اعمال به جهت')
|
|
->options([
|
|
'both' => 'هر دو (صادرات و واردات)',
|
|
'export' => 'فقط صادرات',
|
|
'import' => 'فقط واردات',
|
|
])
|
|
->default('both')
|
|
->required(),
|
|
|
|
Forms\Components\Toggle::make('is_active')
|
|
->label('فعال')
|
|
->default(true),
|
|
])->columns(2),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('item_title')
|
|
->label('عنوان')
|
|
->searchable()
|
|
->weight('bold'),
|
|
|
|
Tables\Columns\IconColumn::make('is_required')
|
|
->label('الزامی')
|
|
->boolean()
|
|
->trueIcon('heroicon-o-exclamation-circle')
|
|
->falseIcon('heroicon-o-minus-circle')
|
|
->trueColor('danger')
|
|
->falseColor('gray'),
|
|
|
|
Tables\Columns\TextColumn::make('sort_order')
|
|
->label('ترتیب')
|
|
->sortable(),
|
|
|
|
Tables\Columns\TextColumn::make('direction')
|
|
->label('جهت')
|
|
->badge()
|
|
->formatStateUsing(fn (string $state) => match ($state) {
|
|
'both' => 'هر دو',
|
|
'export' => 'صادرات',
|
|
'import' => 'واردات',
|
|
default => $state,
|
|
})
|
|
->color(fn (string $state) => match ($state) {
|
|
'both' => 'info',
|
|
'export' => 'warning',
|
|
'import' => 'success',
|
|
default => 'gray',
|
|
}),
|
|
|
|
Tables\Columns\IconColumn::make('is_active')
|
|
->label('فعال')
|
|
->boolean(),
|
|
])
|
|
->defaultSort('sort_order', 'asc')
|
|
->filters([
|
|
Tables\Filters\SelectFilter::make('direction')
|
|
->options([
|
|
'both' => 'هر دو',
|
|
'export' => 'صادرات',
|
|
'import' => 'واردات',
|
|
]),
|
|
Tables\Filters\TernaryFilter::make('is_active')->label('فعال'),
|
|
])
|
|
->actions([
|
|
Tables\Actions\EditAction::make(),
|
|
Tables\Actions\DeleteAction::make(),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListShipmentChecklistTemplates::route('/'),
|
|
'create' => Pages\CreateShipmentChecklistTemplate::route('/create'),
|
|
'edit' => Pages\EditShipmentChecklistTemplate::route('/{record}/edit'),
|
|
];
|
|
}
|
|
|
|
public static function canViewAny(): bool
|
|
{
|
|
return auth()->user()?->hasAnyRole(['super_admin', 'admin', 'staff']) ?? false;
|
|
}
|
|
|
|
public static function canCreate(): bool
|
|
{
|
|
return auth()->user()?->hasRole('super_admin') ?? false;
|
|
}
|
|
|
|
public static function canEdit($record): bool
|
|
{
|
|
return auth()->user()?->hasRole('super_admin') ?? false;
|
|
}
|
|
|
|
public static function canDelete($record): bool
|
|
{
|
|
return auth()->user()?->hasRole('super_admin') ?? false;
|
|
}
|
|
} |