302 lines
11 KiB
PHP
302 lines
11 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\StickerMasterResource\Pages;
|
|
use App\Filament\Resources\StickerMasterResource\RelationManagers;
|
|
use App\Models\StickerMaster;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
|
|
|
class StickerMasterResource extends Resource
|
|
{
|
|
protected static ?string $model = StickerMaster::class;
|
|
|
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
|
|
|
protected static ?string $navigationGroup = 'Master Entries';
|
|
|
|
protected static ?int $navigationSort = 8;
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form
|
|
->schema([
|
|
Forms\Components\Select::make('plant_id')
|
|
->relationship('plant', 'name')
|
|
->reactive()
|
|
->nullable()
|
|
->afterStateUpdated(fn (callable $set) =>
|
|
$set('item_id', null) & $set('item_description', null)
|
|
)
|
|
->required(),
|
|
|
|
Forms\Components\Select::make('item_id')
|
|
->label('Item Code')
|
|
->options(function (callable $get) {
|
|
if (!$get('plant_id')) {
|
|
return [];
|
|
}
|
|
|
|
return \App\Models\Item::where('plant_id', $get('plant_id'))
|
|
->pluck('code', 'id')
|
|
->toArray();
|
|
})
|
|
->required()
|
|
->nullable()
|
|
->searchable()
|
|
->reactive()
|
|
->live(debounce: 500) // Enable live updates
|
|
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
|
$plantId = $get('plant_id'); // Get selected plant_id
|
|
$itemId = $get('item_id'); // Get entered item_id
|
|
|
|
// Ensure `item_id` is not cleared
|
|
if (!$plantId || !$itemId) {
|
|
$set('item_description', null);
|
|
return;
|
|
}
|
|
|
|
// Check if item exists for the selected plant
|
|
$item = \App\Models\Item::where('plant_id', $plantId)
|
|
->where('id', $itemId)
|
|
->first();
|
|
|
|
if ($item) {
|
|
$set('item_description', $item->description);
|
|
} else {
|
|
$set('item_description', null);
|
|
}
|
|
|
|
}),
|
|
// ->validationAttribute('Item Code')
|
|
// ->rule('required')
|
|
// ->extraAttributes(fn ($get) => [
|
|
// 'class' => $get('validationError') ? 'border-red-500' : '',
|
|
// ])
|
|
// ->hint(fn ($get) => $get('validationError') ? $get('validationError') : null)
|
|
// ->hintColor('danger'), // Show error in red under the input field
|
|
|
|
Forms\Components\TextInput::make('item_description')
|
|
->label('Description')
|
|
->required()
|
|
->reactive()
|
|
->readOnly(true),
|
|
|
|
//Forms\Components\Textarea::make('serial_number_motor'),
|
|
|
|
Forms\Components\TextInput::make('part_validation1')
|
|
->nullable(),
|
|
|
|
Forms\Components\TextInput::make('part_validation2')
|
|
->nullable(),
|
|
|
|
Forms\Components\TextInput::make('part_validation3')
|
|
->nullable(),
|
|
|
|
Forms\Components\TextInput::make('part_validation4')
|
|
->nullable(),
|
|
|
|
Forms\Components\TextInput::make('part_validation5')
|
|
->nullable(),
|
|
|
|
Forms\Components\Checkbox::make('serial_number_motor')
|
|
->nullable()
|
|
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
|
|
|
|
//Forms\Components\Textarea::make('serial_number_pump')
|
|
|
|
Forms\Components\Checkbox::make('serial_number_pump')
|
|
->nullable()
|
|
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
|
|
|
|
//Forms\Components\TextInput::make('serial_number_pumpset'),
|
|
|
|
Forms\Components\Checkbox::make('serial_number_pumpset')
|
|
->nullable()
|
|
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
|
|
|
|
//Forms\Components\TextInput::make('pack_slip_motor'),
|
|
|
|
Forms\Components\Checkbox::make('pack_slip_motor')
|
|
->nullable()
|
|
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
|
|
|
|
//Forms\Components\TextInput::make('pack_slip_pump'),
|
|
|
|
Forms\Components\Checkbox::make('pack_slip_pump')
|
|
->nullable()
|
|
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
|
|
|
|
//Forms\Components\TextInput::make('pack_slip_pumpset'),
|
|
|
|
Forms\Components\Checkbox::make('pack_slip_pumpset')
|
|
->nullable()
|
|
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
|
|
|
|
//Forms\Components\TextInput::make('name_plate_motor'),
|
|
|
|
Forms\Components\Checkbox::make('name_plate_motor')
|
|
->nullable()
|
|
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
|
|
|
|
//Forms\Components\TextInput::make('name_plate_pump'),
|
|
|
|
Forms\Components\Checkbox::make('name_plate_pump')
|
|
->nullable()
|
|
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
|
|
|
|
//Forms\Components\TextInput::make('name_plate_pumpset'),
|
|
|
|
Forms\Components\Checkbox::make('name_plate_pumpset')
|
|
->nullable()
|
|
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
|
|
|
|
//Forms\Components\TextInput::make('tube_sticker_motor'),
|
|
|
|
Forms\Components\Checkbox::make('tube_sticker_motor')
|
|
->nullable()
|
|
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
|
|
|
|
//Forms\Components\TextInput::make('tube_sticker_pump'),
|
|
|
|
Forms\Components\Checkbox::make('tube_sticker_pump')
|
|
->nullable()
|
|
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
|
|
|
|
//Forms\Components\TextInput::make('tube_sticker_pumpset'),
|
|
|
|
Forms\Components\Checkbox::make('tube_sticker_pumpset')
|
|
->nullable()
|
|
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
|
|
|
|
//Forms\Components\TextInput::make('warranty_card'),
|
|
|
|
Forms\Components\Checkbox::make('warranty_card')
|
|
->nullable()
|
|
->dehydrateStateUsing(fn ($state) => $state ? $state : null),
|
|
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('id')
|
|
->label('ID')
|
|
->numeric()
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('item.code')
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('plant.name')
|
|
->sortable(),
|
|
Tables\Columns\CheckboxColumn::make('serial_number_motor')
|
|
->disabled(true)
|
|
->sortable(),
|
|
Tables\Columns\CheckboxColumn::make('serial_number_pump')
|
|
->disabled(true)
|
|
->sortable(),
|
|
Tables\Columns\CheckboxColumn::make('serial_number_pumpset')
|
|
->disabled(true)
|
|
->sortable(),
|
|
Tables\Columns\CheckboxColumn::make('pack_slip_motor')
|
|
->disabled(true)
|
|
->sortable(),
|
|
Tables\Columns\CheckboxColumn::make('pack_slip_pump')
|
|
->disabled(true)
|
|
->sortable(),
|
|
Tables\Columns\CheckboxColumn::make('pack_slip_pumpset')
|
|
->disabled(true)
|
|
->sortable(),
|
|
Tables\Columns\CheckboxColumn::make('name_plate_motor')
|
|
->disabled(true)
|
|
->sortable(),
|
|
Tables\Columns\CheckboxColumn::make('name_plate_pump')
|
|
->disabled(true)
|
|
->sortable(),
|
|
Tables\Columns\CheckboxColumn::make('name_plate_pumpset')
|
|
->disabled(true)
|
|
->sortable(),
|
|
Tables\Columns\CheckboxColumn::make('tube_sticker_motor')
|
|
->disabled(true)
|
|
->sortable(),
|
|
Tables\Columns\CheckboxColumn::make('tube_sticker_pump')
|
|
->disabled(true)
|
|
->sortable(),
|
|
Tables\Columns\CheckboxColumn::make('tube_sticker_pumpset')
|
|
->disabled(true)
|
|
->sortable(),
|
|
Tables\Columns\CheckboxColumn::make('warranty_card')
|
|
->disabled(true)
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('part_validation1')
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('part_validation2')
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('part_validation3')
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('part_validation4')
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('part_validation5')
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('created_at')
|
|
->dateTime()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
Tables\Columns\TextColumn::make('updated_at')
|
|
->dateTime()
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
Tables\Columns\TextColumn::make('deleted_at')
|
|
->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(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getRelations(): array
|
|
{
|
|
return [
|
|
//
|
|
];
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListStickerMasters::route('/'),
|
|
'create' => Pages\CreateStickerMaster::route('/create'),
|
|
'view' => Pages\ViewStickerMaster::route('/{record}'),
|
|
'edit' => Pages\EditStickerMaster::route('/{record}/edit'),
|
|
];
|
|
}
|
|
|
|
public static function getEloquentQuery(): Builder
|
|
{
|
|
return parent::getEloquentQuery()
|
|
->withoutGlobalScopes([
|
|
SoftDeletingScope::class,
|
|
]);
|
|
}
|
|
}
|