418 lines
18 KiB
PHP
418 lines
18 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;
|
|
|
|
class MotorTestingMasterResource extends Resource
|
|
{
|
|
protected static ?string $model = MotorTestingMaster::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
|
|
|
protected static ?string $navigationGroup = 'Master Entries';
|
|
|
|
protected static ?int $navigationSort = 12;
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
Forms\Components\Select::make('plant_id')
|
|
->relationship('plant', 'name')
|
|
->required()
|
|
->reactive()
|
|
->default(function () {
|
|
return optional(Item::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\Select::make('item_id')
|
|
->label('Item')
|
|
->options(function (callable $get) {
|
|
$plantId = $get('plant_id');
|
|
if (!$plantId) {
|
|
return [];
|
|
}
|
|
|
|
return Item::where('plant_id', $plantId)
|
|
->pluck('code', 'id')
|
|
->toArray();
|
|
})
|
|
->required()
|
|
->searchable()
|
|
->reactive(),
|
|
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')
|
|
->pluck('c_value', 'c_value')
|
|
->toArray();
|
|
}
|
|
else
|
|
{
|
|
return Configuration::where('c_name', 'MOTOR_PHASE')
|
|
->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')
|
|
->pluck('c_value', 'c_value')
|
|
->toArray();
|
|
}
|
|
else
|
|
{
|
|
return Configuration::where('c_name', 'MOTOR_CONNECTION')
|
|
->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\TextInput::make('ins_res_type')
|
|
->label('Insulation Resistance Type')
|
|
->default('O')
|
|
->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(),
|
|
]);
|
|
}
|
|
|
|
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.code')
|
|
->label('Item 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('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,
|
|
]);
|
|
}
|
|
}
|