Compare commits
4 Commits
cc7fd5b16d
...
0adb82afcf
| Author | SHA1 | Date | |
|---|---|---|---|
| 0adb82afcf | |||
|
|
018c51b75b | ||
|
|
7c086ceb28 | ||
|
|
67ffbf68fd |
@@ -43,11 +43,15 @@ class ProductCharacteristicsMasterResource extends Resource
|
|||||||
Forms\Components\Select::make('plant_id')
|
Forms\Components\Select::make('plant_id')
|
||||||
->label('Plant')
|
->label('Plant')
|
||||||
->relationship('plant', 'name')
|
->relationship('plant', 'name')
|
||||||
|
->searchable()
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$userHas = Filament::auth()->user()->plant_id;
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
|
|
||||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||||
})
|
})
|
||||||
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
|
})
|
||||||
->reactive()
|
->reactive()
|
||||||
->required(),
|
->required(),
|
||||||
Forms\Components\Select::make('item_id')
|
Forms\Components\Select::make('item_id')
|
||||||
@@ -63,10 +67,14 @@ class ProductCharacteristicsMasterResource extends Resource
|
|||||||
|
|
||||||
return \App\Models\Item::where('plant_id', $plantId)->pluck('code', 'id');
|
return \App\Models\Item::where('plant_id', $plantId)->pluck('code', 'id');
|
||||||
})
|
})
|
||||||
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
|
})
|
||||||
->required(),
|
->required(),
|
||||||
Forms\Components\Select::make('line_id')
|
Forms\Components\Select::make('line_id')
|
||||||
->label('Line')
|
->label('Line')
|
||||||
->reactive()
|
->reactive()
|
||||||
|
->searchable()
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
if (empty($plantId)) {
|
if (empty($plantId)) {
|
||||||
@@ -77,10 +85,10 @@ class ProductCharacteristicsMasterResource extends Resource
|
|||||||
})
|
})
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$set('machine_id', null);
|
$set('machine_id', null);
|
||||||
|
|
||||||
if (! $get('work_group_master_id')) {
|
if (! $get('work_group_master_id')) {
|
||||||
$set('machine_id', null);
|
$set('machine_id', null);
|
||||||
}
|
}
|
||||||
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
})
|
})
|
||||||
->required(),
|
->required(),
|
||||||
// ->relationship('line', 'name'),
|
// ->relationship('line', 'name'),
|
||||||
@@ -88,6 +96,7 @@ class ProductCharacteristicsMasterResource extends Resource
|
|||||||
->label('Group Work Center')
|
->label('Group Work Center')
|
||||||
->required()
|
->required()
|
||||||
->reactive()
|
->reactive()
|
||||||
|
->searchable()
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
if (! $get('plant_id') || ! $get('line_id')) {
|
if (! $get('plant_id') || ! $get('line_id')) {
|
||||||
return [];
|
return [];
|
||||||
@@ -107,6 +116,7 @@ class ProductCharacteristicsMasterResource extends Resource
|
|||||||
->disabled(fn (Get $get) => ! empty($get('id')))
|
->disabled(fn (Get $get) => ! empty($get('id')))
|
||||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
$lineId = $get('line_id');
|
$lineId = $get('line_id');
|
||||||
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
if (! $lineId) {
|
if (! $lineId) {
|
||||||
$set('mGroupWorkError', 'Please select a line first.');
|
$set('mGroupWorkError', 'Please select a line first.');
|
||||||
$set('machine_id', null);
|
$set('machine_id', null);
|
||||||
@@ -133,8 +143,8 @@ class ProductCharacteristicsMasterResource extends Resource
|
|||||||
Forms\Components\Select::make('machine_id')
|
Forms\Components\Select::make('machine_id')
|
||||||
->label('Work Center')
|
->label('Work Center')
|
||||||
// ->relationship('machine', 'name'),
|
// ->relationship('machine', 'name'),
|
||||||
->searchable()
|
|
||||||
->reactive()
|
->reactive()
|
||||||
|
->searchable()
|
||||||
->options(function (callable $get) {
|
->options(function (callable $get) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
$lineId = $get('line_id');
|
$lineId = $get('line_id');
|
||||||
@@ -153,6 +163,7 @@ class ProductCharacteristicsMasterResource extends Resource
|
|||||||
if (! $get('plant_id') || ! $get('line_id') || ! $get('work_group_master_id')) {
|
if (! $get('plant_id') || ! $get('line_id') || ! $get('work_group_master_id')) {
|
||||||
$set('machine_id', null);
|
$set('machine_id', null);
|
||||||
}
|
}
|
||||||
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
})
|
})
|
||||||
->required(),
|
->required(),
|
||||||
Forms\Components\Select::make('characteristics_type')
|
Forms\Components\Select::make('characteristics_type')
|
||||||
@@ -162,16 +173,30 @@ class ProductCharacteristicsMasterResource extends Resource
|
|||||||
'Process' => 'Process',
|
'Process' => 'Process',
|
||||||
])
|
])
|
||||||
->reactive()
|
->reactive()
|
||||||
|
->searchable()
|
||||||
|
// ->preload()
|
||||||
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
|
})
|
||||||
->required(),
|
->required(),
|
||||||
Forms\Components\TextInput::make('name')
|
Forms\Components\TextInput::make('name')
|
||||||
->label('Name'),
|
->label('Name')
|
||||||
|
->reactive()
|
||||||
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
|
}),
|
||||||
Forms\Components\Select::make('inspection_type')
|
Forms\Components\Select::make('inspection_type')
|
||||||
->label('Inspection Type')
|
->label('Inspection Type')
|
||||||
|
->searchable()
|
||||||
->options([
|
->options([
|
||||||
'Visual' => 'Visual',
|
'Visual' => 'Visual',
|
||||||
'Value' => 'Value',
|
'Value' => 'Value',
|
||||||
])
|
])
|
||||||
->reactive()
|
->reactive()
|
||||||
|
// ->preload()
|
||||||
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
|
})
|
||||||
->required(),
|
->required(),
|
||||||
// Forms\Components\Select::make('result')
|
// Forms\Components\Select::make('result')
|
||||||
// ->label('Visual Type')
|
// ->label('Visual Type')
|
||||||
@@ -197,7 +222,11 @@ class ProductCharacteristicsMasterResource extends Resource
|
|||||||
->default(0.0)
|
->default(0.0)
|
||||||
->minValue(0.0)
|
->minValue(0.0)
|
||||||
->maxValue(fn (Get $get) => $get('upper') ?? PHP_INT_MAX)
|
->maxValue(fn (Get $get) => $get('upper') ?? PHP_INT_MAX)
|
||||||
->afterStateUpdated(fn ($state, callable $set, callable $get) => $set('middle', ($state + $get('upper')) / 2))
|
// ->afterStateUpdated(fn ($state, callable $set, callable $get) => $set('middle', ($state + $get('upper')) / 2))
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
|
$set('middle', ($state + $get('upper')) / 2);
|
||||||
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
|
})
|
||||||
->visible(fn (callable $get) => $get('inspection_type') == 'Value'),
|
->visible(fn (callable $get) => $get('inspection_type') == 'Value'),
|
||||||
Forms\Components\TextInput::make('upper')
|
Forms\Components\TextInput::make('upper')
|
||||||
->label('Upper')
|
->label('Upper')
|
||||||
@@ -206,7 +235,11 @@ class ProductCharacteristicsMasterResource extends Resource
|
|||||||
->default(0.0)
|
->default(0.0)
|
||||||
->minValue(fn (Get $get) => $get('lower') ?? 0)
|
->minValue(fn (Get $get) => $get('lower') ?? 0)
|
||||||
->maxValue(PHP_INT_MAX)
|
->maxValue(PHP_INT_MAX)
|
||||||
->afterStateUpdated(fn ($state, callable $set, callable $get) => $set('middle', ($get('lower') + $state) / 2))
|
// ->afterStateUpdated(fn ($state, callable $set, callable $get) => $set('middle', ($get('lower') + $state) / 2))
|
||||||
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||||
|
$set('middle', ($get('lower') + $state) / 2);
|
||||||
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
|
})
|
||||||
->visible(fn (callable $get) => $get('inspection_type') == 'Value'),
|
->visible(fn (callable $get) => $get('inspection_type') == 'Value'),
|
||||||
Forms\Components\TextInput::make('middle')
|
Forms\Components\TextInput::make('middle')
|
||||||
->label('Middle')
|
->label('Middle')
|
||||||
@@ -228,12 +261,18 @@ class ProductCharacteristicsMasterResource extends Resource
|
|||||||
// };
|
// };
|
||||||
// })
|
// })
|
||||||
->dehydrateStateUsing(fn ($state, Get $get) => ($get('lower') + $get('upper')) / 2)
|
->dehydrateStateUsing(fn ($state, Get $get) => ($get('lower') + $get('upper')) / 2)
|
||||||
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
|
$set('updated_by', Filament::auth()->user()?->name);
|
||||||
|
})
|
||||||
->visible(fn (callable $get) => $get('inspection_type') == 'Value'),
|
->visible(fn (callable $get) => $get('inspection_type') == 'Value'),
|
||||||
Forms\Components\Hidden::make('created_by')
|
Forms\Components\Hidden::make('created_by')
|
||||||
->label('Created By')
|
->label('Created By')
|
||||||
->default(Filament::auth()->user()?->name),
|
->default(Filament::auth()->user()?->name),
|
||||||
Forms\Components\Hidden::make('updated_by')
|
Forms\Components\Hidden::make('updated_by')
|
||||||
->label('Updated By'),
|
->label('Updated By'),
|
||||||
|
Forms\Components\TextInput::make('id')
|
||||||
|
->hidden()
|
||||||
|
->readOnly(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,27 +15,30 @@ class EditProductCharacteristicsMaster extends EditRecord
|
|||||||
return 'Edit Characteristics'; // This will replace the "New product characteristics master"
|
return 'Edit Characteristics'; // This will replace the "New product characteristics master"
|
||||||
}
|
}
|
||||||
|
|
||||||
public function mount(int|string $record): void
|
// public function mount(int|string $record): void
|
||||||
{
|
// {
|
||||||
parent::mount($record);
|
// parent::mount($record);
|
||||||
|
|
||||||
$model = $this->getRecord(); // actual model instance
|
// $model = $this->getRecord(); // actual model instance
|
||||||
|
|
||||||
// Step 1: Fill the actual saved fields first
|
// // Step 1: Fill the actual saved fields first
|
||||||
$this->form->fill([
|
// $this->form->fill([
|
||||||
'plant_id' => $model->plant_id,
|
// 'plant_id' => $model->plant_id,
|
||||||
'line_id' => $model->line_id,
|
// 'item_id' => $model->item_id,
|
||||||
'item_id' => $model->item_id,
|
// 'line_id' => $model->line_id,
|
||||||
'machine_id' => $model->machine_id,
|
// 'machine_id' => $model->machine_id,
|
||||||
'name' => $model->name,
|
// 'name' => $model->name,
|
||||||
'type' => $model->type,
|
// 'characteristics_type' => $model->characteristics_type,
|
||||||
'upper' => $model->upper,
|
// 'inspection_type' => $model->inspection_type,
|
||||||
'lower' => $model->lower,
|
// // 'type' => $model->type,
|
||||||
'middle' => $model->middle,
|
// 'upper' => $model->upper,
|
||||||
'work_group_master_id' => optional($model->machine)->work_group_master_id,
|
// 'lower' => $model->lower,
|
||||||
]);
|
// 'middle' => $model->middle,
|
||||||
|
// 'created_by' => $model->created_by,
|
||||||
}
|
// 'updated_by' => $model->updated_by,
|
||||||
|
// 'work_group_master_id' => optional($model->machine)->work_group_master_id,
|
||||||
|
// ]);
|
||||||
|
// }
|
||||||
|
|
||||||
protected function getHeaderActions(): array
|
protected function getHeaderActions(): array
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,23 +5,22 @@ namespace App\Models;
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
|
|
||||||
class ProductCharacteristicsMaster extends Model
|
class ProductCharacteristicsMaster extends Model
|
||||||
{
|
{
|
||||||
use SoftDeletes;
|
use SoftDeletes;
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'plant_id',
|
'plant_id',
|
||||||
'line_id',
|
|
||||||
'item_id',
|
'item_id',
|
||||||
|
'line_id',
|
||||||
'work_group_master_id',
|
'work_group_master_id',
|
||||||
'machine_id',
|
'machine_id',
|
||||||
|
'characteristics_type',
|
||||||
'name',
|
'name',
|
||||||
'inspection_type',
|
'inspection_type',
|
||||||
'characteristics_type',
|
|
||||||
'upper',
|
|
||||||
'lower',
|
'lower',
|
||||||
|
'upper',
|
||||||
'middle',
|
'middle',
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
|
|||||||
Reference in New Issue
Block a user