Added migration, model, policy, resource, importer, exporter, controller (Get API) with validation and functionality for Testing Line Visualization
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 16s

This commit is contained in:
dhanabalan
2026-11-03 11:19:07 +05:30
parent 20e64ba356
commit 5c0ed45f74
11 changed files with 1477 additions and 0 deletions

View File

@@ -0,0 +1,75 @@
<?php
namespace App\Filament\Exports;
use App\Models\TestingLineVisualization;
use Filament\Actions\Exports\ExportColumn;
use Filament\Actions\Exports\Exporter;
use Filament\Actions\Exports\Models\Export;
class TestingLineVisualizationExporter extends Exporter
{
protected static ?string $model = TestingLineVisualization::class;
public static function getColumns(): array
{
static $rowNumber = 0;
return [
// ExportColumn::make('id')
// ->label('ID'),
ExportColumn::make('no')
->label('NO')
->state(function ($record) use (&$rowNumber) {
// Increment and return the row number
return ++$rowNumber;
}),
ExportColumn::make('plant.code')
->label('PLANT CODE'),
ExportColumn::make('test_bed_group')
->label('TEST BED GROUP'),
ExportColumn::make('line_no')
->label('LINE NO'),
ExportColumn::make('pump_model')
->label('PUMP MODEL'),
ExportColumn::make('pump_type')
->label('PUMP TYPE'),
ExportColumn::make('motor_details')
->label('MOTOR DETAILS'),
ExportColumn::make('test_type')
->label('TEST TYPE'),
ExportColumn::make('flow')
->label('FLOW'),
ExportColumn::make('head')
->label('HEAD'),
ExportColumn::make('run_time')
->label('RUN TIME'),
ExportColumn::make('live_status')
->label('STATUS'),
ExportColumn::make('observation_remarks')
->label('OBSERVATION / REMARKS'),
ExportColumn::make('created_at')
->label('CREATED AT'),
ExportColumn::make('created_by')
->label('CREATED BY'),
ExportColumn::make('updated_at')
->label('UPDATED AT'),
ExportColumn::make('updated_by')
->label('UPDATED BY'),
ExportColumn::make('deleted_at')
->enabledByDefault(false)
->label('DELETED AT'),
];
}
public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your testing line visualization export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.';
if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.';
}
return $body;
}
}

View File

