505 lines
22 KiB
PHP
505 lines
22 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Exports\MotorTestingMasterExporter;
|
|
use App\Filament\Imports\MotorTestingMasterImporter;
|
|
use App\Filament\Resources\MotorTestingMasterResource\Pages;
|
|
use App\Filament\Resources\MotorTestingMasterResource\RelationManagers;
|
|
use App\Models\Configuration;
|
|
use App\Models\Item;
|
|
use App\Models\MotorTestingMaster;
|
|
use Filament\Facades\Filament;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Forms\Get;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
use Filament\Tables\Actions\ImportAction;
|
|
use Filament\Tables\Actions\ExportAction;
|
|
use Illuminate\Validation\Rule;
|
|
|
|
class MotorTestingMasterResource extends Resource
|
|
{
|
|
protected static ?string $model = MotorTestingMaster::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
|
|
|
protected static ?string $navigationGroup = 'Testing Panel';
|
|
|
|
protected static ?int $navigationSort = 1;
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
Forms\Components\Select::make('plant_id')
|
|
->label('Plant')
|
|
->relationship('plant', 'name')
|
|
->required()
|
|
->reactive()
|
|
->default(function () {
|
|
return optional(MotorTestingMaster::latest()->first())->plant_id;
|
|
})
|
|
->disabled(fn (Get $get) => !empty($get('id')))
|
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
|
$plantId = $get('plant_id');
|
|
if (!$plantId) {
|
|
$set('mTmError', 'Please select a plant first.');
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
$set('mTmError', null);
|
|
}
|
|
})
|
|
->extraAttributes(fn ($get) => [
|
|
'class' => $get('mTmError') ? 'border-red-500' : '',
|
|
])
|
|
->hint(fn ($get) => $get('mTmError') ? $get('mTmError') : null)
|
|
->hintColor('danger'),
|
|
Forms\Components\TimePicker::make('routine_test_time')
|
|
->label('Routine Test Time')
|
|
->default('00:40:00')
|
|
->required()
|
|
->reactive(),
|
|
Forms\Components\Select::make('item_id')
|
|
->label('Item Code')
|
|
//->relationship('item', 'name')
|
|
->options(function (callable $get) {
|
|
$plantId = $get('plant_id');
|
|
if (!$plantId) {
|
|
return [];
|
|
}
|
|
|
|
return Item::where('plant_id', $plantId)
|
|
->pluck('code', 'id')
|
|
->toArray();
|
|
})
|
|
->required()
|
|
->searchable()
|
|
->reactive()
|
|
->rule(function (callable $get) {
|
|
return Rule::unique('motor_testing_masters', 'item_id')
|
|
->where('plant_id', $get('plant_id'))
|
|
->ignore($get('id')); // Ignore current record during updates
|
|
}),
|
|
Forms\Components\TextInput::make('subassembly_code')
|
|
->label('Subassembly Code')
|
|
->required()
|
|
->placeholder('Scan the valid code')
|
|
->reactive()
|
|
->alphaNum()
|
|
->minLength(6)
|
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
|
$code = $get('subassembly_code');
|
|
// Ensure `linestop_id` is not cleared
|
|
if (!$code) {
|
|
$set('iCodeError', 'Scan the valid Subassembly Code.');
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
if (strlen($code) < 6) {
|
|
$set('iCodeError', 'Subassembly code must be at least 6 digits.');
|
|
return;
|
|
}
|
|
else if (!preg_match('/^[a-zA-Z0-9]{6,}$/', $code)) {
|
|
$set('code',null);
|
|
$set('iCodeError', 'Subassembly code must contain only alpha-numeric characters.');
|
|
return;
|
|
}
|
|
$set('iCodeError', null);
|
|
}
|
|
})
|
|
->extraAttributes(fn ($get) => [
|
|
'class' => $get('iCodeError') ? 'border-red-500' : '',
|
|
])
|
|
->hint(fn ($get) => $get('iCodeError') ? $get('iCodeError') : null)
|
|
->hintColor('danger'),
|
|
|
|
Forms\Components\Select::make('isi_model')
|
|
->label('ISI Model')
|
|
->options([
|
|
1 => 'Yes',
|
|
0 => 'No',
|
|
])
|
|
->selectablePlaceholder(false)
|
|
->default(1)
|
|
->required()
|
|
->reactive(),
|
|
Forms\Components\Select::make('phase')
|
|
->label('Phase')
|
|
->options(function (callable $get) {
|
|
$plantId = $get('plant_id');
|
|
|
|
// if (!$plantId || !$lineId)
|
|
// {
|
|
// return [];
|
|
// }
|
|
|
|
if ($plantId)
|
|
{
|
|
return Configuration::where('plant_id', $plantId)
|
|
->where('c_name', 'MOTOR_PHASE')
|
|
->orderBy('created_at')
|
|
->pluck('c_value', 'c_value')
|
|
->toArray();
|
|
}
|
|
else
|
|
{
|
|
return Configuration::where('c_name', 'MOTOR_PHASE')
|
|
->orderBy('created_at')
|
|
->pluck('c_value', 'c_value')
|
|
->toArray();
|
|
}
|
|
})
|
|
->selectablePlaceholder(false)
|
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
|
|
|
if ($state == 'Single' && $get('connection') == 'Star-Delta') {
|
|
$set('phase', 'Three');
|
|
}
|
|
})
|
|
->default('Single')
|
|
->required()
|
|
->reactive(),
|
|
Forms\Components\TextInput::make('hp')
|
|
->label('HP')
|
|
->required(),
|
|
Forms\Components\TextInput::make('kw')
|
|
->label('KW')
|
|
->required(),
|
|
Forms\Components\TextInput::make('volt')
|
|
->label('Volt')
|
|
->required(),
|
|
Forms\Components\TextInput::make('current')
|
|
->label('Current')
|
|
->required(),
|
|
Forms\Components\TextInput::make('rpm')
|
|
->label('RPM')
|
|
->required(),
|
|
Forms\Components\TextInput::make('torque')
|
|
->label('Torque')
|
|
->required(),
|
|
Forms\Components\TextInput::make('frequency')
|
|
->label('Frequency')
|
|
->required(),
|
|
Forms\Components\Select::make('connection')
|
|
->label('Connection')
|
|
->selectablePlaceholder(false)
|
|
->options(function (callable $get) {
|
|
$plantId = $get('plant_id');
|
|
if ($plantId)
|
|
{
|
|
return Configuration::where('plant_id', $plantId)
|
|
->where('c_name', 'MOTOR_CONNECTION')
|
|
->orderBy('created_at')
|
|
->pluck('c_value', 'c_value')
|
|
->toArray();
|
|
}
|
|
else
|
|
{
|
|
return Configuration::where('c_name', 'MOTOR_CONNECTION')
|
|
->orderBy('created_at')
|
|
->pluck('c_value', 'c_value')
|
|
->toArray();
|
|
}
|
|
})
|
|
->afterStateUpdated(function ($state, callable $set) {
|
|
if ($state == 'Star-Delta') {
|
|
$set('phase', 'Three');
|
|
}
|
|
})
|
|
->required()
|
|
->default('Star')
|
|
->reactive(),
|
|
Forms\Components\TextInput::make('ins_res_limit')
|
|
->label('Insulation Resistance Limit')
|
|
->required(),
|
|
Forms\Components\Select::make('ins_res_type')
|
|
->label('Insulation Resistance Type')
|
|
->default('O')
|
|
->selectablePlaceholder(false)
|
|
->options(function (callable $get) {
|
|
$plantId = $get('plant_id');
|
|
if ($plantId)
|
|
{
|
|
return Configuration::where('plant_id', $plantId)
|
|
->where('c_name', 'INSULATION_RESISTANCE_TYPE')
|
|
->orderBy('created_at')
|
|
->pluck('c_value', 'c_value')
|
|
->toArray();
|
|
}
|
|
else
|
|
{
|
|
return Configuration::where('c_name', 'INSULATION_RESISTANCE_TYPE')
|
|
->orderBy('created_at')
|
|
->pluck('c_value', 'c_value')
|
|
->toArray();
|
|
}
|
|
})
|
|
->required(),
|
|
Forms\Components\TextInput::make('res_ry_ll')
|
|
->label('Resistance RY LL')
|
|
->required(),
|
|
Forms\Components\TextInput::make('res_ry_ul')
|
|
->label('Resistance RY UL')
|
|
->required(),
|
|
Forms\Components\TextInput::make('res_yb_ll')
|
|
->label('Resistance YB LL')
|
|
->required(),
|
|
Forms\Components\TextInput::make('res_yb_ul')
|
|
->label('Resistance YB UL')
|
|
->required(),
|
|
Forms\Components\TextInput::make('res_br_ll')
|
|
->label('Resistance BR LL')
|
|
->required(),
|
|
Forms\Components\TextInput::make('res_br_ul')
|
|
->label('Resistance BR UL')
|
|
->required(),
|
|
Forms\Components\TextInput::make('lock_volt_limit')
|
|
->label('Lock Volt Limit')
|
|
->required(),
|
|
Forms\Components\TextInput::make('leak_cur_limit')
|
|
->label('Leakage Current Limit')
|
|
->required(),
|
|
Forms\Components\TextInput::make('lock_cur_ll')
|
|
->label('Lock Current LL')
|
|
->required(),
|
|
Forms\Components\TextInput::make('lock_cur_ul')
|
|
->label('Lock Current UL')
|
|
->required(),
|
|
Forms\Components\TextInput::make('noload_cur_ll')
|
|
->label('No Load Current LL')
|
|
->required(),
|
|
Forms\Components\TextInput::make('noload_cur_ul')
|
|
->label('No Load Current UL')
|
|
->required(),
|
|
Forms\Components\TextInput::make('noload_pow_ll')
|
|
->label('No Load Power LL')
|
|
->required(),
|
|
Forms\Components\TextInput::make('noload_pow_ul')
|
|
->label('No Load Power UL')
|
|
->required(),
|
|
Forms\Components\TextInput::make('noload_spd_ll')
|
|
->label('No Load Speed LL')
|
|
->required(),
|
|
Forms\Components\TextInput::make('noload_spd_ul')
|
|
->label('No Load Speed UL')
|
|
->required(),
|
|
Forms\Components\Hidden::make('created_by')
|
|
->default(fn () => Filament::auth()->user()?->name)
|
|
->required(),
|
|
Forms\Components\Hidden::make('updated_by')
|
|
->default(fn () => Filament::auth()->user()?->name)
|
|
->required(),
|
|
Forms\Components\TextInput::make('id')
|
|
->hidden()
|
|
->readOnly(),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('No.')
|
|
->label('No.')
|
|
->getStateUsing(function ($record, $livewire, $column, $rowLoop) {
|
|
$paginator = $livewire->getTableRecords();
|
|
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
|
|
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
|
|
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
|
}),
|
|
Tables\Columns\TextColumn::make('plant.name')
|
|
->label('Plant')
|
|
->alignCenter()
|
|
->searchable()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('item.category')
|
|
->label('Category')
|
|
->alignCenter()
|
|
->searchable()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('item.code')
|
|
->label('Item Code')
|
|
->searchable()
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('subassembly_code')
|
|
->label('SubAssembly Code')
|
|
->searchable()
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('item.description')
|
|
->label('Model')
|
|
->alignCenter()
|
|
->searchable()
|
|
->sortable(),
|
|
Tables\Columns\IconColumn::make('isi_model')
|
|
->label('ISI Model')
|
|
->alignCenter()
|
|
->boolean(),
|
|
Tables\Columns\TextColumn::make('phase')
|
|
->label('Phase')
|
|
->searchable()
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('kw')
|
|
->label('KW')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('hp')
|
|
->label('HP')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('volt')
|
|
->label('Volt')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('current')
|
|
->label('Current')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('rpm')
|
|
->label('Rpm')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('torque')
|
|
->label('Torque')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('frequency')
|
|
->label('Frequency')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('connection')
|
|
->label('Connection')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('ins_res_limit')
|
|
->label('Insulation Resistance Limit')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('ins_res_type')
|
|
->label('Insulation Resistance Type')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('routine_test_time')
|
|
->label('Routine Test Time')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('res_ry_ll')
|
|
->label('Resistance RY LL')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('res_ry_ul')
|
|
->label('Resistance RY UL')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('res_yb_ll')
|
|
->label('Resistance YB LL')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('res_yb_ul')
|
|
->label('Resistance YB UL')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('res_br_ll')
|
|
->label('Resistance BR LL')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('res_br_ul')
|
|
->label('Resistance BR UL')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('lock_volt_limit')
|
|
->label('Lock Volt Limit')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('leak_cur_limit')
|
|
->label('Leakage Current Limit')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('lock_cur_ll')
|
|
->label('Lock Current LL')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('lock_cur_ul')
|
|
->label('Lock Current UL')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('noload_cur_ll')
|
|
->label('No Load Current LL')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('noload_cur_ul')
|
|
->label('No Load Current UL')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('noload_pow_ll')
|
|
->label('No Load Power LL')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('noload_pow_ul')
|
|
->label('No Load Power UL')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('noload_spd_ll')
|
|
->label('No Load Speed LL')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('noload_spd_ul')
|
|
->label('No Load Speed UL')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('created_at')
|
|
->dateTime()
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('created_by')
|
|
->label('Created By')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('updated_at')
|
|
->dateTime()
|
|
->alignCenter()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('updated_by')
|
|
->label('Updated By')
|
|
->alignCenter(),
|
|
Tables\Columns\TextColumn::make('deleted_at')
|
|
->dateTime()
|
|
->alignCenter()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
])
|
|
->filters([
|
|
Tables\Filters\TrashedFilter::make(),
|
|
])
|
|
->actions([
|
|
Tables\Actions\ViewAction::make(),
|
|
Tables\Actions\EditAction::make(),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
Tables\Actions\ForceDeleteBulkAction::make(),
|
|
Tables\Actions\RestoreBulkAction::make(),
|
|
]),
|
|
])
|
|
->headerActions([
|
|
ImportAction::make()
|
|
->importer(MotorTestingMasterImporter::class)
|
|
->visible(function() {
|
|
return Filament::auth()->user()->can('view import motor testing master');
|
|
}),
|
|
ExportAction::make()
|
|
->exporter(MotorTestingMasterExporter::class)
|
|
->visible(function() {
|
|
return Filament::auth()->user()->can('view export motor testing master');
|
|
}),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
//
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListMotorTestingMasters::route('/'),
|
|
'create' => Pages\CreateMotorTestingMaster::route('/create'),
|
|
'view' => Pages\ViewMotorTestingMaster::route('/{record}'),
|
|
'edit' => Pages\EditMotorTestingMaster::route('/{record}/edit'),
|
|
];
|
|
}
|
|
|
|
public static function getEloquentQuery(): Builder
|
|
{
|
|
return parent::getEloquentQuery()
|
|
->withoutGlobalScopes([
|
|
SoftDeletingScope::class,
|
|
]);
|
|
}
|
|
}
|