ifnex/04_Laravel/app/Filament/Resources/ShipmentResource.php

234 lines
10 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Filament\Resources;
use App\Filament\Resources\ShipmentResource\Pages;
use App\Models\Shipment;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use App\Imports\ShippingRatesImport;
use Maatwebsite\Excel\Facades\Excel;
use Filament\Actions\Action;
use Filament\Forms\Components\FileUpload;
class ShipmentResource extends Resource
{
protected static ?string $model = Shipment::class;
// تغییر آیکون به نماد کامیون/ارسال
protected static ?string $navigationIcon = 'heroicon-o-truck';
public static function form(Form $form): Form
{
return $form
->schema([
// بخش ۱: اطلاعات مسیر و وضعیت
Forms\Components\Section::make('Route & Status Info')
->schema([
Forms\Components\Select::make('user_id')
->relationship('user', 'name')
->searchable()
->preload()
->required(),
Forms\Components\TextInput::make('awb_no')
->required()
->unique(ignoreRecord: true)
->label('AWB No.'),
Forms\Components\Select::make('direction')
->options(['Outbound' => 'Outbound', 'Inbound' => 'Inbound'])
->required(),
Forms\Components\Select::make('type')
->options(['DOC' => 'DOC', 'NON DOC' => 'NON DOC'])
->required(),
Forms\Components\TextInput::make('status')
->required(),
Forms\Components\TextInput::make('reason_for_export')
->required(),
Forms\Components\TextInput::make('forwarder')
->nullable(),
Forms\Components\TextInput::make('forwarder_track_id')
->nullable(),
])->columns(2),
// بخش ۲: اطلاعات وزن و ابعاد
Forms\Components\Section::make('Weight & Dimensions')
->schema([
Forms\Components\TextInput::make('weight')
->numeric()
->required()
->suffix('kg'),
Forms\Components\TextInput::make('volumetric_weight')
->numeric()
->required()
->suffix('kg'),
Forms\Components\TextInput::make('chargeable_weight')
->numeric()
->required()
->suffix('kg'),
Forms\Components\TextInput::make('dimensions')
->required()
->helperText('e.g. 10x20x30'),
])->columns(2),
// بخش ۳: اطلاعات مالی
Forms\Components\Section::make('Financial Info')
->schema([
Forms\Components\TextInput::make('shipping_price')
->numeric()
->required()
->prefix('درهم'),
Forms\Components\TextInput::make('extra_service')
->numeric()
->default(0)
->prefix('درهم'),
Forms\Components\TextInput::make('packing_cost')
->numeric()
->default(0)
->prefix('درهم'),
Forms\Components\TextInput::make('discount')
->numeric()
->default(0)
->prefix('درهم'),
Forms\Components\TextInput::make('total_fee')
->numeric()
->required()
->prefix('درهم'),
Forms\Components\TextInput::make('net_dirham')
->numeric()
->required()
->prefix('درهم'),
Forms\Components\TextInput::make('net_rial')
->numeric()
->required()
->suffix('ریال'),
])->columns(3),
// بخش ۴: اطلاعات فرستنده
Forms\Components\Section::make('Sender Info')
->schema([
Forms\Components\TextInput::make('sender_name')->required(),
Forms\Components\TextInput::make('sender_company')->required(),
Forms\Components\TextInput::make('sender_phone')->required()->tel(),
Forms\Components\TextInput::make('sender_email')->required()->email(),
Forms\Components\TextInput::make('sender_address')->required(),
Forms\Components\TextInput::make('sender_city')->required(),
Forms\Components\TextInput::make('sender_zip')->required(),
Forms\Components\TextInput::make('sender_id_number')->required(),
])->columns(2),
// بخش ۵: اطلاعات گیرنده
Forms\Components\Section::make('Receiver Info')
->schema([
Forms\Components\TextInput::make('receiver_name')->required(),
Forms\Components\TextInput::make('receiver_company')->required(),
Forms\Components\TextInput::make('receiver_phone')->required()->tel(),
Forms\Components\TextInput::make('receiver_email')->required()->email(),
Forms\Components\TextInput::make('receiver_address')->required(),
Forms\Components\TextInput::make('receiver_city')->required(),
Forms\Components\TextInput::make('receiver_zip')->required(),
Forms\Components\TextInput::make('receiver_id_number')->required(),
])->columns(2),
// بخش ۶: اقلام گمرکی (Repeater)
Forms\Components\Section::make('Customs Items')
->schema([
Forms\Components\Repeater::make('items')
->relationship() // استفاده از رابطه items در مدل Shipment
->schema([
Forms\Components\TextInput::make('row_number')
->required()
->numeric()
->minValue(1)
->maxValue(9)
->label('Row'),
Forms\Components\TextInput::make('description')
->required()
->columnSpan(2),
Forms\Components\TextInput::make('hs_code')
->required()
->label('HS Code'),
Forms\Components\TextInput::make('quantity')
->required()
->numeric(),
Forms\Components\TextInput::make('unit_price')
->required()
->numeric()
->prefix('USD'),
Forms\Components\TextInput::make('total_usd')
->required()
->numeric()
->prefix('USD'),
])->columns(4) // چیدمان ۴ ستونه برای فیلدهای داخل ریپیتر
->maxItems(9) // محدودیت ثبت حداکثر ۹ ردیف مطابق سند
->defaultItems(1)
->reorderable()
->label(''),
])
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('awb_no')
->searchable()
->label('AWB No.')
->sortable(),
Tables\Columns\TextColumn::make('direction')
->badge()
->color(fn (string $state): string => match ($state) {
'Inbound' => 'success',
'Outbound' => 'info',
default => 'gray',
}),
Tables\Columns\TextColumn::make('status')
->badge()
->searchable(),
Tables\Columns\TextColumn::make('sender_name')
->searchable()
->toggleable(),
Tables\Columns\TextColumn::make('receiver_name')
->searchable()
->toggleable(),
Tables\Columns\TextColumn::make('total_fee')
->money('AED')
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->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 [
'index' => Pages\ListShipments::route('/'),
'create' => Pages\CreateShipment::route('/create'),
'edit' => Pages\EditShipment::route('/{record}/edit'),
];
}
}