@@ -0,0 +1,232 @@
<?php
namespace App\Filament\Imports;
use App\Models\Plant;
use App\Models\TestingLineVisualization;
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;
use Filament\Facades\Filament;
use Illuminate\Support\Str;
class TestingLineVisualizationImporter extends Importer
{
protected static ?string $model = TestingLineVisualization::class;
public static function getColumns(): array
{
return [
ImportColumn::make('plant')
->requiredMapping()
->label('PLANT CODE')
->exampleHeader('PLANT CODE')
->example(['1000'])
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('test_bed_group')
->requiredMapping()
->label('TEST BED GROUP')
->exampleHeader('TEST BED GROUP')
->example(['Test Bed 1'])
->rules(['required']),
ImportColumn::make('line_no')
->requiredMapping()
->label('LINE NO')
->exampleHeader('LINE NO')
->example(['1'])
->rules(['required']),
ImportColumn::make('pump_model')
->requiredMapping()
->label('PUMP MODEL')
->exampleHeader('PUMP MODEL')
->example(['CRP-001'])
->rules(['required']),
ImportColumn::make('pump_type')
->requiredMapping()
->label('PUMP TYPE')
->exampleHeader('PUMP TYPE')
->example(['Vertical Turbine (VT)'])
->rules(['required']),
ImportColumn::make('motor_details')
->requiredMapping()
->label('MOTOR DETAILS')
->exampleHeader('MOTOR DETAILS')
->example(['200 kW / 2950 RPM'])
->rules(['required']),
ImportColumn::make('test_type')
->requiredMapping()
->label('TEST TYPE')
->exampleHeader('TEST TYPE')
->example(['Performance'])
->rules(['required']),
ImportColumn::make('flow')
->requiredMapping()
->label('FLOW')
->exampleHeader('FLOW')
->example(['220'])
->rules(['required']),
ImportColumn::make('head')
->requiredMapping()
->label('HEAD')
->exampleHeader('HEAD')
->example(['150'])
->rules(['required']),
ImportColumn::make('run_time')
->requiredMapping()
->label('RUN TIME')
->exampleHeader('RUN TIME')
->example(['2.5'])
->rules(['required']),
ImportColumn::make('live_status')
->requiredMapping()
->label('STATUS')
->exampleHeader('STATUS')
->example(['Running'])
->rules(['required']),
ImportColumn::make('observation_remarks')
->requiredMapping()
->label('OBSERVATION / REMARKS')
->exampleHeader('OBSERVATION / REMARKS')
->example(['Normal']),
// ImportColumn::make('created_by')
// ->requiredMapping()
// ->label('CREATED BY')
// ->exampleHeader('CREATED BY')
// ->example('RAW01234'),
// ImportColumn::make('updated_by')
// ->requiredMapping()
// ->label('UPDATED BY')
// ->exampleHeader('UPDATED BY')
// ->example('RAW01234'),
];
}
public function resolveRecord(): ?TestingLineVisualization
{
$warnMsg = [];
$plantCod = trim($this->data['plant']);
$plant = null;
$plantId = null;
$testBedGroup = trim($this->data['test_bed_group']);
$lineNo = trim($this->data['line_no']);
$pumpModel = trim($this->data['pump_model']);
$pumpType = trim($this->data['pump_type']);
$motorDetails = trim($this->data['motor_details']);
$testType = trim($this->data['test_type']);
$flow = trim($this->data['flow']);
$head = trim($this->data['head']);
$runTime = trim($this->data['run_time']);
$status = trim($this->data['live_status']);
$remarks = trim($this->data['observation_remarks']);
$createdBy = Filament::auth()->user()->name;
$updatedBy = Filament::auth()->user()->name;
if ($plantCod == null || $plantCod == '') {
$warnMsg[] = "Plant code can't be empty!";
} elseif (! is_numeric($plantCod)) {
$warnMsg[] = 'Plant code should contain only numeric values!';
} elseif (Str::length($plantCod) < 4 || Str::length($plantCod) > 7) {
$warnMsg[] = 'Plant code must be between 4 and 7 digits only!';
} elseif (! preg_match('/^[1-9]\d{3,6}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found!';
} else {
$plant = Plant::where('code', $plantCod)->first();
}
if (! $plant) {
$warnMsg[] = 'Plant not found!';
} else {
$plantId = $plant->id;
if ($testBedGroup == null || $testBedGroup == '') {
$warnMsg[] = "Test bed group can't be empty!";
}
if ($lineNo == null || $lineNo == '') {
$warnMsg[] = "Line no can't be empty!";
}
if ($pumpModel == null || $pumpModel == '') {
$warnMsg[] = "Pump model can't be empty!";
}
if ($pumpType == null || $pumpType == '') {
$warnMsg[] = "Pump type can't be empty!";
}
if ($motorDetails == null || $motorDetails == '') {
$warnMsg[] = "Motor details can't be empty!";
}
if ($testType == null || $testType == '') {
$warnMsg[] = "Test type can't be empty!";
}
if ($flow == null || $flow == '') {
$flow = '0';
} elseif (! is_numeric($flow)) {
$warnMsg[] = 'Flow must be a numeric value!';
}
if ($head == null || $head == '') {
$head = '0';
} elseif (! is_numeric($head)) {
$warnMsg[] = 'Head must be a numeric value!';
}
if ($runTime == null || $runTime == '') {
$runTime = '0.0';
} elseif (! is_numeric($runTime)) {
$warnMsg[] = 'Run time must be a numeric value!';
}
if ($status == null || $status == '') {
$warnMsg[] = "Status can't be empty!";
} elseif ($status != 'Running' && $status != 'OFF' && $status != 'Aligning' && $status != 'MTN') {
$warnMsg[] = 'Invalid status value!';
}
// Check for duplicate record based on plant_id, test_bed_group, and line_no
}
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
}
TestingLineVisualization::updateOrCreate([
'plant_id' => $plantId,
'test_bed_group' => $testBedGroup,
'line_no' => $lineNo,
'pump_model' => $pumpModel,
'pump_type' => $pumpType,
'motor_details' => $motorDetails,
'test_type' => $testType,
'flow' => $flow,
'head' => $head,
'run_time' => $runTime,
'live_status' => $status,
'observation_remarks' => $remarks,
'created_by' => $createdBy,
'updated_by' => $updatedBy,
]);
return null;
// return TestingLineVisualization::firstOrNew([
// // Update existing records, matching them by `$this->data['column_name']`
// 'email' => $this->data['email'],
// ]);
// // return new TestingLineVisualization;
}
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your testing line visualization import has completed and '.number_format($import->successful_rows).' '.str('row')->plural($import->successful_rows).' imported.';
if ($failedRowsCount = $import->getFailedRowsCount()) {
$body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to import.';
}
return $body;
}
}

