Loading foreign key value while update and added restrict production plan if created
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Filament\Resources\ProductionPlanResource\RelationManagers;
|
||||
use App\Models\ProductionPlan;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
@@ -38,6 +39,7 @@ class ProductionPlanResource extends Resource
|
||||
->required()
|
||||
// ->nullable()
|
||||
->reactive()
|
||||
->disabled(fn (Get $get) => !empty($get('id')))
|
||||
// ->afterStateUpdated(fn ($set) => $set('block_name', null))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
@@ -72,8 +74,20 @@ class ProductionPlanResource extends Resource
|
||||
->reactive()
|
||||
//->afterStateUpdated(fn ($set) => $set('shift_id', null))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
if($get('id'))
|
||||
{
|
||||
$getShift = ProductionPlan::where('id', $get('id'))->first();
|
||||
$getBlock = \App\Models\Shift::where('id', $getShift->shift_id)->first();
|
||||
if($getBlock->block_id)
|
||||
{
|
||||
$set('block_name', $getBlock->block_id);
|
||||
$set('ppBlockError', null);
|
||||
}
|
||||
}
|
||||
|
||||
$blockId = $get('block_name');
|
||||
$set('shift_id', null);
|
||||
|
||||
if (!$blockId) {
|
||||
$set('ppBlockError', 'Please select a block first.');
|
||||
return;
|
||||
@@ -105,8 +119,19 @@ class ProductionPlanResource extends Resource
|
||||
->reactive()
|
||||
// ->afterStateUpdated(fn ($set) => $set('line_id', null))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
if($get('id'))
|
||||
{
|
||||
$getShift = ProductionPlan::where('id', $get('id'))->first();
|
||||
if($getShift->shift_id)
|
||||
{
|
||||
$set('shift_id', $getShift->shift_id);
|
||||
$set('ppShiftError', null);
|
||||
}
|
||||
}
|
||||
|
||||
$shiftId = $get('shift_id');
|
||||
$set('line_id', null);
|
||||
|
||||
if (!$shiftId) {
|
||||
$set('ppShiftError', 'Please select a shift first.');
|
||||
return;
|
||||
@@ -141,7 +166,18 @@ class ProductionPlanResource extends Resource
|
||||
})
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
if($get('id'))
|
||||
{
|
||||
$getShift = ProductionPlan::where('id', $get('id'))->first();
|
||||
if($getShift->line_id)
|
||||
{
|
||||
$set('line_id', $getShift->line_id);
|
||||
$set('ppLineError', null);
|
||||
}
|
||||
}
|
||||
|
||||
$lineId = $get('line_id');
|
||||
|
||||
if (!$lineId) {
|
||||
$set('ppLineError', 'Please select a line first.');
|
||||
return;
|
||||
@@ -172,19 +208,35 @@ class ProductionPlanResource extends Resource
|
||||
}
|
||||
else
|
||||
{
|
||||
$currentDate = date('Y-m-d');
|
||||
$shiftId = \App\Models\Shift::where('id', $get('shift_id'))
|
||||
->first();
|
||||
|
||||
if($shiftId->start_time > $shiftId->end_time)
|
||||
{
|
||||
$set('ppLineError', 'End time goes tomorrow...');
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$set('ppLineError', 'End time is within today...');
|
||||
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
|
||||
$hRs = (int) $hRs;
|
||||
$miNs = (int) $miNs;
|
||||
|
||||
$totalMinutes = $hRs * 60 + $miNs;
|
||||
|
||||
$from_dt = $currentDate . ' ' . $shiftId->start_time;
|
||||
|
||||
$to_dt = date('Y-m-d H:i:s', strtotime($from_dt . " + $totalMinutes minutes"));
|
||||
|
||||
$currentDateTime = date('Y-m-d H:i:s');
|
||||
|
||||
// Check if current date time is within the range
|
||||
if ($currentDateTime >= $from_dt && $currentDateTime < $to_dt) {
|
||||
//echo "Choosed a valid shift...";
|
||||
// $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
|
||||
$set('ppLineError', null);
|
||||
return;
|
||||
} else {
|
||||
// 'Invalid (From: '.$from_dt.', To: '.$to_dt.')'
|
||||
$set('ppLineError', 'Choosed a invalid shift...');
|
||||
return;
|
||||
}
|
||||
|
||||
// if($shiftId->start_time > $shiftId->end_time)
|
||||
}
|
||||
}
|
||||
$set('ppLineError', null);
|
||||
|
||||
Reference in New Issue
Block a user