Updated alignments and added orderby query while load plant
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

This commit is contained in:
dhanabalan
2026-02-10 12:45:54 +05:30
parent 6c9408663b
commit aaa9c17e66
36 changed files with 1592 additions and 1574 deletions

View File

@@ -5,21 +5,20 @@ namespace App\Filament\Resources;
use App\Filament\Exports\MfmMeterExporter;
use App\Filament\Imports\MfmMeterImporter;
use App\Filament\Resources\MfmMeterResource\Pages;
use App\Filament\Resources\MfmMeterResource\RelationManagers;
use App\Models\DeviceMaster;
use App\Models\MfmMeter;
use App\Models\Plant;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\Section;
use Filament\Forms\Form;
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;
use Filament\Forms\Components\Section;
use Filament\Tables\Actions\ImportAction;
use Filament\Tables\Actions\ExportAction;
class MfmMeterResource extends Resource
{
@@ -34,35 +33,37 @@ class MfmMeterResource extends Resource
return $form
->schema([
Section::make('')
->schema([
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->label('Plant')
->reactive()
->required()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
}),
Forms\Components\Select::make('device_master_id')
//->relationship('device', 'name')
->options(function ($get) {
$plantId = $get('plant_id');
if (!$plantId) {
return [];
}
return DeviceMaster::where('plant_id', $plantId)->pluck('name', 'id');
})
->label('Device Name')
->required(),
Forms\Components\TextInput::make('sequence')
->required(),
Forms\Components\TextInput::make('name')
->required(),
Forms\Components\Hidden::make('created_by')
->default(Filament::auth()->user()?->name),
])
->columns(4),
->schema([
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->label('Plant')
->reactive()
->required()
->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();
}),
Forms\Components\Select::make('device_master_id')
// ->relationship('device', 'name')
->options(function ($get) {
$plantId = $get('plant_id');
if (! $plantId) {
return [];
}
return DeviceMaster::where('plant_id', $plantId)->pluck('name', 'id');
})
->label('Device Name')
->required(),
Forms\Components\TextInput::make('sequence')
->required(),
Forms\Components\TextInput::make('name')
->required(),
Forms\Components\Hidden::make('created_by')
->default(Filament::auth()->user()?->name),
])
->columns(4),
]);
}
@@ -71,12 +72,13 @@ class MfmMeterResource extends Resource
{
return $table
->columns([
Tables\Columns\TextColumn::make('No.')
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')
@@ -121,19 +123,19 @@ class MfmMeterResource extends Resource
Tables\Actions\RestoreBulkAction::make(),
]),
])
->headerActions([
->headerActions([
ImportAction::make()
->label('Import MFM Meters')
->color('warning')
->importer(MfmMeterImporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view import mfm meter');
}),
ExportAction::make()
->label('Export MFM Meters')
->color('warning')
->exporter(MfmMeterExporter::class)
->visible(function() {
->visible(function () {
return Filament::auth()->user()->can('view export mfm meter');
}),
]);