View File

@@ -0,0 +1,734 @@
<?php
namespace App\Filament\Resources;
use App\Filament\Exports\TestingLineVisualizationExporter;
use App\Filament\Imports\TestingLineVisualizationImporter;
use App\Filament\Resources\TestingLineVisualizationResource\Pages;
use App\Models\Configuration;
use App\Models\Plant;
use App\Models\TestingLineVisualization;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
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\Filters\Filter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Support\Str;
class TestingLineVisualizationResource extends Resource
{
protected static ?string $model = TestingLineVisualization::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Pump Testing Panel';
protected static ?int $navigationSort = 4;
public static function form(Form $form): Form
{
return $form
->schema([
Section::make('')
->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();
})
->required()
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : optional(TestingLineVisualization::latest()->first())->plant_id ?? null;
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('updated_by', Filament::auth()->user()?->name);
})
->disabled(fn (Get $get) => ! empty($get('id'))),
Forms\Components\TextInput::make('test_bed_group')
->label('Test Bed Group')
->placeholder('Enter Test Bed Group')
->reactive()
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : optional(TestingLineVisualization::latest()->first())->test_bed_group ?? null;
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\TextInput::make('line_no')
->label('Line Number')
->placeholder('Enter Line Number')
->reactive()
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : optional(TestingLineVisualization::latest()->first())->line_no ?? null;
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\TextInput::make('pump_model')
->label('Pump Model')
->placeholder('Enter Pump Model')
->reactive()
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : optional(TestingLineVisualization::latest()->first())->pump_model ?? null;
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\TextInput::make('pump_type')
->label('Pump Type')
->placeholder('Enter Pump Type')
->reactive()
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : optional(TestingLineVisualization::latest()->first())->pump_type ?? null;
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\TextInput::make('motor_details')
->label('Motor Details')
->placeholder('Enter Motor Details')
->reactive()
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : optional(TestingLineVisualization::latest()->first())->motor_details ?? null;
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\Select::make('test_type')
->label('Test Type')
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
if ($plantId) {
return Configuration::where('plant_id', $plantId)
->where('c_name', 'VISUALIZATION_TEST_TYPE')
->orderBy('created_at')
->pluck('c_value', 'c_value')
->toArray();
} else {
return Configuration::where('c_name', 'VISUALIZATION_TEST_TYPE')
->orderBy('created_at')
->pluck('c_value', 'c_value')
->toArray();
}
})
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : optional(TestingLineVisualization::latest()->first())->test_type ?? null;
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('updated_by', Filament::auth()->user()?->name);
})
->searchable()
->reactive()
->required(),
Forms\Components\TextInput::make('flow')
->label('Flow')
->placeholder('Enter Flow')
->reactive()
->numeric()
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : optional(TestingLineVisualization::latest()->first())->flow ?? '0';
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\TextInput::make('head')
->label('Head')
->placeholder('Enter Head')
->reactive()
->numeric()
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : optional(TestingLineVisualization::latest()->first())->head ?? '0';
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\TextInput::make('run_time')
->label('Run Time')
->placeholder('Enter Run Time')
->reactive()
->numeric()
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : optional(TestingLineVisualization::latest()->first())->run_time ?? '0.0';
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
Forms\Components\Select::make('live_status')
->label('Status')
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
if ($plantId) {
return Configuration::where('plant_id', $plantId)
->where('c_name', 'VISUALIZATION_LIVE_STATUS')
->orderBy('created_at')
->pluck('c_value', 'c_value')
->toArray();
} else {
return Configuration::where('c_name', 'VISUALIZATION_LIVE_STATUS')
->orderBy('created_at')
->pluck('c_value', 'c_value')
->toArray();
}
})
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : optional(TestingLineVisualization::latest()->first())->live_status ?? null;
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('updated_by', Filament::auth()->user()?->name);
})
->searchable()
->reactive()
->required(),
Forms\Components\TextInput::make('observation_remarks')
->label('Observation Remarks')
->placeholder('Enter Observation Remarks')
->reactive()
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? null : optional(TestingLineVisualization::latest()->first())->observation_remarks ?? 'Normal';
})
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('updated_by', Filament::auth()->user()?->name);
}),
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(),
])
->columns(['default' => 1, 'sm' => 2]),
]);
}
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 Name')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('test_bed_group')
->label('Test Bed Group')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('line_no')
->label('Line No')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('pump_model')
->label('Pump Model')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('pump_type')
->label('Pump Type')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('motor_details')
->label('Motor Details')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('test_type')
->label('Test Type')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('flow')
->label('Flow')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('head')
->label('Head')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('run_time')
->label('Run Time')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('live_status')
->label('Status')
->alignCenter()
->searchable()
->sortable()
->color(fn (string $state): string => match ($state) {
'Running' => 'success',
'OFF' => 'danger',
'Aligning' => 'warning',
'MTN' => 'info',
default => 'gray',
})
->badge()
->default('-'),
Tables\Columns\TextColumn::make('observation_remarks')
->label('Observation / Remarks')
->alignCenter()
->searchable()
->sortable()
->color(fn (string $state): string => match ($state) {
default => 'gray',
})
->badge()
->default('-'),
Tables\Columns\TextColumn::make('created_at')
->label('Created At')
->dateTime()
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('created_by')
->label('Created By')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('updated_at')
->label('Updated At')
->dateTime()
->alignCenter()
->searchable()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_by')
->label('Updated By')
->alignCenter()
->searchable()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('deleted_at')
->label('Deleted At')
->dateTime()
->alignCenter()
->searchable()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
Tables\Filters\TrashedFilter::make(),
Filter::make('advanced_filters')
->label('Advanced Filters')
->form([
Select::make('Plant')
->label('Search by Plant Name')
->nullable()
->searchable()
->reactive()
->options(function (callable $get) {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return Plant::where('id', $userHas)->pluck('name', 'id')->toArray();
} else {
return Plant::whereHas('testingLineVisualizations', function ($query) {
$query->whereNotNull('id');
})->orderBy('code')->pluck('name', 'id');
}
})
->afterStateUpdated(function ($state, callable $set, callable $get): void {
$set('created_by', null);
$set('updated_by', null);
}),
TextInput::make('test_bed_group')
->label('Test Bed Group')
->placeholder('Enter Test Bed Group')
->live(500),
TextInput::make('line_no')
->label('Line No')
->placeholder('Enter Line No')
->live(500),
TextInput::make('pump_model')
->label('Pump Model')
->placeholder('Enter Pump Model')
->live(500),
TextInput::make('pump_type')
->label('Pump Type')
->placeholder('Enter Pump Type')
->live(500),
TextInput::make('motor_details')
->label('Motor Details')
->placeholder('Enter Motor Details')
->live(500),
Select::make('test_type')
->label('Test Type')
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
if ($plantId) {
return TestingLineVisualization::where('plant_id', $plantId)->whereNotNull('test_type')->select('test_type')->distinct()->pluck('test_type', 'test_type');
} else {
return TestingLineVisualization::whereNotNull('test_type')->select('test_type')->distinct()->pluck('test_type', 'test_type');
}
})
->searchable()
->reactive(),
TextInput::make('flow')
->label('Flow')
->placeholder('Enter Flow')
->reactive()
->numeric(),
TextInput::make('head')
->label('Head')
->placeholder('Enter Head')
->reactive()
->numeric(),
TextInput::make('run_time')
->label('Run Time')
->placeholder('Enter Run Time')
->reactive()
->numeric(),
Select::make('live_status')
->label('Status')
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
if ($plantId) {
return TestingLineVisualization::where('plant_id', $plantId)->whereNotNull('live_status')->select('live_status')->distinct()->pluck('live_status', 'live_status');
} else {
return TestingLineVisualization::whereNotNull('live_status')->select('live_status')->distinct()->pluck('live_status', 'live_status');
}
})
->searchable()
->reactive(),
TextInput::make('observation_remarks')
->label('Observation / Remarks')
->placeholder('Enter Observation / Remarks')
->live(500),
Select::make('created_by')
->label('Search by Created By')
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
if ($plantId) {
return TestingLineVisualization::where('plant_id', $plantId)->whereNotNull('created_by')->select('created_by')->distinct()->pluck('created_by', 'created_by');
} else {
return TestingLineVisualization::whereNotNull('created_by')->select('created_by')->distinct()->pluck('created_by', 'created_by');
}
})
->searchable()
->reactive(),
DateTimePicker::make('created_from')
->label('Created From')
->placeholder('Select From DateTime')
->reactive()
->native(false),
DateTimePicker::make('created_to')
->label('Created To')
->placeholder('Select To DateTime')
->reactive()
->native(false),
Select::make('updated_by')
->label('Search by Updated By')
->nullable()
->options(function (callable $get) {
$plantId = $get('Plant');
if ($plantId) {
return TestingLineVisualization::where('plant_id', $plantId)->whereNotNull('updated_by')->select('updated_by')->distinct()->pluck('updated_by', 'updated_by');
} else {
return TestingLineVisualization::whereNotNull('updated_by')->select('updated_by')->distinct()->pluck('updated_by', 'updated_by');
}
})
->searchable()
->reactive(),
DateTimePicker::make(name: 'updated_from')
->label('Updated From')
->placeholder(placeholder: 'Select From DateTime')
->reactive()
->native(false),
DateTimePicker::make('updated_to')
->label('Updated To')
->placeholder(placeholder: 'Select To DateTime')
->reactive()
->native(false),
])
->query(function ($query, array $data) {
// Hide all records initially if no filters are applied
if (empty($data['Plant']) && empty($data['test_bed_group']) && empty($data['line_no']) && empty($data['pump_model']) && empty($data['pump_type']) && empty($data['motor_details']) && empty($data['test_type']) && Str::length($data['flow']) <= 0 && Str::length($data['head']) <= 0 && Str::length($data['run_time']) <= 0 && empty($data['live_status']) && empty($data['observation_remarks']) && empty($data['created_by']) && empty($data['created_from']) && empty($data['created_to']) && empty($data['updated_by']) && empty($data['updated_from']) && empty($data['updated_to'])) {
return $query->whereRaw('1 = 0');
}
if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
$query->where('plant_id', $data['Plant']);
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return $query->whereRaw('1 = 0');
}
}
if (! empty($data['test_bed_group'])) {
$query->where('test_bed_group', 'like', '%'.$data['test_bed_group'].'%');
}
if (! empty($data['line_no'])) {
$query->where('line_no', $data['line_no']);
}
if (! empty($data['pump_model'])) {
$query->where('pump_model', 'like', '%'.$data['pump_model'].'%');
}
if (! empty($data['pump_type'])) {
$query->where('pump_type', 'like', '%'.$data['pump_type'].'%');
}
if (! empty($data['motor_details'])) {
$query->where('motor_details', 'like', '%'.$data['motor_details'].'%');
}
if (! empty($data['test_type'])) {
$query->where('test_type', $data['test_type']);
}
if (Str::length($data['flow']) > 0) {
$query->where('flow', $data['flow']);
}
if (Str::length($data['head']) > 0) {
$query->where('head', $data['head']);
}
if (Str::length($data['run_time']) > 0) {
$query->where('run_time', $data['run_time']);
}
if (! empty($data['live_status'])) {
$query->where('live_status', $data['live_status']);
}
if (! empty($data['observation_remarks'])) {
$query->where('observation_remarks', 'like', '%'.$data['observation_remarks'].'%');
}
if (! empty($data['created_by'])) {
$query->where('created_by', $data['created_by']);
}
if (! empty($data['created_from'])) {
$query->where('created_at', '>=', $data['created_from']);
}
if (! empty($data['created_to'])) {
$query->where('created_at', '<=', $data['created_to']);
}
if (! empty($data['updated_by'])) {
$query->where('updated_by', $data['updated_by']);
}
if (! empty($data['updated_from'])) {
$query->where('updated_at', '>=', $data['updated_from']);
}
if (! empty($data['updated_to'])) {
$query->where('updated_at', '<=', $data['updated_to']);
}
})
->indicateUsing(function (array $data) {
$indicators = [];
if (! empty($data['Plant'])) {
$indicators[] = 'Plant Name: '.Plant::where('id', $data['Plant'])->value('name');
} else {
$userHas = Filament::auth()->user()->plant_id;
if ($userHas && strlen($userHas) > 0) {
return 'Plant: Choose plant to filter records.';
}
}
if (! empty($data['test_bed_group'])) {
$indicators[] = 'Test Bed Group: '.$data['test_bed_group'];
}
if (! empty($data['line_no'])) {
$indicators[] = 'Line No: '.$data['line_no'];
}
if (! empty($data['pump_model'])) {
$indicators[] = 'Pump Model: '.$data['pump_model'];
}
if (! empty($data['pump_type'])) {
$indicators[] = 'Pump Type: '.$data['pump_type'];
}
if (! empty($data['motor_details'])) {
$indicators[] = 'Motor Details: '.$data['motor_details'];
}
if (! empty($data['test_type'])) {
$indicators[] = 'Test Type: '.$data['test_type'];
}
if (Str::length($data['flow']) > 0) {
$indicators[] = 'Flow: '.$data['flow'];
}
if (Str::length($data['head']) > 0) {
$indicators[] = 'Head: '.$data['head'];
}
if (Str::length($data['run_time']) > 0) {
$indicators[] = 'Run Time: '.$data['run_time'];
}
if (! empty($data['live_status'])) {
$indicators[] = 'Status: '.$data['live_status'];
}
if (! empty($data['observation_remarks'])) {
$indicators[] = 'Observation / Remarks: '.$data['observation_remarks'];
}
if (! empty($data['created_by'])) {
$indicators[] = 'Created By: '.$data['created_by'];
}
if (! empty($data['created_from'])) {
$indicators[] = 'Created From: '.$data['created_from'];
}
if (! empty($data['created_to'])) {
$indicators[] = 'Created To: '.$data['created_to'];
}
if (! empty($data['updated_by'])) {
$indicators[] = 'Updated By: '.$data['updated_by'];
}
if (! empty($data['updated_from'])) {
$indicators[] = 'Updated From: '.$data['updated_from'];
}
if (! empty($data['updated_to'])) {
$indicators[] = 'Updated To: '.$data['updated_to'];
}
return $indicators;
}),
])
->filtersFormMaxHeight('280px')
->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 Testing Line Visualizations')
->color('warning')
->importer(TestingLineVisualizationImporter::class)
->visible(function () {
return Filament::auth()->user()->can('view import testing line visualizations');
}),
ExportAction::make()
->label('Export Testing Line Visualizations')
->color('warning')
->exporter(TestingLineVisualizationExporter::class)
->visible(function () {
return Filament::auth()->user()->can('view export testing line visualizations');
}),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListTestingLineVisualizations::route('/'),
'create' => Pages\CreateTestingLineVisualization::route('/create'),
'view' => Pages\ViewTestingLineVisualization::route('/{record}'),
'edit' => Pages\EditTestingLineVisualization::route('/{record}/edit'),
];
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace App\Filament\Resources\TestingLineVisualizationResource\Pages;
use App\Filament\Resources\TestingLineVisualizationResource;
use Filament\Resources\Pages\CreateRecord;
class CreateTestingLineVisualization extends CreateRecord
{
protected static string $resource = TestingLineVisualizationResource::class;
protected function getRedirectUrl(): string
{
return $this->getResource()::getUrl('create');
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Filament\Resources\TestingLineVisualizationResource\Pages;
use App\Filament\Resources\TestingLineVisualizationResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
class EditTestingLineVisualization extends EditRecord
{
protected static string $resource = TestingLineVisualizationResource::class;
protected function getHeaderActions(): array
{
return [
Actions\ViewAction::make(),
Actions\DeleteAction::make(),
Actions\ForceDeleteAction::make(),
Actions\RestoreAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\TestingLineVisualizationResource\Pages;
use App\Filament\Resources\TestingLineVisualizationResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class ListTestingLineVisualizations extends ListRecords
{
protected static string $resource = TestingLineVisualizationResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Filament\Resources\TestingLineVisualizationResource\Pages;
use App\Filament\Resources\TestingLineVisualizationResource;
use Filament\Actions;
use Filament\Resources\Pages\ViewRecord;
class ViewTestingLineVisualization extends ViewRecord
{
protected static string $resource = TestingLineVisualizationResource::class;
protected function getHeaderActions(): array
{
return [
Actions\EditAction::make(),
];
}
}

View File

@@ -0,0 +1,170 @@
<?php
namespace App\Http\Controllers;
// use App\Models\ItemCharacteristic;
use App\Models\Plant;
use App\Models\TestingLineVisualization;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Str;
class TestingLineVisualizationController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function getTestingLineVisualization(Request $request)
{
$expectedUser = env('API_AUTH_USER');
$expectedPw = env('API_AUTH_PW');
$headerAuth = $request->header('Authorization');
$expectedToken = 'Bearer '.$expectedUser.':'.$expectedPw;
if ($headerAuth != $expectedToken) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => 'Invalid authorization token!',
], 401);
}
$userName = $request->header('user-name');
$plantCode = $request->header('plant-code');
Log::info('Testing Line Visualization GET API >>', ['user-name' => $userName, 'plant-code' => $plantCode]);
if (! $userName || $userName == null || $userName == '') {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "User name can't be empty!",
], 404);
} elseif ($userName == 'jothi') {
$userName = 'Admin';
}
if (! $plantCode || $plantCode == null || $plantCode == '') {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Plant code can't be empty!",
], 404);
} elseif (! is_numeric($plantCode)) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Plant code '{$plantCode}' should contain only numeric values!",
], 400);
} elseif (Str::length($plantCode) < 4 || Str::length($plantCode) > 7) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Plant code '{$plantCode}' must be between 4 and 7 digits only!",
], 400);
} elseif (! preg_match('/^[1-9]\d{3,6}$/', $plantCode)) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Invalid plant code '{$plantCode}' found!",
], 400);
}
$plant = Plant::where('code', $plantCode)->first();
if (! $plant) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Plant code '{$plantCode}' not found in plants table!",
], 404);
}
$plantId = $plant->id;
$user = User::where('name', $userName)->first();
if (! $user) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "User name '{$userName}' not found in users table!",
], 404);
}
$userPlant = User::where('name', $userName)->where('plant_id', $plantId)->first();
if (! $userPlant && ! $user->hasRole('Super Admin')) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "User name '{$userName}' not found for the plant code '{$plantCode}' in users table!",
], 404);
} elseif (! $user->hasRole(['Super Admin', 'Testing Line Visualization Manager', 'Testing Line Visualization Supervisor', 'Testing Line Visualization Employee'])) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "User '{$userName}' does not have rights!",
], 404);
}
$jobAgaPlant = TestingLineVisualization::where('plant_id', $plantId)->first();
if (! $jobAgaPlant) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Reports not found for the plant code '{$plantCode}' in testing line visualization table!",
], 404);
}
$records = TestingLineVisualization::where('plant_id', $plantId)->orderBy('id')->get();
$response = [];
foreach ($records as $row) {
$response[] = [
'test_bed_group' => $row->test_bed_group ?? '',
'line_no' => $row->line_no ?? '',
'pump_model' => $row->pump_model ?? '',
'pump_type' => $row->pump_type ?? '',
'motor_details' => $row->motor_details ?? '',
'test_type' => $row->test_type ?? '',
'flow' => $row->flow ?? '',
'head' => $row->head ?? '',
'run_time' => $row->run_time ?? '',
'status' => $row->live_status ?? '',
'observation_remarks' => $row->observation_remarks ?? '',
'created_by' => ($row->created_by == 'Admin') ? 'jothi' : $row->created_by ?? '',
'created_at' => $row->created_at ? $row->created_at->format('Y-m-d H:i:s') : '',
'updated_by' => ($row->updated_by == 'Admin') ? 'jothi' : $row->updated_by ?? '',
'updated_at' => $row->updated_at ? $row->updated_at->format('Y-m-d H:i:s') : '',
];
}
return response()->json([
'testing_line_visualizations' => $response,
], 200);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class TestingLineVisualization extends Model
{
use SoftDeletes;
protected $fillable = [
'plant_id',
'test_bed_group',
'line_no',
'pump_model',
'pump_type',
'motor_details',
'test_type',
'flow',
'head',
'run_time',
'live_status',
'observation_remarks',
'created_at',
'created_by',
'updated_at',
'updated_by',
];
public function plant(): BelongsTo
{
return $this->belongsTo(Plant::class);
}
}

