ifnex/04_Laravel/app/Filament/Resources/ShipmentResource/RelationManagers/TrackingEventsRelationManager.php
Kazem Alghasi c74924d3aa feat(shipment): implement status history tracking and rate import improvements
Introduce a shipment status history system to audit status changes,
including the reason for change and the user responsible. This includes
a new `ShipmentStatusHistory` model and a bulk action in the Filament
ShipmentResource to transition statuses.

Enhance the rate import workflow by adding a downloadable Excel
template and refactoring the `ImportRatesPage` to use the modern
Filament form schema.

- Add `ShipmentStatusHistory` model and migration
- Add bulk `changeStatus` action to `ShipmentResource`
- Add `source` field to tracking events
- Implement `ShippingRatesTemplateExport` for rate template downloads
- Refactor `ImportRatesPage` form implementation and UI
- Add `statusHistories` relationship to `Shipment` model
2026-08-24 03:40:13 +03:30

81 lines
3.0 KiB
PHP

<?php
namespace App\Filament\Resources\ShipmentResource\RelationManagers;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;
class TrackingEventsRelationManager extends RelationManager
{
protected static string $relationship = 'trackingEvents';
protected static ?string $title = 'Tracking Events';
protected static ?string $icon = 'heroicon-o-clock';
public function form(Form $form): Form
{
return $form->schema([
Forms\Components\DatePicker::make('event_date')
->required()
->default(now())
->label('Event Date'),
Forms\Components\TimePicker::make('event_time')
->required()
->default(now())
->label('Event Time'),
Forms\Components\TextInput::make('location')->nullable()->label('Location'),
Forms\Components\Select::make('source')
->options([
'manual' => 'دستی',
'api' => 'API',
'system' => 'سیستم',
])
->default('manual')
->label('منبع'),
Forms\Components\TextInput::make('event_description')->required()->label('Event Description'),
Forms\Components\Select::make('delivery_status')
->options([
'processed' => 'Processed',
'picked_up' => 'Picked Up',
'in_transit' => 'In Transit',
'out_for_delivery' => 'Out For Delivery',
'failed' => 'Failed',
'delivered' => 'Delivered',
'returned' => 'Returned',
])
->nullable()
->label('Delivery Status'),
]);
}
public function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('event_date')->date()->label('Date')->sortable(),
Tables\Columns\TextColumn::make('event_time')->time()->label('Time'),
Tables\Columns\TextColumn::make('location')->label('Location'),
Tables\Columns\TextColumn::make('event_description')->label('Description')->limit(60),
Tables\Columns\TextColumn::make('delivery_status')->badge()->label('Status'),
Tables\Columns\TextColumn::make('source')->badge()->label('Source'),
])
->defaultSort('event_date', 'desc')
->headerActions([
Tables\Actions\CreateAction::make(),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
}