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 App\Models\ProductionPlan;
|
||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
|
use Filament\Forms\Get;
|
||||||
use Filament\Resources\Resource;
|
use Filament\Resources\Resource;
|
||||||
use Filament\Tables;
|
use Filament\Tables;
|
||||||
use Filament\Tables\Actions\ImportAction;
|
use Filament\Tables\Actions\ImportAction;
|
||||||
@@ -38,6 +39,7 @@ class ProductionPlanResource extends Resource
|
|||||||
->required()
|
->required()
|
||||||
// ->nullable()
|
// ->nullable()
|
||||||
->reactive()
|
->reactive()
|
||||||
|
->disabled(fn (Get $get) => !empty($get('id')))
|
||||||
// ->afterStateUpdated(fn ($set) => $set('block_name', null))
|
// ->afterStateUpdated(fn ($set) => $set('block_name', null))
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
@@ -72,8 +74,20 @@ class ProductionPlanResource extends Resource
|
|||||||
->reactive()
|
->reactive()
|
||||||
//->afterStateUpdated(fn ($set) => $set('shift_id', null))
|
//->afterStateUpdated(fn ($set) => $set('shift_id', null))
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->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');
|
$blockId = $get('block_name');
|
||||||
$set('shift_id', null);
|
$set('shift_id', null);
|
||||||
|
|
||||||
if (!$blockId) {
|
if (!$blockId) {
|
||||||
$set('ppBlockError', 'Please select a block first.');
|
$set('ppBlockError', 'Please select a block first.');
|
||||||
return;
|
return;
|
||||||
@@ -105,8 +119,19 @@ class ProductionPlanResource extends Resource
|
|||||||
->reactive()
|
->reactive()
|
||||||
// ->afterStateUpdated(fn ($set) => $set('line_id', null))
|
// ->afterStateUpdated(fn ($set) => $set('line_id', null))
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->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');
|
$shiftId = $get('shift_id');
|
||||||
$set('line_id', null);
|
$set('line_id', null);
|
||||||
|
|
||||||
if (!$shiftId) {
|
if (!$shiftId) {
|
||||||
$set('ppShiftError', 'Please select a shift first.');
|
$set('ppShiftError', 'Please select a shift first.');
|
||||||
return;
|
return;
|
||||||
@@ -141,7 +166,18 @@ class ProductionPlanResource extends Resource
|
|||||||
})
|
})
|
||||||
->reactive()
|
->reactive()
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->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');
|
$lineId = $get('line_id');
|
||||||
|
|
||||||
if (!$lineId) {
|
if (!$lineId) {
|
||||||
$set('ppLineError', 'Please select a line first.');
|
$set('ppLineError', 'Please select a line first.');
|
||||||
return;
|
return;
|
||||||
@@ -172,19 +208,35 @@ class ProductionPlanResource extends Resource
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
$currentDate = date('Y-m-d');
|
||||||
$shiftId = \App\Models\Shift::where('id', $get('shift_id'))
|
$shiftId = \App\Models\Shift::where('id', $get('shift_id'))
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if($shiftId->start_time > $shiftId->end_time)
|
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
|
||||||
{
|
$hRs = (int) $hRs;
|
||||||
$set('ppLineError', 'End time goes tomorrow...');
|
$miNs = (int) $miNs;
|
||||||
return;
|
|
||||||
}
|
$totalMinutes = $hRs * 60 + $miNs;
|
||||||
else
|
|
||||||
{
|
$from_dt = $currentDate . ' ' . $shiftId->start_time;
|
||||||
$set('ppLineError', 'End time is within today...');
|
|
||||||
|
$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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if($shiftId->start_time > $shiftId->end_time)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$set('ppLineError', null);
|
$set('ppLineError', null);
|
||||||
|
|||||||
Reference in New Issue
Block a user