View File

@@ -0,0 +1,105 @@
<?php
namespace App\Policies;
use App\Models\TestingLineVisualization;
use App\Models\User;
class TestingLineVisualizationPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return $user->checkPermissionTo('view-any TestingLineVisualization');
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, TestingLineVisualization $testinglinevisualization): bool
{
return $user->checkPermissionTo('view TestingLineVisualization');
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return $user->checkPermissionTo('create TestingLineVisualization');
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, TestingLineVisualization $testinglinevisualization): bool
{
return $user->checkPermissionTo('update TestingLineVisualization');
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, TestingLineVisualization $testinglinevisualization): bool
{
return $user->checkPermissionTo('delete TestingLineVisualization');
}
/**
* Determine whether the user can delete any models.
*/
public function deleteAny(User $user): bool
{
return $user->checkPermissionTo('delete-any TestingLineVisualization');
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, TestingLineVisualization $testinglinevisualization): bool
{
return $user->checkPermissionTo('restore TestingLineVisualization');
}
/**
* Determine whether the user can restore any models.
*/
public function restoreAny(User $user): bool
{
return $user->checkPermissionTo('restore-any TestingLineVisualization');
}
/**
* Determine whether the user can replicate the model.
*/
public function replicate(User $user, TestingLineVisualization $testinglinevisualization): bool
{
return $user->checkPermissionTo('replicate TestingLineVisualization');
}
/**
* Determine whether the user can reorder the models.
*/
public function reorder(User $user): bool
{
return $user->checkPermissionTo('reorder TestingLineVisualization');
}
/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, TestingLineVisualization $testinglinevisualization): bool
{
return $user->checkPermissionTo('force-delete TestingLineVisualization');
}
/**
* Determine whether the user can permanently delete any models.
*/
public function forceDeleteAny(User $user): bool
{
return $user->checkPermissionTo('force-delete-any TestingLineVisualization');
}
}

View File

@@ -0,0 +1,49 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
$sql = <<<'SQL'
CREATE TABLE testing_line_visualizations (
id BIGINT GENERATED always AS IDENTITY PRIMARY KEY,
plant_id BIGINT NOT NULL,
test_bed_group TEXT DEFAULT NULL,
line_no TEXT DEFAULT NULL,
pump_model TEXT DEFAULT NULL,
pump_type TEXT DEFAULT NULL,
motor_details TEXT DEFAULT NULL,
test_type TEXT DEFAULT NULL,
flow TEXT DEFAULT '0',
head TEXT DEFAULT '0',
run_time TEXT DEFAULT '0.0',
live_status TEXT DEFAULT NULL,
observation_remarks TEXT DEFAULT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
created_by TEXT DEFAULT NULL,
updated_by TEXT DEFAULT NULL,
deleted_at TIMESTAMP,
-- UNIQUE (plant_id, machine_name),
FOREIGN KEY (plant_id) REFERENCES plants (id)
);
SQL;
DB::statement($sql);
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('testing_line_visualizations');
}
};