Added model masters resources, importer, and exporter files
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
This commit is contained in:
394
app/Filament/Resources/ModelMasterResource.php
Normal file
394
app/Filament/Resources/ModelMasterResource.php
Normal file
@@ -0,0 +1,394 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Exports\ModelMasterExporter;
|
||||
use App\Filament\Imports\ModelMasterImporter;
|
||||
use App\Filament\Resources\ModelMasterResource\Pages;
|
||||
use App\Models\Machine;
|
||||
use App\Models\ModelMaster;
|
||||
use App\Models\Plant;
|
||||
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\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class ModelMasterResource extends Resource
|
||||
{
|
||||
protected static ?string $model = ModelMaster::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Laser Marking';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->label('PLANT NAME')
|
||||
->relationship('plant', 'name')
|
||||
->reactive()
|
||||
->searchable()
|
||||
->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();
|
||||
})
|
||||
->disabled(fn (Get $get) => ! empty($get('id')))
|
||||
->default(function () {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? $userHas : optional(ModelMaster::latest()->first())->plant_id;
|
||||
})
|
||||
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
||||
$set('machine_id', null);
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\Select::make('machine_id')
|
||||
->label('WORK CENTER')
|
||||
->reactive()
|
||||
->searchable()
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (empty($plantId)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Machine::where('plant_id', $plantId)->orderBy('work_center')->pluck('work_center', 'id')->toArray();
|
||||
})
|
||||
->disabled(fn (Get $get) => ! empty($get('id')))
|
||||
->default(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (empty($plantId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ModelMaster::where('plant_id', $plantId)->latest()->first()->machine_id ?? null;
|
||||
})
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('heading_name')
|
||||
->label('HEADING NAME')
|
||||
->reactive()
|
||||
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('heading_value')
|
||||
->label('HEADING VALUE')
|
||||
->reactive()
|
||||
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('type_name')
|
||||
->label('TYPE NAME')
|
||||
->reactive()
|
||||
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
}),
|
||||
Forms\Components\TextInput::make('type_value')
|
||||
->label('TYPE VALUE')
|
||||
->reactive()
|
||||
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
}),
|
||||
Forms\Components\TextInput::make('has_motor')
|
||||
->label('HAS MOTOR')
|
||||
->reactive()
|
||||
->minValue(0)
|
||||
->integer()
|
||||
->maxValue(1)
|
||||
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('has_m_part')
|
||||
->label('HAS MOTOR PART')
|
||||
->reactive()
|
||||
->minValue(0)
|
||||
->integer()
|
||||
->maxValue(1)
|
||||
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('has_m_count')
|
||||
->label('HAS MOTOR COUNT')
|
||||
->reactive()
|
||||
->minValue(0)
|
||||
->integer()
|
||||
->maxValue(99)
|
||||
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('has_pump')
|
||||
->label('HAS PUMP')
|
||||
->reactive()
|
||||
->minValue(0)
|
||||
->integer()
|
||||
->maxValue(1)
|
||||
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('has_p_part')
|
||||
->label('HAS PUMP PART')
|
||||
->reactive()
|
||||
->minValue(0)
|
||||
->integer()
|
||||
->maxValue(1)
|
||||
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('has_p_count')
|
||||
->label('HAS PUMP COUNT')
|
||||
->reactive()
|
||||
->minValue(0)
|
||||
->integer()
|
||||
->maxValue(99)
|
||||
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('has_name_plate')
|
||||
->label('HAS NAME PLATE')
|
||||
->reactive()
|
||||
->minValue(0)
|
||||
->integer()
|
||||
->maxValue(1)
|
||||
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('has_np_part')
|
||||
->label('HAS NAME PLATE PART')
|
||||
->reactive()
|
||||
->minValue(0)
|
||||
->integer()
|
||||
->maxValue(1)
|
||||
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('has_np_count')
|
||||
->label('HAS NAME PLATE COUNT')
|
||||
->reactive()
|
||||
->minValue(0)
|
||||
->integer()
|
||||
->maxValue(99)
|
||||
->readOnly(fn (callable $get) => (! $get('plant_id') || ! $get('machine_id')))
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\Hidden::make('created_by')
|
||||
->label('Created By')
|
||||
->default(Filament::auth()->user()?->name),
|
||||
Forms\Components\Hidden::make('updated_by')
|
||||
->label('Updated By')
|
||||
->default(Filament::auth()->user()?->name),
|
||||
Forms\Components\TextInput::make('id')
|
||||
->hidden()
|
||||
->readOnly(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('No.')
|
||||
->label('NO')
|
||||
->alignCenter()
|
||||
->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 NAME')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('machine.work_center')
|
||||
->label('WORK CENTER')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('heading_name')
|
||||
->label('HEADING NAME')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('heading_value')
|
||||
->label('HEADING VALUE')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('type_name')
|
||||
->label('TYPE NAME')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('type_value')
|
||||
->label('TYPE VALUE')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('has_motor')
|
||||
->label('HAS MOTOR')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('has_m_part')
|
||||
->label('HAS MOTOR PART')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('has_m_count')
|
||||
->label('HAS MOTOR COUNT')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('has_pump')
|
||||
->label('HAS PUMP')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('has_p_part')
|
||||
->label('HAS PUMP PART')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('has_p_count')
|
||||
->label('HAS PUMP COUNT')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('has_name_plate')
|
||||
->label('HAS NAME PLATE')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('has_np_part')
|
||||
->label('HAS NAME PLATE PART')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('has_np_count')
|
||||
->label('HAS NAME PLATE COUNT')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('CREATED AT')
|
||||
->alignCenter()
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_by')
|
||||
->label('CREATED BY')
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->label('UPDATED AT')
|
||||
->alignCenter()
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: false),
|
||||
Tables\Columns\TextColumn::make('updated_by')
|
||||
->label('UPDATED BY')
|
||||
->alignCenter()
|
||||
->toggleable(isToggledHiddenByDefault: false),
|
||||
Tables\Columns\TextColumn::make('deleted_at')
|
||||
->label('DELETED AT')
|
||||
->alignCenter()
|
||||
->dateTime()
|
||||
->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()
|
||||
->label('Import Model Masters')
|
||||
->color('warning')
|
||||
->importer(ModelMasterImporter::class)
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view import model master');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->label('Export Model Masters')
|
||||
->color('warning')
|
||||
->exporter(ModelMasterExporter::class)
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view export model master');
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListModelMasters::route('/'),
|
||||
'create' => Pages\CreateModelMaster::route('/create'),
|
||||
'view' => Pages\ViewModelMaster::route('/{record}'),
|
||||
'edit' => Pages\EditModelMaster::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user