Added combined unique and default value

This commit is contained in:
dhanabalan
2025-04-08 09:19:53 +05:30
parent f066794bca
commit 4ad7a4e524
3 changed files with 96 additions and 42 deletions

View File

@@ -6,6 +6,7 @@ use App\Filament\Imports\ProductionPlanImporter;
use App\Filament\Resources\ProductionPlanResource\Pages;
use App\Filament\Resources\ProductionPlanResource\RelationManagers;
use App\Models\ProductionPlan;
use App\Models\Shift;
use Carbon\Carbon;
use Filament\Forms;
use Filament\Forms\Form;
@@ -40,6 +41,9 @@ class ProductionPlanResource extends Resource
->required()
// ->nullable()
->reactive()
->default(function () {
return optional(ProductionPlan::latest()->first())->plant_id;
})
->disabled(fn (Get $get) => !empty($get('id')))
// ->afterStateUpdated(fn ($set) => $set('block_name', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
@@ -73,12 +77,16 @@ class ProductionPlanResource extends Resource
->toArray();
})
->reactive()
->default(function () {
$latestShiftId = optional(ProductionPlan::latest()->first())->shift_id;
return optional(Shift::where('id', $latestShiftId)->first())->block_id;
})
//->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();
$getBlock = Shift::where('id', $getShift->shift_id)->first();
if($getBlock->block_id)
{
$set('block_name', $getBlock->block_id);
@@ -113,12 +121,15 @@ class ProductionPlanResource extends Resource
return [];
}
return \App\Models\Shift::where('plant_id', $get('plant_id'))
return Shift::where('plant_id', $get('plant_id'))
->where('block_id', $get('block_name'))
->pluck('name', 'id')
->toArray();
})
->reactive()
->default(function () {
return optional(ProductionPlan::latest()->first())->shift_id;
})
// ->afterStateUpdated(fn ($set) => $set('line_id', null))
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
@@ -167,6 +178,9 @@ class ProductionPlanResource extends Resource
->toArray();
})
->reactive()
// ->default(function () {
// return optional(ProductionPlan::latest()->first())->line_id;
// })
->afterStateUpdated(function ($state, callable $set, callable $get) {
if($get('id'))
{
@@ -223,7 +237,7 @@ class ProductionPlanResource extends Resource
//$currentDate = date('Y-m-d');
$yesterday = date('Y-m-d', strtotime('-1 days'));
$shiftId = \App\Models\Shift::where('id', $get('shift_id'))
$shiftId = Shift::where('id', $get('shift_id'))
->first();
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
@@ -251,7 +265,7 @@ class ProductionPlanResource extends Resource
{
$currentDate = date('Y-m-d');
$shiftId = \App\Models\Shift::where('id', $get('shift_id'))
$shiftId = Shift::where('id', $get('shift_id'))
->first();
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
@@ -285,7 +299,7 @@ class ProductionPlanResource extends Resource
//$currentDate = date('Y-m-d');
$yesterday = date('Y-m-d', strtotime('-1 days'));
$shiftId = \App\Models\Shift::where('id', $get('shift_id'))
$shiftId = Shift::where('id', $get('shift_id'))
->first();
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
@@ -316,7 +330,7 @@ class ProductionPlanResource extends Resource
{
$currentDate = date('Y-m-d');
$shiftId = \App\Models\Shift::where('id', $get('shift_id'))
$shiftId = Shift::where('id', $get('shift_id'))
->first();
[$hRs, $miNs] = explode('.', $shiftId->duration) + [0, 0];
@@ -532,7 +546,8 @@ class ProductionPlanResource extends Resource
])
->headerActions([
ImportAction::make()
->importer(ProductionPlanImporter::class),
->importer(ProductionPlanImporter::class)
->maxRows(100000),
]);
}