Added motor_testing_master migration, model, resource with dependencies, importer, exporter
This commit is contained in:
402
app/Filament/Resources/MotorTestingMasterResource.php
Normal file
402
app/Filament/Resources/MotorTestingMasterResource.php
Normal file
@@ -0,0 +1,402 @@
|
||||
<?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';
|
||||
|
||||
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)
|
||||
->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();
|
||||
}
|
||||
})
|
||||
->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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MotorTestingMasterResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MotorTestingMasterResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateMotorTestingMaster extends CreateRecord
|
||||
{
|
||||
protected static string $resource = MotorTestingMasterResource::class;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MotorTestingMasterResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MotorTestingMasterResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditMotorTestingMaster extends EditRecord
|
||||
{
|
||||
protected static string $resource = MotorTestingMasterResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\ViewAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
Actions\ForceDeleteAction::make(),
|
||||
Actions\RestoreAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MotorTestingMasterResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MotorTestingMasterResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListMotorTestingMasters extends ListRecords
|
||||
{
|
||||
protected static string $resource = MotorTestingMasterResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\MotorTestingMasterResource\Pages;
|
||||
|
||||
use App\Filament\Resources\MotorTestingMasterResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewMotorTestingMaster extends ViewRecord
|
||||
{
|
||||
protected static string $resource = MotorTestingMasterResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\EditAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user