ranjith-dev #499

Merged
jothi merged 7 commits from ranjith-dev into master 2026-04-02 12:25:47 +00:00
8 changed files with 457 additions and 142 deletions

View File

@@ -211,9 +211,9 @@ class MotorTestingMasterImporter extends Importer
->rules(['required']),
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('Plant')
->exampleHeader('Plant Code')
->example(['1000', '1010', '1020'])
->label('Plant')
->label('Plant Code')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('created_by')

View File

@@ -19,6 +19,7 @@ use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Validation\Rule;
class ConfigurationResource extends Resource
{
@@ -107,7 +108,16 @@ class ConfigurationResource extends Resource
->required(),
Forms\Components\TextInput::make('c_value')
->label('Value')
->required(),
->required()
->rule(function (callable $get) {
return Rule::unique('configurations', 'c_value')
->where('plant_id', $get('plant_id'))
->where('line_id', $get('line_id'))
->where('c_type', $get('c_type'))
->where('c_group', $get('c_group'))
->where('c_name', $get('c_name'))
->ignore($get('id')); // Ignore current record during updates
}),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),

View File

@@ -42,9 +42,10 @@ class MotorTestingMasterResource extends Resource
return $form
->schema([
Forms\Components\Select::make('plant_id')
->label('Plant')
->label('Plant Name')
->relationship('plant', 'name')
->required()
->searchable()
->reactive()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
@@ -64,6 +65,8 @@ class MotorTestingMasterResource extends Resource
} else {
$set('mTmError', null);
}
$set('updated_by', Filament::auth()->user()?->name);
})
->extraAttributes(fn ($get) => [
'class' => $get('mTmError') ? 'border-red-500' : '',
@@ -74,6 +77,9 @@ class MotorTestingMasterResource extends Resource
->label('Routine Test Time')
->default('00:40:00')
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
})
->reactive(),
Forms\Components\Select::make('item_id')
->label('Item Code')
@@ -84,13 +90,27 @@ class MotorTestingMasterResource extends Resource
return [];
}
return Item::where('plant_id', $plantId)
->pluck('code', 'id')
->toArray();
if (! $get('id')) {
// whereHas
return Item::where('plant_id', $plantId)->whereDoesntHave('motorTestingMasters')->pluck('code', 'id');
} else {
$itemId = MotorTestingMaster::where('id', $get('id'))->first()?->item_id;
return Item::where('plant_id', $plantId)
->where(function ($query) use ($itemId) {
$query->whereDoesntHave('motorTestingMasters')
->orWhere('id', $itemId);
})
->pluck('code', 'id');
}
// return Item::where('plant_id', $plantId)->pluck('code', 'id')->toArray();
})
->required()
->searchable()
->reactive()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
})
->rule(function (callable $get) {
return Rule::unique('motor_testing_masters', 'item_id')
->where('plant_id', $get('plant_id'))
@@ -122,6 +142,8 @@ class MotorTestingMasterResource extends Resource
}
$set('iCodeError', null);
}
$set('updated_by', Filament::auth()->user()?->name);
})
->extraAttributes(fn ($get) => [
'class' => $get('iCodeError') ? 'border-red-500' : '',
@@ -138,6 +160,9 @@ class MotorTestingMasterResource extends Resource
->selectablePlaceholder(false)
->default(1)
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
})
->reactive(),
Forms\Components\Select::make('phase')
->label('Phase')
@@ -159,35 +184,57 @@ class MotorTestingMasterResource extends Resource
})
->selectablePlaceholder(false)
->afterStateUpdated(function ($state, callable $set, callable $get) {
if ($state == 'Single' && $get('connection') == 'Star-Delta') {
$set('phase', 'Three');
}
$set('updated_by', Filament::auth()->user()?->name);
})
->default('Single')
->required()
->reactive(),
Forms\Components\TextInput::make('hp')
->label('HP')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('kw')
->label('KW')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('volt')
->label('Volt')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('current')
->label('Current')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('rpm')
->label('RPM')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('torque')
->label('Torque')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('frequency')
->label('Frequency')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\Select::make('connection')
->label('Connection')
->selectablePlaceholder(false)
@@ -210,12 +257,17 @@ class MotorTestingMasterResource extends Resource
if ($state == 'Star-Delta') {
$set('phase', 'Three');
}
$set('updated_by', Filament::auth()->user()?->name);
})
->required()
->default('Star')
->reactive(),
Forms\Components\TextInput::make('ins_res_limit')
->label('Insulation Resistance Limit')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\Select::make('ins_res_type')
->label('Insulation Resistance Type')
@@ -236,55 +288,106 @@ class MotorTestingMasterResource extends Resource
->toArray();
}
})
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('res_ry_ll')
->label('Resistance RY LL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('res_ry_ul')
->label('Resistance RY UL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('res_yb_ll')
->label('Resistance YB LL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('res_yb_ul')
->label('Resistance YB UL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('res_br_ll')
->label('Resistance BR LL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('res_br_ul')
->label('Resistance BR UL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('lock_volt_limit')
->label('Lock Volt Limit')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('leak_cur_limit')
->label('Leakage Current Limit')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('lock_cur_ll')
->label('Lock Current LL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('lock_cur_ul')
->label('Lock Current UL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('noload_cur_ll')
->label('No Load Current LL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('noload_cur_ul')
->label('No Load Current UL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('noload_pow_ll')
->label('No Load Power LL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('noload_pow_ul')
->label('No Load Power UL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('noload_spd_ll')
->label('No Load Speed LL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('noload_spd_ul')
->label('No Load Speed UL')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\Hidden::make('created_by')
->default(fn () => Filament::auth()->user()?->name)
->required(),
@@ -311,7 +414,7 @@ class MotorTestingMasterResource extends Resource
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant.name')
->label('Plant')
->label('Plant Name')
->searchable()
->alignCenter()
->sortable(),
@@ -458,17 +561,26 @@ class MotorTestingMasterResource extends Resource
->label('Advanced Filters')
->form([
Select::make('Plant')
->label('Select Plant')
->label('Search by Plant Name')
->nullable()
->searchable()
->reactive()
// ->options(function () {
// return Plant::pluck('name', 'id');
// })
->options(function (callable $get) {
$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();
if ($userHas && strlen($userHas) > 0) {
return Plant::where('id', $userHas)->pluck('name', 'id')->toArray();
} else {
return Plant::whereHas('motorTestingMasters', function ($query) {
$query->whereNotNull('id');
})->orderBy('code')->pluck('name', 'id');
}
// return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('Item', null);
$set('isi_type', null);
@@ -681,7 +793,7 @@ class MotorTestingMasterResource extends Resource
$indicators = [];
if (! empty($data['Plant'])) {
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
$indicators[] = 'Plant Name: '.Plant::where('id', $data['Plant'])->value('name');
} else {
$userHas = Filament::auth()->user()->plant_id;

View File

@@ -728,6 +728,7 @@ class ProcessOrderResource extends Resource
if ($uploaded instanceof TemporaryUploadedFile) {
$originalName = $uploaded->getClientOriginalName();
$path = 'uploads/ProcessOrder/'.$originalName;
$processOrder = trim($get('process_order'));
// Check if file already exists
if (Storage::disk('local')->exists($path)) {
@@ -765,34 +766,34 @@ class ProcessOrderResource extends Resource
}
// Get the value of process_order field
$processOrder = trim($get('process_order'));
if ($batchId != $processOrder) {
Notification::make()
->title('Mismatch')
->body("Batch ID ($batchId) does not match Process Order ($processOrder)")
->danger()
->send();
return;
}
// if ($batchId != $processOrder) {
// Notification::make()
// ->title('Mismatch')
// ->body("Batch ID ($batchId) does not match Process Order ($processOrder)")
// ->danger()
// ->send();
if ($batchId == $processOrder) {
// return;
// }
// if ($batchId == $processOrder) {
// If batch matches, store the PDF permanently
$storedPath = $uploaded->storeAs(
'uploads/ProcessOrder',
$originalName,
$processOrder,
'local'
);
Notification::make()
->title('Success')
->body("Batch ID matches Process Order: $batchId. PDF uploaded successfully.")
->body("Process Order: $processOrder. PDF uploaded successfully.")
->success()
->send();
return;
}
// }
}
} else {
Notification::make()

View File

@@ -832,7 +832,7 @@ class StickerMasterResource extends Resource
$indicators = [];
if (! empty($data['Plant'])) {
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
$indicators[] = 'Plant Name: '.Plant::where('id', $data['Plant'])->value('name');
} else {
$userHas = Filament::auth()->user()->plant_id;

View File

@@ -56,8 +56,9 @@ class TestingPanelReadingResource extends Resource
return $form
->schema([
Forms\Components\Select::make('plant_id')
->label('Plant')
->label('Plant Name')
->relationship('plant', 'name')
->searchable()
->required()
->reactive()
->options(function (callable $get) {
@@ -73,17 +74,19 @@ class TestingPanelReadingResource extends Resource
$plantId = $get('plant_id');
if (! $plantId) {
$set('line_id', null);
$set('item_id', null);
$set('motor_testing_master_id', null);
$set('machine_id', null);
$set('tPrError', 'Please select a plant first.');
return;
} else {
$set('line_id', null);
$set('item_id', null);
$set('motor_testing_master_id', null);
$set('machine_id', null);
$set('tPrError', null);
}
$set('updated_by', Filament::auth()->user()?->name);
})
->extraAttributes(fn ($get) => [
'class' => $get('tPrError') ? 'border-red-500' : '',
@@ -91,8 +94,9 @@ class TestingPanelReadingResource extends Resource
->hint(fn ($get) => $get('tPrError') ? $get('tPrError') : null)
->hintColor('danger'),
Forms\Components\Select::make('line_id')
->label('Line')
->label('Line Name')
->relationship('line', 'name')
->searchable()
->options(function (callable $get) {
$plantId = $get('plant_id');
if (! $plantId) {
@@ -109,10 +113,14 @@ class TestingPanelReadingResource extends Resource
->disabled(fn (Get $get) => ! empty($get('id')))
->required()
->reactive()
->afterStateUpdated(fn (callable $set) => $set('item_id', null)),
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('motor_testing_master_id', null);
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\Select::make('machine_id')
->label('Machine')
->relationship('machine', 'name')
->label('Work Center')
->relationship('machine', 'work_center')
->searchable()
->options(function (callable $get) {
$lineId = $get('line_id');
if (! $lineId) {
@@ -121,7 +129,7 @@ class TestingPanelReadingResource extends Resource
// Only show machines for the selected line
return Machine::where('line_id', $lineId)
->pluck('name', 'id')
->pluck('work_center', 'id')
->toArray();
})
->default(function () {
@@ -129,7 +137,10 @@ class TestingPanelReadingResource extends Resource
})
->disabled(fn (Get $get) => ! empty($get('id')))
->required()
->reactive(),
->reactive()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\Select::make('motor_testing_master_id')
->label('Item Code')
// ->relationship('motorTestingMaster', 'item.code')
@@ -163,101 +174,234 @@ class TestingPanelReadingResource extends Resource
// )
->required()
->searchable()
->reactive(),
->reactive()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('output')
->label('Output')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('serial_number')
->label('Serial Number')
->required(),
->required()
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('winded_serial_number')
->label('Winded Serial Number'),
->label('Winded Serial Number')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('before_fr_volt')
->label('Before FR Volt'),
->label('Before FR Volt')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('before_fr_cur')
->label('Before FR Current'),
->label('Before FR Current')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('before_fr_pow')
->label('Before FR Power'),
->label('Before FR Power')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('before_fr_res_ry')
->label('Before FR Resistance RY'),
->label('Before FR Resistance RY')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('before_fr_res_yb')
->label('Before FR Resistance YB'),
->label('Before FR Resistance YB')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('before_fr_res_br')
->label('Before FR Resistance BR'),
->label('Before FR Resistance BR')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('before_fr_ir')
->label('Before FR IR'),
->label('Before FR IR')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('before_fr_ir_r')
->label('Before FR IR R'),
->label('Before FR IR R')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('before_fr_ir_y')
->label('Before FR IR Y'),
->label('Before FR IR Y')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('before_fr_ir_b')
->label('Before FR IR B'),
->label('Before FR IR B')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('before_fr_freq')
->label('Before FR Frequency'),
->label('Before FR Frequency')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('before_fr_speed')
->label('Before FR Speed'),
->label('Before FR Speed')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('after_fr_vol')
->label('After FR Volt'),
->label('After FR Volt')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('after_fr_cur')
->label('After FR Current'),
->label('After FR Current')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('after_fr_pow')
->label('After FR Power'),
->label('After FR Power')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('after_fr_ir_hot')
->label('After FR IR Hot'),
->label('After FR IR Hot')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('after_fr_ir_hot_r')
->label('After FR IR Hot R'),
->label('After FR IR Hot R')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('after_fr_ir_hot_y')
->label('After FR IR Hot Y'),
->label('After FR IR Hot Y')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('after_fr_ir_hot_b')
->label('After FR IR Hot B'),
->label('After FR IR Hot B')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('after_fr_ir_cool')
->label('After FR IR Cool'),
->label('After FR IR Cool')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('after_fr_ir_cool_r')
->label('After FR IR Cool R'),
->label('After FR IR Cool R')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('after_fr_ir_cool_y')
->label('After FR IR Cool Y'),
->label('After FR IR Cool Y')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('after_fr_ir_cool_b')
->label('After FR IR Cool B'),
->label('After FR IR Cool B')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('after_fr_freq')
->label('After FR Frequency'),
->label('After FR Frequency')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('after_fr_speed')
->label('After FR Speed'),
->label('After FR Speed')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('after_fr_leak_cur')
->label('After FR Leak Current'),
->label('After FR Leak Current')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('locked_rt_volt')
->label('Locked RT Volt'),
->label('Locked RT Volt')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('locked_rt_cur')
->label('Locked RT Current'),
->label('Locked RT Current')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('locked_rt_pow')
->label('Locked RT Power'),
->label('Locked RT Power')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('no_load_pickup_volt')
->label('No Load Pickup Volt'),
->label('No Load Pickup Volt')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('room_temperature')
->label('Room Temperature'),
->label('Room Temperature')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('hv_test')
->label('High Voltage Test'),
->label('High Voltage Test')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('batch_number')
->label('Batch Number'),
->label('Batch Number')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('batch_count')
->label('Batch Count')
->default('0'),
->default('0')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('result')
->label('Result'),
->label('Result')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('remark')
->label('Remark'),
->label('Remark')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('rework_count')
->label('Rework Count')
->default('0'),
->default('0')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('update_count')
->label('Update Count')
->default('0'),
->default('0')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('output_flag')
->label('Output Flag')
->default('0'),
->default('0')
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
$set('updated_by', Filament::auth()->user()?->name);
}),
Forms\Components\TextInput::make('tested_by')
->label('Tested By'),
->label('Tested By')
->default(fn () => Filament::auth()->user()?->name)
->required(),
Forms\Components\TextInput::make('updated_by')
->label('Updated By'),
->label('Updated By')
->default(fn () => Filament::auth()->user()?->name)
->required(),
Forms\Components\TextInput::make('id')
->hidden()
->readOnly(),
@@ -283,17 +427,20 @@ class TestingPanelReadingResource extends Resource
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('plant.name')
->label('Plant')
->label('Plant Name')
->alignCenter(),
Tables\Columns\TextColumn::make('line.name')
->label('Line')
->label('Line Name')
->alignCenter(),
Tables\Columns\TextColumn::make('machine.name')
->label('Machine')
Tables\Columns\TextColumn::make('machine.work_center')
->label('Work Center')
->alignCenter(),
Tables\Columns\TextColumn::make('motorTestingMaster.item.code')
->label('Item Code')
->alignCenter(),
Tables\Columns\TextColumn::make('motorTestingMaster.subassembly_code')
->label('Subassembly Code')
->alignCenter(),
Tables\Columns\TextColumn::make('motorTestingMaster.item.description')
->label('Model')
->alignCenter(),
@@ -477,13 +624,22 @@ class TestingPanelReadingResource extends Resource
->label('Advanced Filters')
->form([
Select::make('Plant')
->label('Select Plant')
->label('Search by Plant Name')
->searchable()
->nullable()
->options(function () {
// return Plant::pluck('name', 'id');
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return Plant::where('id', $userHas)->pluck('name', 'id')->toArray();
} else {
return Plant::whereHas('testingPanelReadings', function ($query) {
$query->whereNotNull('id');
})->orderBy('code')->pluck('name', '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();
})
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
@@ -492,7 +648,8 @@ class TestingPanelReadingResource extends Resource
}),
Select::make('Line')
->label('Select Line')
->label('Search by Line Name')
->searchable()
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
@@ -507,11 +664,11 @@ class TestingPanelReadingResource extends Resource
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('item_code', null);
}),
Select::make('item_code')
->label('Item Code')
->label('Search by Item Code')
->searchable()
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
if ($plantId) {
@@ -520,15 +677,20 @@ class TestingPanelReadingResource extends Resource
->pluck('code', 'id')
->toArray();
} else {
return Item::whereHas('motorTestingMasters')
->pluck('code', 'id')
->toArray();
return [];
// return Item::whereHas('motorTestingMasters')
// ->pluck('code', 'id')
// ->toArray();
}
// return [];
})
->reactive(),
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('item_description', null);
}),
Select::make('machine_name')
->label('Machine Name')
->label('Search by Work Center')
->searchable()
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
$lineId = $get('Line');
@@ -539,30 +701,43 @@ class TestingPanelReadingResource extends Resource
return Machine::where('plant_id', $plantId)
->where('line_id', $lineId)
->pluck('name', 'id')
->pluck('work_center', 'id')
->toArray();
})
->reactive(),
TextInput::make('serial_number')
->label('Serial Number')
->reactive()
->placeholder(placeholder: 'Enter Serial Number'),
->placeholder('Enter Serial Number'),
Select::make('item_description')
->label('Model')
->searchable()
->options(function (callable $get) {
$plantId = $get('Plant');
$query = Item::query();
// $query = Item::query();
// if ($plantId) {
// $query->where('plant_id', $plantId);
// }
$plantId = $get('Plant');
if ($plantId) {
$query->where('plant_id', $plantId);
return Item::where('plant_id', $plantId)
->whereHas('motorTestingMasters')
->pluck('description', 'id')
->toArray();
} else {
return [];
// return Item::whereHas('motorTestingMasters')
// ->pluck('description', 'id')
// ->toArray();
}
return $query->pluck('description', 'description')->toArray();
//return $query->pluck('description', 'description')->toArray();
})
->reactive(),
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('item_code', null);
}),
Select::make('output')
->label('Output')
->searchable()
@@ -702,12 +877,23 @@ class TestingPanelReadingResource extends Resource
}
if (! empty($data['item_description'])) {
$item = Item::where('description', $data['item_description'])->first();
$itemId = $data['item_description']; // Item::where('description', $data['item_description'])->first()?->id ?? null;
if ($item) {
$query->whereHas('motorTestingMaster', function ($subQuery) use ($item) {
$subQuery->where('item_id', $item->id);
});
if ($itemId) { // $item
$mastId = MotorTestingMaster::where('item_id', $itemId)->first()?->id ?? null;
if ($mastId) { // $item
$motId = TestingPanelReading::where('motor_testing_master_id', $mastId)->first()?->id ?? null;
if ($motId) { // $item
$query->where('motor_testing_master_id', $mastId);
// $query->whereHas('motorTestingMaster', function ($subQuery) use ($itemId) {
// $subQuery->where('item_id', $itemId); //$item->id
// });
} else {
$query->whereRaw('1 = 0');
}
} else {
$query->whereRaw('1 = 0');
}
} else {
$query->whereRaw('1 = 0');
}
@@ -756,7 +942,7 @@ class TestingPanelReadingResource extends Resource
$indicators = [];
if (! empty($data['Plant'])) {
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
$indicators[] = 'Plant Name: '.Plant::where('id', $data['Plant'])->value('name');
} else {
$userHas = Filament::auth()->user()->plant_id;
@@ -765,26 +951,27 @@ class TestingPanelReadingResource extends Resource
}
}
if (! empty($data['Line'])) {
$indicators[] = 'Line: '.Line::where('id', $data['Line'])->value('name');
$indicators[] = 'Line Name: '.Line::where('id', $data['Line'])->value('name');
}
if (! empty($data['item_code'])) {
$indicators[] = 'Item Code: '.Item::where('id', $data['item_code'])->value('code');
}
if (! empty($data['machine_name'])) {
$indicators[] = 'Machine: '.Machine::where('id', $data['machine_name'])->value('name');
$indicators[] = 'Work Center: '.Machine::where('id', $data['machine_name'])->value('work_center');
}
if (! empty($data['output'])) {
$indicators[] = 'Output: '.$data['output'];
}
if (! empty($data['item_description'])) {
$indicators[] = 'Model: '.$data['item_description'];
$item = Item::where('id', $data['item_description'])->first()?->description ?? null;
$indicators[] = 'Model: '.$item;
}
// if (!empty($data['phase'])) {
// $indicators[] = 'Phase: ' . $data['phase'];
// }
// if (!empty($data['connection'])) {
// $indicators[] = 'Connection: ' . $data['connection'];
// }
if (!empty($data['connection'])) {
$indicators[] = 'Connection: ' . $data['connection'];
}
if (! empty($data['remark'])) {
$indicators[] = 'Remark: '.$data['remark'];
}

View File

@@ -41,7 +41,7 @@ class Item extends Model
public function motorTestingMasters()
{
return $this->hasMany(MotorTestingMaster::class);
return $this->hasMany(MotorTestingMaster::class, 'item_id', 'id');
}
public function testingPanelReadings()

View File

@@ -63,6 +63,11 @@ class Plant extends Model
return $this->hasMany(QualityValidation::class, 'plant_id', 'id');
}
public function motorTestingMasters()
{
return $this->hasMany(MotorTestingMaster::class, 'plant_id', 'id');
}
public function testingPanelReadings()
{
return $this->hasMany(TestingPanelReading::class, 'plant_id', 'id');