Add entry and exit time fields with duration calculation in VehicleEntryResource form #310
@@ -6,6 +6,7 @@ use App\Filament\Resources\VehicleEntryResource\Pages;
|
|||||||
use App\Filament\Resources\VehicleEntryResource\RelationManagers;
|
use App\Filament\Resources\VehicleEntryResource\RelationManagers;
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
use App\Models\VehicleEntry;
|
use App\Models\VehicleEntry;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Filament\Facades\Filament;
|
use Filament\Facades\Filament;
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
@@ -40,12 +41,36 @@ class VehicleEntryResource extends Resource
|
|||||||
->required(),
|
->required(),
|
||||||
Forms\Components\DateTimePicker::make('entry_time')
|
Forms\Components\DateTimePicker::make('entry_time')
|
||||||
->label('Entry Time')
|
->label('Entry Time')
|
||||||
->required(),
|
->required()
|
||||||
|
->afterStateUpdated(function ($state, callable $get, callable $set) {
|
||||||
|
$exitTime = $get('exit_time');
|
||||||
|
|
||||||
|
if ($state && $exitTime) {
|
||||||
|
$duration = Carbon::parse($exitTime)
|
||||||
|
->diff(Carbon::parse($state))
|
||||||
|
->format('%H:%I:%S');
|
||||||
|
|
||||||
|
$set('duration', $duration);
|
||||||
|
}
|
||||||
|
}),
|
||||||
Forms\Components\DateTimePicker::make('exit_time')
|
Forms\Components\DateTimePicker::make('exit_time')
|
||||||
->label('Exit Time')
|
->label('Exit Time')
|
||||||
->required(),
|
->required()
|
||||||
|
->reactive()
|
||||||
|
->afterStateUpdated(function ($state, callable $get, callable $set) {
|
||||||
|
$entryTime = $get('entry_time');
|
||||||
|
|
||||||
|
if ($state && $entryTime) {
|
||||||
|
$duration = Carbon::parse($state)
|
||||||
|
->diff(Carbon::parse($entryTime))
|
||||||
|
->format('%H:%I:%S');
|
||||||
|
|
||||||
|
$set('duration', $duration);
|
||||||
|
}
|
||||||
|
}),
|
||||||
Forms\Components\TextInput::make('duration')
|
Forms\Components\TextInput::make('duration')
|
||||||
->label('Duration')
|
->label('Duration')
|
||||||
|
->readOnly()
|
||||||
->required(),
|
->required(),
|
||||||
Forms\Components\TextInput::make('type')
|
Forms\Components\TextInput::make('type')
|
||||||
->label('Type')
|
->label('Type')
|
||||||
|
|||||||
Reference in New Issue
Block a user