Added Auto focus and restrict duplicate shift name and invalid duration
This commit is contained in:
@@ -97,6 +97,7 @@ class ShiftResource extends Resource
|
|||||||
->hintColor('danger'),
|
->hintColor('danger'),
|
||||||
Forms\Components\TextInput::make('name')
|
Forms\Components\TextInput::make('name')
|
||||||
->placeholder('Scan the valid name')
|
->placeholder('Scan the valid name')
|
||||||
|
->autofocus(true)
|
||||||
->required()
|
->required()
|
||||||
->reactive()
|
->reactive()
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
@@ -108,6 +109,17 @@ class ShiftResource extends Resource
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
$exists = Shift::where('plant_id', $get('plant_id'))
|
||||||
|
->where('block_id', $get('block_id'))
|
||||||
|
->where('name', $nameId)
|
||||||
|
->latest()
|
||||||
|
->exists();
|
||||||
|
if ($exists)
|
||||||
|
{
|
||||||
|
$set('start_time', null);
|
||||||
|
$set('sNameError', 'Scanned name already exist.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
$set('sNameError', null);
|
$set('sNameError', null);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -125,15 +137,27 @@ class ShiftResource extends Resource
|
|||||||
// )
|
// )
|
||||||
->reactive()
|
->reactive()
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$nameId = $get('start_time');
|
$startTime = $get('start_time');
|
||||||
// $set('duration', null);
|
$set('duration', null);
|
||||||
$set('end_time', self::calculateEndTime($state, $get('duration')));
|
$set('end_time', self::calculateEndTime($state, $get('duration')));
|
||||||
if (!$nameId) {
|
if (!$startTime) {
|
||||||
$set('sStartTimeError', 'Choose the valid start time.');
|
$set('sStartTimeError', 'Choose the valid start time.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
$exists = Shift::where('plant_id', $get('plant_id'))
|
||||||
|
->where('block_id', $get('block_id'))
|
||||||
|
->where('name', $get('name'))
|
||||||
|
->latest()
|
||||||
|
->exists();
|
||||||
|
if ($exists)
|
||||||
|
{
|
||||||
|
$set('start_time', null);
|
||||||
|
$set('sStartTimeError', null);
|
||||||
|
$set('sNameError', 'Scanned name already exist.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
$set('sStartTimeError', null);
|
$set('sStartTimeError', null);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -167,6 +191,15 @@ class ShiftResource extends Resource
|
|||||||
$hRs = (int) $hRs;
|
$hRs = (int) $hRs;
|
||||||
$miNs = (int) $miNs;
|
$miNs = (int) $miNs;
|
||||||
|
|
||||||
|
$set('duration', $hRs.'.'.$miNs);
|
||||||
|
|
||||||
|
if ($miNs > 60) {
|
||||||
|
$set('sDurationError', 'Minutes exceeds 1 hour.');
|
||||||
|
$set('duration', null);
|
||||||
|
$set('end_time', null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$totalMinutes = $hRs * 60 + $miNs;
|
$totalMinutes = $hRs * 60 + $miNs;
|
||||||
|
|
||||||
if ($totalMinutes > 1440) {
|
if ($totalMinutes > 1440) {
|
||||||
@@ -212,8 +245,6 @@ class ShiftResource extends Resource
|
|||||||
])
|
])
|
||||||
->columns(2),
|
->columns(2),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function table(Table $table): Table
|
public static function table(Table $table): Table
|
||||||
|
|||||||
Reference in New Issue
Block a user