From b8e03d231ecfbc5cd433e01f2fea2e8cf0160415 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 24 Aug 2026 10:01:53 +0530 Subject: [PATCH 01/10] Added pump testing master migration file --- ...4520_create_pump_testing_masters_table.php | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 database/migrations/2026_08_10_094520_create_pump_testing_masters_table.php diff --git a/database/migrations/2026_08_10_094520_create_pump_testing_masters_table.php b/database/migrations/2026_08_10_094520_create_pump_testing_masters_table.php new file mode 100644 index 0000000..898a6bb --- /dev/null +++ b/database/migrations/2026_08_10_094520_create_pump_testing_masters_table.php @@ -0,0 +1,71 @@ + Date: Mon, 24 Aug 2026 10:04:36 +0530 Subject: [PATCH 02/10] Added pump testing master policies and model file --- app/Models/PumpTestingMaster.php | 62 +++++++++++++ app/Policies/PumpTestingMasterPolicy.php | 105 +++++++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 app/Models/PumpTestingMaster.php create mode 100644 app/Policies/PumpTestingMasterPolicy.php diff --git a/app/Models/PumpTestingMaster.php b/app/Models/PumpTestingMaster.php new file mode 100644 index 0000000..271624f --- /dev/null +++ b/app/Models/PumpTestingMaster.php @@ -0,0 +1,62 @@ +belongsTo(Plant::class); + } + + public function item(): BelongsTo + { + return $this->belongsTo(Item::class, 'item_id', 'id'); + } + + public function pumpTestingEntries() + { + return $this->hasMany(PumpTestingEntry::class, 'pump_testing_master_id', 'id'); + } +} diff --git a/app/Policies/PumpTestingMasterPolicy.php b/app/Policies/PumpTestingMasterPolicy.php new file mode 100644 index 0000000..6ab6f41 --- /dev/null +++ b/app/Policies/PumpTestingMasterPolicy.php @@ -0,0 +1,105 @@ +checkPermissionTo('view-any PumpTestingMaster'); + } + + /** + * Determine whether the user can view the model. + */ + public function view(User $user, PumpTestingMaster $pumptestingmaster): bool + { + return $user->checkPermissionTo('view PumpTestingMaster'); + } + + /** + * Determine whether the user can create models. + */ + public function create(User $user): bool + { + return $user->checkPermissionTo('create PumpTestingMaster'); + } + + /** + * Determine whether the user can update the model. + */ + public function update(User $user, PumpTestingMaster $pumptestingmaster): bool + { + return $user->checkPermissionTo('update PumpTestingMaster'); + } + + /** + * Determine whether the user can delete the model. + */ + public function delete(User $user, PumpTestingMaster $pumptestingmaster): bool + { + return $user->checkPermissionTo('delete PumpTestingMaster'); + } + + /** + * Determine whether the user can delete any models. + */ + public function deleteAny(User $user): bool + { + return $user->checkPermissionTo('delete-any PumpTestingMaster'); + } + + /** + * Determine whether the user can restore the model. + */ + public function restore(User $user, PumpTestingMaster $pumptestingmaster): bool + { + return $user->checkPermissionTo('restore PumpTestingMaster'); + } + + /** + * Determine whether the user can restore any models. + */ + public function restoreAny(User $user): bool + { + return $user->checkPermissionTo('restore-any PumpTestingMaster'); + } + + /** + * Determine whether the user can replicate the model. + */ + public function replicate(User $user, PumpTestingMaster $pumptestingmaster): bool + { + return $user->checkPermissionTo('replicate PumpTestingMaster'); + } + + /** + * Determine whether the user can reorder the models. + */ + public function reorder(User $user): bool + { + return $user->checkPermissionTo('reorder PumpTestingMaster'); + } + + /** + * Determine whether the user can permanently delete the model. + */ + public function forceDelete(User $user, PumpTestingMaster $pumptestingmaster): bool + { + return $user->checkPermissionTo('force-delete PumpTestingMaster'); + } + + /** + * Determine whether the user can permanently delete any models. + */ + public function forceDeleteAny(User $user): bool + { + return $user->checkPermissionTo('force-delete-any PumpTestingMaster'); + } +} -- 2.49.1 From e4dc7560b35dd0a2f36d527c1183715e83d0414d Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 24 Aug 2026 10:09:11 +0530 Subject: [PATCH 03/10] Added pump testing master model files for hasMany relations --- app/Models/Item.php | 5 +++++ app/Models/Plant.php | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/Models/Item.php b/app/Models/Item.php index 5e80092..1b0dc5c 100644 --- a/app/Models/Item.php +++ b/app/Models/Item.php @@ -49,6 +49,11 @@ class Item extends Model return $this->hasMany(TestingPanelReading::class); } + public function pumpTestingMasters() + { + return $this->hasMany(PumpTestingMaster::class, 'item_id', 'id'); + } + public function processOrders() { return $this->hasMany(ProcessOrder::class); diff --git a/app/Models/Plant.php b/app/Models/Plant.php index dbc57eb..91b3dd6 100644 --- a/app/Models/Plant.php +++ b/app/Models/Plant.php @@ -84,10 +84,10 @@ class Plant extends Model return $this->hasMany(TestingPanelReading::class, 'plant_id', 'id'); } - // public function pumpTestingMasters() - // { - // return $this->hasMany(PumpTestingMaster::class, 'plant_id', 'id'); - // } + public function pumpTestingMasters() + { + return $this->hasMany(PumpTestingMaster::class, 'plant_id', 'id'); + } // public function pumpTestingEntries() // { -- 2.49.1 From d9d9f84378af1ba485e27c1c0dd9208339abd023 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 24 Aug 2026 10:11:23 +0530 Subject: [PATCH 04/10] Added pump testing master resource files and exporter file --- .../Exports/PumpTestingMasterExporter.php | 113 ++ .../Resources/PumpTestingMasterResource.php | 991 ++++++++++++++++++ .../Pages/CreatePumpTestingMaster.php | 12 + .../Pages/EditPumpTestingMaster.php | 22 + .../Pages/ListPumpTestingMasters.php | 19 + .../Pages/ViewPumpTestingMaster.php | 19 + 6 files changed, 1176 insertions(+) create mode 100644 app/Filament/Exports/PumpTestingMasterExporter.php create mode 100644 app/Filament/Resources/PumpTestingMasterResource.php create mode 100644 app/Filament/Resources/PumpTestingMasterResource/Pages/CreatePumpTestingMaster.php create mode 100644 app/Filament/Resources/PumpTestingMasterResource/Pages/EditPumpTestingMaster.php create mode 100644 app/Filament/Resources/PumpTestingMasterResource/Pages/ListPumpTestingMasters.php create mode 100644 app/Filament/Resources/PumpTestingMasterResource/Pages/ViewPumpTestingMaster.php diff --git a/app/Filament/Exports/PumpTestingMasterExporter.php b/app/Filament/Exports/PumpTestingMasterExporter.php new file mode 100644 index 0000000..4989967 --- /dev/null +++ b/app/Filament/Exports/PumpTestingMasterExporter.php @@ -0,0 +1,113 @@ +label('NO') + ->state(function ($record) use (&$rowNumber) { + // Increment and return the row number + return ++$rowNumber; + }), + ExportColumn::make('plant.code') + ->label('PLANT CODE'), + ExportColumn::make('item.code') + ->label('PUMP CODE'), + ExportColumn::make('item.category') + ->label('PUMP CATEGORY') + ->enabledByDefault(false), + ExportColumn::make('item.description') + ->label('PUMP TYPE'), + ExportColumn::make('item.uom') + ->label('UNIT OF MEASURE') + ->enabledByDefault(false), + ExportColumn::make('head') + ->label('HEAD'), + ExportColumn::make('head_type') + ->label('HEAD TYPE'), + ExportColumn::make('discharge') + ->label('DISCHARGE'), + ExportColumn::make('discharge_type') + ->label('DISCHARGE TYPE'), + ExportColumn::make('motor_efficiency') + ->label('MOTOR EFFICIENCY'), + ExportColumn::make('pump_efficiency') + ->label('PUMP EFFICIENCY'), + ExportColumn::make('speed') + ->label('SPEED'), + ExportColumn::make('frequency') + ->label('FREQUENCY'), + ExportColumn::make('i_max') + ->label('I-MAX'), + ExportColumn::make('p_input') + ->label('P-INPUT'), + ExportColumn::make('delivery_size') + ->label('DELIVERY SIZE'), + ExportColumn::make('no_of_stages') + ->label('NO OF STAGES'), + ExportColumn::make('size') + ->label('SIZE'), + ExportColumn::make('maximum_head') + ->label('MAXIMUM HEAD'), + ExportColumn::make('motor_type') + ->label('MOTOR TYPE'), + ExportColumn::make('motor_code') + ->label('MOTOR CODE'), + ExportColumn::make('kw_hp') + ->label('KW / HP'), + ExportColumn::make('connection_type') + ->label('CONNECTION TYPE'), + ExportColumn::make('voltage') + ->label('VOLTAGE'), + ExportColumn::make('phase') + ->label('PHASE'), + ExportColumn::make('oh_minimum') + ->label('OH MINIMUM'), + ExportColumn::make('oh_maximum') + ->label('OH MAXIMUM'), + ExportColumn::make('current_minimum') + ->label('CURRENT MINIMUM'), + ExportColumn::make('current_maximum') + ->label('CURRENT MAXIMUM'), + ExportColumn::make('class_of_insulation') + ->label('CLASS OF INSULATION'), + ExportColumn::make('testing_code') + ->label('TESTING CODE'), + 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 pump testing master 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; + } +} diff --git a/app/Filament/Resources/PumpTestingMasterResource.php b/app/Filament/Resources/PumpTestingMasterResource.php new file mode 100644 index 0000000..ab08c57 --- /dev/null +++ b/app/Filament/Resources/PumpTestingMasterResource.php @@ -0,0 +1,991 @@ +schema([ + Section::make('') + ->schema([ + Forms\Components\Select::make('plant_id') + ->label('Plant Name') + ->relationship('plant', 'name') + ->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(); + }) + ->columnSpan(1) // (['default' => 1, 'sm' => 2]) + ->required() + ->searchable() + ->reactive() + ->default(function () { + $userHas = Filament::auth()->user()->plant_id; + + return ($userHas && strlen($userHas) > 0) ? $userHas : optional(PumpTestingMaster::latest()->first())->plant_id ?? null; + }) + ->disabled(fn (Get $get) => ! empty($get('id'))) + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $plantId = $get('plant_id'); + if (! $plantId) { + $set('pTmError', 'Please select a plant first.'); + + return; + } else { + $set('pTmError', null); + } + + $set('updated_by', Filament::auth()->user()?->name); + }) + ->extraAttributes(fn ($get) => [ + 'class' => $get('pTmError') ? 'border-red-500' : '', + ]) + ->hint(fn ($get) => $get('pTmError') ? $get('pTmError') : null) + ->hintColor('danger'), + Forms\Components\Select::make('item_id') + ->label('Item Code') + // ->relationship('item', 'name') + ->options(function (callable $get) { + $plantId = $get('plant_id'); + if (! $plantId) { + return []; + } + + if (! $get('id')) { + // whereHas + return Item::where('plant_id', $plantId)->whereDoesntHave('pumpTestingMasters')->pluck('code', 'id'); + } else { + $itemId = PumpTestingMaster::where('id', $get('id'))->first()?->item_id; + + return Item::where('plant_id', $plantId) + ->where(function ($query) use ($itemId) { + $query->whereDoesntHave('pumpTestingMasters') + ->orWhere('id', $itemId); + }) + ->pluck('code', 'id'); + } + // return Item::where('plant_id', $plantId)->pluck('code', 'id')->toArray(); + }) + ->columnSpan(1) + ->required() + ->searchable() + ->reactive() + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->rule(function (callable $get) { + return Rule::unique('pump_testing_masters', 'item_id') + ->where('plant_id', $get('plant_id')) + ->ignore($get('id')); // Ignore current record during updates + }), + Forms\Components\TextInput::make('head') + ->label('Head') + ->placeholder('Scan the head') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\Select::make('head_type') + ->label('Head Type') + ->selectablePlaceholder(false) + ->options(function (callable $get) { + $plantId = $get('plant_id'); + if ($plantId) { + return Configuration::where('plant_id', $plantId) + ->where('c_name', 'PUMP_HEAD_TYPE') + ->orderBy('created_at') + ->pluck('c_value', 'c_value') + ->toArray(); + } else { + return Configuration::where('c_name', 'PUMP_HEAD_TYPE') + ->orderBy('created_at') + ->pluck('c_value', 'c_value') + ->toArray(); + } + }) + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->default('m') + ->reactive(), + Forms\Components\TextInput::make('discharge') + ->label('Discharge') + ->placeholder('Scan the discharge') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\Select::make('discharge_type') + ->label('Discharge Type') + ->selectablePlaceholder(false) + ->options(function (callable $get) { + $plantId = $get('plant_id'); + if ($plantId) { + return Configuration::where('plant_id', $plantId) + ->where('c_name', 'PUMP_DISCHARGE_TYPE') + ->orderBy('created_at') + ->pluck('c_value', 'c_value') + ->toArray(); + } else { + return Configuration::where('c_name', 'PUMP_DISCHARGE_TYPE') + ->orderBy('created_at') + ->pluck('c_value', 'c_value') + ->toArray(); + } + }) + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->default('lps') + ->reactive(), + Forms\Components\TextInput::make('motor_efficiency') + ->label('Motor Efficiency') + ->placeholder('Scan the motor efficiency') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->reactive() + ->required(), + Forms\Components\TextInput::make('pump_efficiency') + ->label('Pump Efficiency') + ->placeholder('Scan the pump efficiency') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->reactive() + ->required(), + Forms\Components\TextInput::make('speed') + ->label('Speed') + ->placeholder('Scan the Speed') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('frequency') + ->label('Frequency') + ->placeholder('Scan the frequency') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('i_max') + ->label('I-Max') + ->placeholder('Scan the I-Max') + ->columnSpan(1) + ->required() + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->reactive(), + Forms\Components\TextInput::make('p_input') + ->label('P-Input') + ->placeholder('Scan the P-Input') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('delivery_size') + ->label('Delivery Size') + ->placeholder('Scan the delivery size') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('no_of_stages') + ->label('No of Stages') + ->placeholder('Scan the no of stages') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('size') + ->label('Size') + ->placeholder('Scan the size') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('maximum_head') + ->label('Maximum Head') + ->placeholder('Scan the maximum head') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('motor_type') + ->label('Motor Type') + ->placeholder('Scan the motor type') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('motor_code') + ->label('Motor Code') + ->placeholder('Scan the motor code') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('kw_hp') + ->label('KW / HP') + ->placeholder('Scan the KW / HP') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\Select::make('connection_type') + ->label('Connection Type') + ->selectablePlaceholder(false) + ->options(function (callable $get) { + $plantId = $get('plant_id'); + if ($plantId) { + return Configuration::where('plant_id', $plantId) + ->where('c_name', 'PUMP_CONNECTION') + ->orderBy('created_at') + ->pluck('c_value', 'c_value') + ->toArray(); + } else { + return Configuration::where('c_name', 'PUMP_CONNECTION') + ->orderBy('created_at') + ->pluck('c_value', 'c_value') + ->toArray(); + } + }) + ->afterStateUpdated(function ($state, callable $set) { + if ($state == 'STAR DELTA') { + $set('phase', 'Three'); + } + + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->default('STAR') + ->reactive(), + Forms\Components\TextInput::make('voltage') + ->label('Voltage') + ->placeholder('Scan the voltage') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\Select::make('phase') + ->label('Phase') + ->selectablePlaceholder(false) + ->options(function (callable $get) { + $plantId = $get('plant_id'); + + if ($plantId) { + return Configuration::where('plant_id', $plantId) + ->where('c_name', 'PUMP_PHASE') + ->orderBy('created_at') + ->pluck('c_value', 'c_value') + ->toArray(); + } else { + return Configuration::where('c_name', 'PUMP_PHASE') + ->orderBy('created_at') + ->pluck('c_value', 'c_value') + ->toArray(); + } + }) + ->afterStateUpdated(function ($state, callable $set, callable $get) { + if ($state == 'Single' && $get('connection_type') == 'STAR DELTA') { + $set('phase', 'Three'); + } + + $set('updated_by', Filament::auth()->user()?->name); + }) + ->default('Single') + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('oh_minimum') + ->label('OH Minimum') + ->placeholder('Scan the OH minimum') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('oh_maximum') + ->label('OH Maximum') + ->placeholder('Scan the OH maximum') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('current_minimum') + ->label('Current Minimum') + ->placeholder('Scan the current minimum') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('current_maximum') + ->label('Current Maximum') + ->placeholder('Scan the current maximum') + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('class_of_insulation') + ->label('Class of Insulation') + ->placeholder('Scan the class of insulation') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('testing_code') + ->label('Testing Code') + ->placeholder('Scan the testing code') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\Hidden::make('created_by') + ->default(fn () => Filament::auth()->user()?->name) + ->columnSpan(1) + ->required(), + Forms\Components\Hidden::make('updated_by') + ->default(fn () => Filament::auth()->user()?->name) + ->columnSpan(1) + ->required(), + Forms\Components\TextInput::make('id') + ->hidden() + ->columnSpan(1) + ->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') + ->searchable() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('item.code') + ->label('Pump Code') + ->searchable() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('item.category') + ->label('Pump Category') + ->default('-') + ->searchable() + ->alignCenter() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('item.description') + ->label('Pump Type') + ->searchable() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('item.uom') + ->label('Unit Of Measure') + ->default('-') + ->searchable() + ->alignCenter() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('head') + ->label('Head') + ->default('-') + ->searchable() + ->alignCenter(), + Tables\Columns\TextColumn::make('head_type') + ->label('Head Type') + ->default('-') + ->searchable() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('discharge') + ->label('Discharge') + ->default('-') + ->searchable() + ->alignCenter(), + Tables\Columns\TextColumn::make('discharge_type') + ->label('Discharge Type') + ->default('-') + ->searchable() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('motor_efficiency') + ->label('Motor Efficiency') + ->default('-') + ->searchable() + ->alignCenter(), + Tables\Columns\TextColumn::make('pump_efficiency') + ->label('Pump Efficiency') + ->default('-') + ->searchable() + ->alignCenter(), + Tables\Columns\TextColumn::make('speed') + ->label('Speed') + ->default('-') + ->searchable() + ->alignCenter(), + Tables\Columns\TextColumn::make('frequency') + ->label('Frequency') + ->default('-') + ->searchable() + ->alignCenter(), + Tables\Columns\TextColumn::make('i_max') + ->label('I-Max') + ->default('-') + ->searchable() + ->alignCenter(), + Tables\Columns\TextColumn::make('p_input') + ->label('P-Input') + ->default('-') + ->searchable() + ->alignCenter(), + Tables\Columns\TextColumn::make('delivery_size') + ->label('Delivery Size') + ->default('-') + ->searchable() + ->alignCenter(), + Tables\Columns\TextColumn::make('no_of_stages') + ->label('No of Stages') + ->default('-') + ->searchable() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('size') + ->label('Size') + ->default('-') + ->searchable() + ->alignCenter(), + Tables\Columns\TextColumn::make('maximum_head') + ->label('Maximum Head') + ->default('-') + ->searchable() + ->alignCenter(), + Tables\Columns\TextColumn::make('motor_type') + ->label('Motor Type') + ->default('-') + ->searchable() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('motor_code') + ->label('Motor Code') + ->default('-') + ->searchable() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('kw_hp') + ->label('KW / HP') + ->default('-') + ->searchable() + ->alignCenter(), + Tables\Columns\TextColumn::make('connection_type') + ->label('Connection Type') + ->default('-') + ->searchable() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('voltage') + ->label('Voltage') + ->default('-') + ->searchable() + ->alignCenter(), + Tables\Columns\TextColumn::make('phase') + ->label('Phase') + ->default('-') + ->searchable() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('oh_minimum') + ->label('OH Minimum') + ->default('-') + ->searchable() + ->alignCenter(), + Tables\Columns\TextColumn::make('oh_maximum') + ->label('OH Maximum') + ->default('-') + ->searchable() + ->alignCenter(), + Tables\Columns\TextColumn::make('current_minimum') + ->label('Current Minimum') + ->default('-') + ->searchable() + ->alignCenter(), + Tables\Columns\TextColumn::make('current_maximum') + ->label('Current Maximum') + ->default('-') + ->searchable() + ->alignCenter(), + Tables\Columns\TextColumn::make('class_of_insulation') + ->label('Class of Insulation') + ->default('-') + ->searchable() + ->alignCenter(), + Tables\Columns\TextColumn::make('testing_code') + ->label('Testing Code') + ->default('-') + ->searchable() + ->alignCenter(), + Tables\Columns\TextColumn::make('created_at') + ->label('Created At') + ->dateTime() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('created_by') + ->label('Created By') + ->searchable() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('updated_at') + ->label('Updated At') + ->dateTime() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('updated_by') + ->label('Updated By') + ->searchable() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('deleted_at') + ->label('Deleted At') + ->dateTime() + ->alignCenter() + ->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 () { + // return Plant::pluck('name', 'id'); + // }) + ->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('pumpTestingMasters', function ($query) { + $query->whereNotNull('id'); + })->orderBy('code')->pluck('name', 'id'); + } + + // return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); + }) + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $set('Item', null); + $set('isi_type', null); + $set('created_by', null); + $set('updated_by', null); + }), + Select::make('Item') + ->label('Search by Pump Code') + ->nullable() + ->options(function (callable $get) { + $pId = $get('Plant'); + + if (! $pId) { + return []; + } else { + return Item::whereHas('pumpTestingMasters', function ($query) use ($pId) { + if ($pId) { + $query->where('plant_id', $pId); + } + })->pluck('code', 'id'); + } + }) + ->searchable() + ->reactive(), + TextInput::make('description') + ->label('Pump Type') + ->placeholder('Enter the Pump Type'), + Select::make('motor_code') + ->label('Search by Motor Code') + ->nullable() + ->options(function (callable $get) { + $plantId = $get('Plant'); + if (! $plantId) { + return []; + } else { + return PumpTestingMaster::where('plant_id', $plantId)->whereNotNull('motor_code')->select('motor_code')->distinct()->pluck('motor_code', 'motor_code'); + } + }) + ->searchable() + ->reactive(), + Select::make('phase_type') + ->label('Select Phase') + ->nullable() + ->options(function (callable $get) { + $plantId = $get('plant_id'); + + if ($plantId) { + return Configuration::where('plant_id', $plantId) + ->where('c_name', 'PUMP_PHASE') + ->orderBy('created_at') + ->pluck('c_value', 'c_value') + ->toArray(); + } else { + return Configuration::where('c_name', 'PUMP_PHASE') + ->orderBy('created_at') + ->pluck('c_value', 'c_value') + ->toArray(); + } + }) + ->afterStateUpdated(function ($state, callable $set, callable $get) { + + if ($state == 'Single' && $get('connection_type') == 'STAR DELTA') { + $set('phase_type', 'Three'); + } + }) + ->reactive(), + Select::make('connection_type') + ->label('Select Connection') + ->nullable() + ->options(function (callable $get) { + $plantId = $get('plant_id'); + if ($plantId) { + return Configuration::where('plant_id', $plantId) + ->where('c_name', 'PUMP_CONNECTION') + ->orderBy('created_at') + ->pluck('c_value', 'c_value') + ->toArray(); + } else { + return Configuration::where('c_name', 'PUMP_CONNECTION') + ->orderBy('created_at') + ->pluck('c_value', 'c_value') + ->toArray(); + } + }) + ->afterStateUpdated(function ($state, callable $set) { + if ($state == 'STAR DELTA') { + $set('phase_type', 'Three'); + } + }) + ->reactive(), + Select::make('created_by') + ->label('Created By') + ->nullable() + ->options(function (callable $get) { + $plantId = $get('Plant'); + if (! $plantId) { + return PumpTestingMaster::whereNotNull('created_by')->select('created_by')->distinct()->pluck('created_by', 'created_by'); + } else { + return PumpTestingMaster::where('plant_id', $plantId)->whereNotNull('created_by')->select('created_by')->distinct()->pluck('created_by', 'created_by'); + } + }) + ->searchable() + ->reactive(), + DateTimePicker::make(name: 'created_from') + ->label('Created From') + ->placeholder(placeholder: 'Select From DateTime') + ->reactive() + ->native(false), + DateTimePicker::make('created_to') + ->label('Created To') + ->placeholder(placeholder: 'Select To DateTime') + ->reactive() + ->native(false), + Select::make('updated_by') + ->label('Updated By') + ->nullable() + ->options(function (callable $get) { + $plantId = $get('Plant'); + if (! $plantId) { + return PumpTestingMaster::whereNotNull('updated_by')->select('updated_by')->distinct()->pluck('updated_by', 'updated_by'); + } else { + return PumpTestingMaster::where('plant_id', $plantId)->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['Item']) && empty($data['description']) && empty($data['motor_code']) && empty($data['phase_type']) && empty($data['connection_type']) && empty($data['created_by']) && empty($data['created_from']) && empty($data['created_to']) && empty($data['updated_by']) && empty($data['updated_from']) && empty($data['updated_to'])) {// || $data['isi_type'] == 'All') + return $query->whereRaw('1 = 0'); + } + + if (! empty($data['Plant'])) { + $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['Item'])) { + $itemIds = Item::where('id', $data['Item']) + ->pluck('id') + ->toArray(); + + if (! empty($itemIds)) { + $query->whereIn('item_id', $itemIds); + } + } + + if (! empty($data['description'])) { + $pId = $data['Plant'] ?? null; + $descIds = Item::where('description', 'like', '%'.$data['description'].'%')->whereHas('pumpTestingMasters', function ($query) use ($pId) { + if ($pId) { + $query->where('plant_id', $pId); + } + })->pluck('id')->toArray(); + + if (! empty($descIds)) { + $query->whereIn('item_id', $descIds); + } + } + + if (! empty($data['motor_code'])) { + $query->where('motor_code', $data['motor_code']); + } + + if (! empty($data['phase_type'])) { + $query->where('phase', $data['phase_type']); + } + + if (! empty($data['connection_type'])) { + $query->where('connection_type', $data['connection_type']); + } + + 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['Item'])) { + $itemCode = Item::find($data['Item'])->code ?? 'Unknown'; + $indicators[] = 'Pump Code: '.$itemCode; + } + + if (! empty($data['description'])) { + $indicators[] = 'Pump Type: '.$data['description']; + } + + if (! empty($data['motor_code'])) { + $indicators[] = 'Motor Code: '.$data['motor_code']; + } + + if (! empty($data['phase_type'])) { + $indicators[] = 'Phase: '.$data['phase_type']; + } + + if (! empty($data['connection_type'])) { + $indicators[] = 'Connection: '.$data['connection_type']; + } + + 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(), + ]) + ->headerActions([ + ExportAction::make() + ->label('Export Pump Testing Masters') + ->color('warning') + ->exporter(PumpTestingMasterExporter::class) + ->visible(function () { + return Filament::auth()->user()->can('view export pump testing master'); + }), + ]) + ->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\ListPumpTestingMasters::route('/'), + 'create' => Pages\CreatePumpTestingMaster::route('/create'), + 'view' => Pages\ViewPumpTestingMaster::route('/{record}'), + 'edit' => Pages\EditPumpTestingMaster::route('/{record}/edit'), + ]; + } + + public static function getEloquentQuery(): Builder + { + return parent::getEloquentQuery() + ->withoutGlobalScopes([ + SoftDeletingScope::class, + ]); + } +} diff --git a/app/Filament/Resources/PumpTestingMasterResource/Pages/CreatePumpTestingMaster.php b/app/Filament/Resources/PumpTestingMasterResource/Pages/CreatePumpTestingMaster.php new file mode 100644 index 0000000..a5f6ab2 --- /dev/null +++ b/app/Filament/Resources/PumpTestingMasterResource/Pages/CreatePumpTestingMaster.php @@ -0,0 +1,12 @@ + Date: Mon, 24 Aug 2026 10:19:16 +0530 Subject: [PATCH 05/10] Added pump testing (master, entry, result) get api --- routes/api.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/routes/api.php b/routes/api.php index b65e45c..5f35861 100644 --- a/routes/api.php +++ b/routes/api.php @@ -152,6 +152,14 @@ Route::post('material-invoice/store-data', [InvoiceValidationController::class, Route::get('user/get-data', [UserController::class, 'get_user_data']); +// Pump Performance Software + +Route::get('testing/pump-master/get', [TestingPanelController::class, 'get_pump_master']); + +Route::get('testing/pump-entry/get', [TestingPanelController::class, 'get_pump_entry']); + +Route::get('testing/pump-result/get', [TestingPanelController::class, 'get_pump_result']); + // Testing panel Controller Route::get('testing/user/get-data', [UserController::class, 'get_user_data']); -- 2.49.1 From a59369111fd0516d5e96802daf87527ee0365990 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 24 Aug 2026 10:22:29 +0530 Subject: [PATCH 06/10] Added pump testing entry migration file --- ...2300_create_pump_testing_entries_table.php | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 database/migrations/2026_08_11_102300_create_pump_testing_entries_table.php diff --git a/database/migrations/2026_08_11_102300_create_pump_testing_entries_table.php b/database/migrations/2026_08_11_102300_create_pump_testing_entries_table.php new file mode 100644 index 0000000..2fbc47d --- /dev/null +++ b/database/migrations/2026_08_11_102300_create_pump_testing_entries_table.php @@ -0,0 +1,57 @@ + Date: Mon, 24 Aug 2026 10:24:55 +0530 Subject: [PATCH 07/10] Added pump testing entry policies and model file --- app/Models/PumpTestingEntry.php | 43 ++++++++++ app/Policies/PumpTestingEntryPolicy.php | 105 ++++++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 app/Models/PumpTestingEntry.php create mode 100644 app/Policies/PumpTestingEntryPolicy.php diff --git a/app/Models/PumpTestingEntry.php b/app/Models/PumpTestingEntry.php new file mode 100644 index 0000000..6d43a13 --- /dev/null +++ b/app/Models/PumpTestingEntry.php @@ -0,0 +1,43 @@ +belongsTo(Plant::class); + } + + public function pumpTestingMasters(): BelongsTo + { + return $this->belongsTo(PumpTestingMaster::class, 'pump_testing_master_id', 'id'); + } +} diff --git a/app/Policies/PumpTestingEntryPolicy.php b/app/Policies/PumpTestingEntryPolicy.php new file mode 100644 index 0000000..2497275 --- /dev/null +++ b/app/Policies/PumpTestingEntryPolicy.php @@ -0,0 +1,105 @@ +checkPermissionTo('view-any PumpTestingEntry'); + } + + /** + * Determine whether the user can view the model. + */ + public function view(User $user, PumpTestingEntry $pumptestingentry): bool + { + return $user->checkPermissionTo('view PumpTestingEntry'); + } + + /** + * Determine whether the user can create models. + */ + public function create(User $user): bool + { + return $user->checkPermissionTo('create PumpTestingEntry'); + } + + /** + * Determine whether the user can update the model. + */ + public function update(User $user, PumpTestingEntry $pumptestingentry): bool + { + return $user->checkPermissionTo('update PumpTestingEntry'); + } + + /** + * Determine whether the user can delete the model. + */ + public function delete(User $user, PumpTestingEntry $pumptestingentry): bool + { + return $user->checkPermissionTo('delete PumpTestingEntry'); + } + + /** + * Determine whether the user can delete any models. + */ + public function deleteAny(User $user): bool + { + return $user->checkPermissionTo('delete-any PumpTestingEntry'); + } + + /** + * Determine whether the user can restore the model. + */ + public function restore(User $user, PumpTestingEntry $pumptestingentry): bool + { + return $user->checkPermissionTo('restore PumpTestingEntry'); + } + + /** + * Determine whether the user can restore any models. + */ + public function restoreAny(User $user): bool + { + return $user->checkPermissionTo('restore-any PumpTestingEntry'); + } + + /** + * Determine whether the user can replicate the model. + */ + public function replicate(User $user, PumpTestingEntry $pumptestingentry): bool + { + return $user->checkPermissionTo('replicate PumpTestingEntry'); + } + + /** + * Determine whether the user can reorder the models. + */ + public function reorder(User $user): bool + { + return $user->checkPermissionTo('reorder PumpTestingEntry'); + } + + /** + * Determine whether the user can permanently delete the model. + */ + public function forceDelete(User $user, PumpTestingEntry $pumptestingentry): bool + { + return $user->checkPermissionTo('force-delete PumpTestingEntry'); + } + + /** + * Determine whether the user can permanently delete any models. + */ + public function forceDeleteAny(User $user): bool + { + return $user->checkPermissionTo('force-delete-any PumpTestingEntry'); + } +} -- 2.49.1 From 21bc0cf59eff205c52efb40e4221410f1b8d6f94 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 24 Aug 2026 10:32:06 +0530 Subject: [PATCH 08/10] Added pump testing entry model file for hasMany relations --- app/Models/Plant.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Models/Plant.php b/app/Models/Plant.php index 91b3dd6..7b3d18e 100644 --- a/app/Models/Plant.php +++ b/app/Models/Plant.php @@ -89,10 +89,10 @@ class Plant extends Model return $this->hasMany(PumpTestingMaster::class, 'plant_id', 'id'); } - // public function pumpTestingEntries() - // { - // return $this->hasMany(PumpTestingEntry::class, 'plant_id', 'id'); - // } + public function pumpTestingEntries() + { + return $this->hasMany(PumpTestingEntry::class, 'plant_id', 'id'); + } public function guardNames() { -- 2.49.1 From c097e5664009ac5e5f9763fbca9e9e45199bbf8b Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Mon, 24 Aug 2026 10:36:36 +0530 Subject: [PATCH 09/10] Added pump testing entry resource files and exporter file --- .../Exports/PumpTestingEntryExporter.php | 85 ++ .../Resources/PumpTestingEntryResource.php | 758 ++++++++++++++++++ .../Pages/CreatePumpTestingEntry.php | 12 + .../Pages/EditPumpTestingEntry.php | 22 + .../Pages/ListPumpTestingEntries.php | 19 + .../Pages/ViewPumpTestingEntry.php | 19 + 6 files changed, 915 insertions(+) create mode 100644 app/Filament/Exports/PumpTestingEntryExporter.php create mode 100644 app/Filament/Resources/PumpTestingEntryResource.php create mode 100644 app/Filament/Resources/PumpTestingEntryResource/Pages/CreatePumpTestingEntry.php create mode 100644 app/Filament/Resources/PumpTestingEntryResource/Pages/EditPumpTestingEntry.php create mode 100644 app/Filament/Resources/PumpTestingEntryResource/Pages/ListPumpTestingEntries.php create mode 100644 app/Filament/Resources/PumpTestingEntryResource/Pages/ViewPumpTestingEntry.php diff --git a/app/Filament/Exports/PumpTestingEntryExporter.php b/app/Filament/Exports/PumpTestingEntryExporter.php new file mode 100644 index 0000000..6b78607 --- /dev/null +++ b/app/Filament/Exports/PumpTestingEntryExporter.php @@ -0,0 +1,85 @@ +label('NO') + ->state(function ($record) use (&$rowNumber) { + // Increment and return the row number + return ++$rowNumber; + }), + ExportColumn::make('plant.code') + ->label('PLANT CODE'), + ExportColumn::make('tested_date') + ->label('TESTED DATE'), + ExportColumn::make('tested_type') + ->label('TESTED TYPE'), + ExportColumn::make('pumpTestingMaster.item.code') + ->label('PUMP CODE'), + ExportColumn::make('pumpTestingMaster.item.category') + ->label('PUMP CATEGORY') + ->enabledByDefault(false), + ExportColumn::make('pumpTestingMaster.item.description') + ->label('PUMP TYPE'), + ExportColumn::make('pumpTestingMaster.item.uom') + ->label('UNIT OF MEASURE') + ->enabledByDefault(false), + ExportColumn::make('pump_serial_number') + ->label('PUMP SERIAL NUMBER'), + ExportColumn::make('correction_head') + ->label('CORRECTION HEAD'), + ExportColumn::make('sl_no') + ->label('SL. NO.'), + ExportColumn::make('voltage') + ->label('VOLTAGE'), + ExportColumn::make('frequency') + ->label('FREQUENCY'), + ExportColumn::make('speed') + ->label('SPEED'), + ExportColumn::make('head') + ->label('HEAD'), + ExportColumn::make('flow_reading') + ->label('FLOW READING'), + ExportColumn::make('current') + ->label('CURRENT'), + ExportColumn::make('watt') + ->label('WATT'), + 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 pump testing entry 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; + } +} diff --git a/app/Filament/Resources/PumpTestingEntryResource.php b/app/Filament/Resources/PumpTestingEntryResource.php new file mode 100644 index 0000000..2905f71 --- /dev/null +++ b/app/Filament/Resources/PumpTestingEntryResource.php @@ -0,0 +1,758 @@ +schema([ + Section::make('') + ->schema([ + Forms\Components\Select::make('plant_id') + ->label('Plant Name') + ->relationship('plant', 'name') + ->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(); + }) + ->columnSpan(1) // (['default' => 1, 'sm' => 2]) + ->required() + ->searchable() + ->reactive() + ->default(function () { + $userHas = Filament::auth()->user()->plant_id; + + return ($userHas && strlen($userHas) > 0) ? $userHas : optional(PumpTestingEntry::latest()->first())->plant_id ?? null; + }) + ->disabled(fn (Get $get) => ! empty($get('id'))) + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $plantId = $get('plant_id'); + $set('pump_testing_master_id', null); + $set('pump_master_id', null); + // $set('pump_type', null); + + if (! $plantId) { + $set('pTeError', 'Please select a plant first.'); + + return; + } else { + $set('pTeError', null); + } + + $set('updated_by', Filament::auth()->user()?->name); + }) + ->extraAttributes(fn ($get) => [ + 'class' => $get('pTeError') ? 'border-red-500' : '', + ]) + ->hint(fn ($get) => $get('pTeError') ? $get('pTeError') : null) + ->hintColor('danger'), + Forms\Components\Select::make('tested_type') + ->label('Tested Type') + ->selectablePlaceholder(false) + ->options(function (callable $get) { + $plantId = $get('plant_id'); + if ($plantId) { + return Configuration::where('plant_id', $plantId) + ->where('c_name', 'PUMP_DISPLAY_TEST_TYPE') + ->whereNot('c_value', 'Routine Test') + ->orderBy('created_at') + ->pluck('c_value', 'c_value') + ->toArray(); + } else { + return Configuration::where('c_name', 'PUMP_DISPLAY_TEST_TYPE') + ->whereNot('c_value', 'Routine Test') + ->orderBy('created_at') + ->pluck('c_value', 'c_value') + ->toArray(); + } + }) + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->default('Pump Performance Test') + ->reactive(), + Forms\Components\DatePicker::make('tested_date') + ->label('Tested Date') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->default(now()) + ->required() + ->reactive(), + Forms\Components\TextInput::make('correction_head') + ->label('Correction Head') + ->placeholder('Scan the correction head') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\Hidden::make('pump_testing_master_id') + // ->relationship('pumpTestingMasters', 'id') + ->required(), + Forms\Components\Select::make('pump_master_id') + ->label('Pump Code') + // ->relationship('pumpTestingMasters', 'id') + ->options(function (callable $get) { + $plantId = $get('plant_id'); + if (! $plantId) { + return []; + } + + return Item::where('plant_id', $plantId)->whereHas('pumpTestingMasters')->orderBy('code')->pluck('code', 'code'); + }) + ->columnSpan(1) + ->required() + ->searchable() + ->reactive() + ->afterStateUpdated(function (callable $set, callable $get, ?string $state) { + $plantId = $get('plant_id'); // Get selected plant + $set('pump_testing_master_id', null); + // $set('pump_type', null); + if (! $plantId) { + $set('pump_master_id', null); + } elseif ($state) { + // $pumpMaster = PumpTestingMaster::where('plant_id', $plantId)->where('item_id', $state)->first(); + $pumpMaster = PumpTestingMaster::where('plant_id', $plantId)->whereHas('item', function ($query) use ($state) { + $query->where('code', $state); + })->first(); + + if (! $pumpMaster) { + $set('pump_master_id', null); + } else { + $set('pump_testing_master_id', $pumpMaster->id); + // $set('pump_type', $pumpMaster->item->description ?? null); + } + } + + $set('updated_by', Filament::auth()->user()?->name); + }) + ->afterStateHydrated(function ($component, $state, Get $get, Set $set) { + if ($get('id')) { + $itemId = PumpTestingMaster::where('id', $get('pump_testing_master_id'))->first()?->item_id; + if ($itemId) { + $item = Item::where('id', $itemId)->first()?->code; + if ($item) { + $set('pump_master_id', $item); + } else { + $set('pump_master_id', null); + } + } else { + $set('pump_master_id', null); + } + } + }), + // Forms\Components\TextInput::make('pump_type') + // ->label('Pump Type]') + // ->placeholder('Choose the pump code first') + // ->readOnly() + // ->afterStateUpdated(function ($state, callable $set) { + // $set('updated_by', Filament::auth()->user()?->name); + // }) + // ->columnSpan(1) + // ->required() + // ->reactive(), + Forms\Components\TextInput::make('pump_serial_number') + ->label('Pump Serial Number') + ->placeholder('Scan the pump serial number') + ->rule(function (callable $get) { + return Rule::unique('pump_testing_entries', 'pump_serial_number') + ->where('plant_id', $get('plant_id')) + ->where('pump_testing_master_id', $get('pump_testing_master_id')) + ->where('tested_type', $get('tested_type')) + ->where('sl_no', $get('sl_no')) + ->ignore($get('id')); + }) + ->afterStateUpdated(function ($state, callable $set) { + + if (strpos($state, '|') != false) { + $parts = explode('|', $state); + $set('pump_serial_number', $parts[1]); + } + + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('sl_no') + ->label('Sl. No.') + ->placeholder('Scan the sl. no.') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('voltage') + ->label('Voltage') + ->placeholder('Scan the voltage') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('frequency') + ->label('Frequency') + ->placeholder('Scan the frequency') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('speed') + ->label('Speed') + ->placeholder('Scan the speed') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('head') + ->label('Head') + ->placeholder('Scan the head') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('flow_reading') + ->label('Flow Reading') + ->placeholder('Scan the flow reading') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('current') + ->label('Current') + ->placeholder('Scan the current') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\TextInput::make('watt') + ->label('Watt') + ->placeholder('Scan the watt') + ->afterStateUpdated(function ($state, callable $set) { + $set('updated_by', Filament::auth()->user()?->name); + }) + ->columnSpan(1) + ->required() + ->reactive(), + Forms\Components\Hidden::make('created_by') + ->default(fn () => Filament::auth()->user()?->name) + ->columnSpan(1) + ->required(), + Forms\Components\Hidden::make('updated_by') + ->default(fn () => Filament::auth()->user()?->name) + ->columnSpan(1) + ->required(), + Forms\Components\TextInput::make('id') + ->hidden() + ->columnSpan(1) + ->readOnly(), + ]) + ->columns(['default' => 1, 'sm' => 2]), + ]); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + // Tables\Columns\TextColumn::make('id') + // ->label('ID') + // ->numeric() + // ->sortable(), + 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') + ->searchable() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('tested_date') + ->label('Tested Date') + ->date() // 'F d, Y' + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('tested_type') + ->label('Tested Type') + ->searchable() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('pumpTestingMasters.item.code') + ->label('Pump Code') + ->searchable() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('pumpTestingMasters.item.category') + ->label('Pump Category') + ->default('-') + ->searchable() + ->alignCenter() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('pumpTestingMasters.item.description') + ->label('Pump Type') + ->searchable() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('pumpTestingMasters.item.uom') + ->label('Unit Of Measure') + ->default('-') + ->searchable() + ->alignCenter() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + Tables\Columns\TextColumn::make('pump_serial_number') + ->label('Pump Serial Number') + ->searchable() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('correction_head') + ->label('Correction Head') + ->searchable() + ->alignCenter(), + // ->sortable(), + Tables\Columns\TextColumn::make('sl_no') + ->label('Sl. No.') + ->searchable() + ->alignCenter(), + // ->sortable(), + Tables\Columns\TextColumn::make('voltage') + ->label('Voltage') + ->searchable() + ->alignCenter(), + // ->sortable(), + Tables\Columns\TextColumn::make('frequency') + ->label('Frequency') + ->searchable() + ->alignCenter(), + // ->sortable(), + Tables\Columns\TextColumn::make('speed') + ->label('Speed') + ->searchable() + ->alignCenter(), + // ->sortable(), + Tables\Columns\TextColumn::make('head') + ->label('Head') + ->searchable() + ->alignCenter(), + // ->sortable(), + Tables\Columns\TextColumn::make('flow_reading') + ->label('Flow Reading') + ->searchable() + ->alignCenter(), + // ->sortable(), + Tables\Columns\TextColumn::make('current') + ->label('Current') + ->searchable() + ->alignCenter(), + // ->sortable(), + Tables\Columns\TextColumn::make('watt') + ->label('Watt') + ->searchable() + ->alignCenter(), + // ->sortable(), + Tables\Columns\TextColumn::make('created_by') + ->label('Created By') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('created_at') + ->label('Created At') + ->dateTime() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('updated_by') + ->label('Updated By') + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('updated_at') + ->label('Updated At') + ->dateTime() + ->alignCenter() + ->sortable(), + Tables\Columns\TextColumn::make('deleted_at') + ->label('Deleted At') + ->dateTime() + ->alignCenter() + ->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() + // ->options(function () { + // return Plant::pluck('name', 'id'); + // }) + ->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('pumpTestingEntries', function ($query) { + $query->whereNotNull('id'); + })->orderBy('code')->pluck('name', 'id'); + } + + // return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray(); + }) + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $set('Item', null); + $set('isi_type', null); + $set('created_by', null); + $set('updated_by', null); + }), + DatePicker::make('tested_from') + ->label('Tested From') + ->placeholder('Select From Date') + ->reactive() + ->native(false), + DatePicker::make('tested_to') + ->label('Tested To') + ->placeholder('Select To Date') + ->reactive() + ->native(false), + Select::make('tested_type') + ->label('Tested Type') + ->nullable() + ->options(function (callable $get) { + $plantId = $get('Plant'); + if (! $plantId) { + return PumpTestingEntry::whereNotNull('tested_type')->select('tested_type')->distinct()->pluck('tested_type', 'tested_type'); + } else { + return PumpTestingEntry::where('plant_id', $plantId)->whereNotNull('tested_type')->select('tested_type')->distinct()->pluck('tested_type', 'tested_type'); + } + }) + ->searchable() + ->reactive(), + Select::make('Item') + ->label('Search by Pump Code') + ->nullable() + ->options(function (callable $get) { + $pId = $get('Plant'); + + if (! $pId) { + return []; + } else { + return Item::whereHas('pumpTestingMasters', function ($query) use ($pId) { + if ($pId) { + $query->where('plant_id', $pId); + } + $query->whereHas('pumpTestingEntries'); + })->pluck('code', 'id'); + } + }) + ->searchable() + ->reactive(), + TextInput::make('description') + ->label('Pump Type') + ->placeholder('Enter the Pump Type'), + TextInput::make('pump_serial_number') + ->label('Pump Serial Number') + ->placeholder('Enter the Pump Serial Number'), + Select::make('created_by') + ->label('Search by Created By') + ->nullable() + ->options(function (callable $get) { + $plantId = $get('Plant'); + if (! $plantId) { + return PumpTestingEntry::whereNotNull('created_by')->select('created_by')->distinct()->pluck('created_by', 'created_by'); + } else { + return PumpTestingEntry::where('plant_id', $plantId)->whereNotNull('created_by')->select('created_by')->distinct()->pluck('created_by', 'created_by'); + } + }) + ->searchable() + ->reactive(), + DateTimePicker::make(name: 'created_from') + ->label('Created From') + ->placeholder(placeholder: 'Select From DateTime') + ->reactive() + ->native(false), + DateTimePicker::make('created_to') + ->label('Created To') + ->placeholder(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 PumpTestingEntry::whereNotNull('updated_by')->select('updated_by')->distinct()->pluck('updated_by', 'updated_by'); + } else { + return PumpTestingEntry::where('plant_id', $plantId)->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['tested_from']) && empty($data['tested_to']) && empty($data['tested_type']) && empty($data['Item']) && empty($data['description']) && empty($data['pump_serial_number']) && empty($data['created_by']) && empty($data['created_from']) && empty($data['created_to']) && empty($data['updated_by']) && empty($data['updated_from']) && empty($data['updated_to'])) {// || $data['isi_type'] == 'All') + return $query->whereRaw('1 = 0'); + } + + if (! empty($data['Plant'])) { + $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['tested_from'])) { + $query->where('tested_date', '>=', $data['tested_from']); + } + + if (! empty($data['tested_to'])) { + $query->where('tested_date', '<=', $data['tested_to']); + } + + if (! empty($data['tested_type'])) { + $query->where('tested_type', $data['tested_type']); + } + + if (! empty($data['Item']) && ! empty($data['Plant'])) { + $itemIds = Item::where('id', $data['Item']) + ->where('plant_id', $data['Plant']) + ->pluck('id') + ->toArray(); + + if (! empty($itemIds)) { + $query->whereIn('item_id', $itemIds); + } + } + + if (! empty($data['description'])) { + $pId = $data['Plant'] ?? null; + $descIds = Item::where('description', 'like', '%'.$data['description'].'%')->whereHas('pumpTestingMasters', function ($query) use ($pId) { + if ($pId) { + $query->where('plant_id', $pId); + } + })->pluck('id')->toArray(); + + if (! empty($descIds)) { + $query->whereIn('item_id', $descIds); + } + } + + if (! empty($data['pump_serial_number'])) { + $query->where('pump_serial_number', 'like', '%'.$data['pump_serial_number'].'%'); + } + + 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['tested_from'])) { + $indicators[] = 'Tested From: '.$data['tested_from']; + } + + if (! empty($data['tested_to'])) { + $indicators[] = 'Tested To: '.$data['tested_to']; + } + + if (! empty($data['tested_type'])) { + $indicators[] = 'Tested Type: '.$data['tested_type']; + } + + if (! empty($data['Item']) && ! empty($data['Plant'])) { + $itemCode = Item::find($data['Item'])->code ?? 'Unknown'; + $indicators[] = 'Pump Code: '.$itemCode; + } + + if (! empty($data['description'])) { + $indicators[] = 'Pump Type: '.$data['description']; + } + + if (! empty($data['pump_serial_number'])) { + $indicators[] = 'Pump Serial Number: '.$data['pump_serial_number']; + } + + 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(), + ]) + ->headerActions([ + ExportAction::make() + ->label('Export Pump Testing Entries') + ->color('warning') + ->exporter(PumpTestingEntryExporter::class) + ->visible(function () { + return Filament::auth()->user()->can('view export pump testing entries'); + }), + ]) + ->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\ListPumpTestingEntries::route('/'), + 'create' => Pages\CreatePumpTestingEntry::route('/create'), + 'view' => Pages\ViewPumpTestingEntry::route('/{record}'), + 'edit' => Pages\EditPumpTestingEntry::route('/{record}/edit'), + ]; + } + + public static function getEloquentQuery(): Builder + { + return parent::getEloquentQuery() + ->withoutGlobalScopes([ + SoftDeletingScope::class, + ]); + } +} diff --git a/app/Filament/Resources/PumpTestingEntryResource/Pages/CreatePumpTestingEntry.php b/app/Filament/Resources/PumpTestingEntryResource/Pages/CreatePumpTestingEntry.php new file mode 100644 index 0000000..abe2bf0 --- /dev/null +++ b/app/Filament/Resources/PumpTestingEntryResource/Pages/CreatePumpTestingEntry.php @@ -0,0 +1,12 @@ + Date: Mon, 24 Aug 2026 10:40:23 +0530 Subject: [PATCH 10/10] Added pump testing master and entry get api function with validations --- .../Controllers/TestingPanelController.php | 654 ++++++++++++++++++ 1 file changed, 654 insertions(+) diff --git a/app/Http/Controllers/TestingPanelController.php b/app/Http/Controllers/TestingPanelController.php index 61b45a7..ab8d6b9 100644 --- a/app/Http/Controllers/TestingPanelController.php +++ b/app/Http/Controllers/TestingPanelController.php @@ -8,6 +8,8 @@ use App\Models\LeakTestReading; use App\Models\Machine; use App\Models\MotorTestingMaster; use App\Models\Plant; +use App\Models\PumpTestingEntry; +use App\Models\PumpTestingMaster; use App\Models\TestingPanelReading; use App\Models\WorkGroupMaster; use Illuminate\Http\Request; @@ -1061,6 +1063,658 @@ class TestingPanelController extends Controller return response()->json($output, 200); } + public function get_pump_master(Request $request) + { + $expectedUser = env('API_AUTH_USER'); + $expectedPw = env('API_AUTH_PW'); + $header_auth = $request->header('Authorization'); + $expectedToken = $expectedUser.':'.$expectedPw; + + // $data = $request->all(); + if ('Bearer '.$expectedToken != $header_auth) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Invalid authorization token!', + ], 403); + } + + $plantCode = $request->header('plant-code'); + $pumpCode = $request->header('pump-code'); + // $description = $item ? $item->description : ''; + + if ($plantCode == null || $plantCode == '') { + // return response("ERROR: Plant Name can't be empty", 400) + // ->header('Content-Type', 'text/plain'); + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Plant code can't be empty!", + ], 400); + } elseif (Str::length($plantCode) < 4 || ! is_numeric($plantCode) || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Invalid plant code found!', + ], 400); + } elseif ($pumpCode == null || $pumpCode == '' || ! $pumpCode) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump code can't be empty!", + ], 404); + } elseif (Str::length($pumpCode) < 6) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump code '{$pumpCode}' should contain minimum 6 digits!", + ], 404); + } elseif (! ctype_alnum($pumpCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump code '{$pumpCode}' should contain only alpha-numeric values!", + ], 404); + } elseif (! preg_match('/^[a-zA-Z1-9][a-zA-Z0-9]{5,}$/', $pumpCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump code '{$pumpCode}' should not begin with '0'!", + ], 404); + } + + $plant = Plant::where('code', $plantCode)->first(); + + if (! $plant) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Plant not found!', + ], 400); + } + + $plantId = $plant->id; + $plantName = $plant->name; + + $item = Item::where('code', $pumpCode)->first(); + + if (! $item) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Pump code not found in item master table!', + ], 404); + } + + $item = Item::where('plant_id', $plantId)->where('code', $pumpCode)->first(); + + if (! $item) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump code not found in item master table for the plant : '$plantName'!", + ], 404); + } + + $itemId = $item->id; + + $description = $item ? $item->description : ''; + + // $category = $item ? $item->category : ''; + + $pumpTestingMaster = PumpTestingMaster::where('item_id', $itemId)->first(); + + if (! $pumpTestingMaster) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Pump code not found in pump testing master table!', + ], 404); + } + + $pumpTestingMaster = PumpTestingMaster::where('plant_id', $plantId)->where('item_id', $itemId)->first(); + + if (! $pumpTestingMaster) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump code not found in pump testing master table for the plant : '$plantName'!", + ], 404); + } + + $output = [ + 'pump_type' => ($pumpCode == '123456') ? 'SAMPLE TYPE' : $description, + 'head' => $pumpTestingMaster->head ?? '', + 'head_type' => $pumpTestingMaster->head_type ?? '', + 'discharge' => $pumpTestingMaster->discharge ?? '', + 'discharge_type' => $pumpTestingMaster->discharge_type ?? '', + 'motor_efficiency' => $pumpTestingMaster->motor_efficiency ?? '', + 'pump_efficiency' => $pumpTestingMaster->pump_efficiency ?? '', + 'speed' => $pumpTestingMaster->speed ?? '', + 'frequency' => $pumpTestingMaster->frequency ?? '', + 'i_max' => $pumpTestingMaster->i_max ?? '', + 'p_input' => $pumpTestingMaster->p_input ?? '', + 'delivery_size' => $pumpTestingMaster->delivery_size ?? '', + 'no_of_stages' => $pumpTestingMaster->no_of_stages ?? '', + 'size' => $pumpTestingMaster->size ?? '', + 'maximum_head' => $pumpTestingMaster->maximum_head ?? '', + 'motor_type' => $pumpTestingMaster->motor_type ?? '', + 'motor_code' => $pumpTestingMaster->motor_code ?? '', + 'kw_hp' => $pumpTestingMaster->kw_hp ?? '', + 'connection_type' => $pumpTestingMaster->connection_type ?? '', + 'voltage' => $pumpTestingMaster->voltage ?? '', + 'phase' => $pumpTestingMaster->phase ?? '', + 'oh_minimum' => $pumpTestingMaster->oh_minimum ?? '', + 'oh_maximum' => $pumpTestingMaster->oh_maximum ?? '', + 'current_minimum' => $pumpTestingMaster->current_minimum ?? '', + 'current_maximum' => $pumpTestingMaster->current_maximum ?? '', + 'class_of_insulation' => $pumpTestingMaster->class_of_insulation ?? '', + 'testing_code' => $pumpTestingMaster->testing_code ?? '', + ]; + + return response()->json($output, 200); + } + + public function get_pump_entry(Request $request) + { + $expectedUser = env('API_AUTH_USER'); + $expectedPw = env('API_AUTH_PW'); + $header_auth = $request->header('Authorization'); + $expectedToken = $expectedUser.':'.$expectedPw; + + // $data = $request->all(); + if ('Bearer '.$expectedToken != $header_auth) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Invalid authorization token!', + ], 403); + } + + $plantCode = $request->header('plant-code'); + $pumpCode = $request->header('pump-code'); + $pumpSerial = $request->header('pump-serial-number'); + $testedType = $request->header('tested-type') ?? 'Pump Performance Test'; + + if ($plantCode == null || $plantCode == '') { + // return response("ERROR: Plant Name can't be empty", 400) + // ->header('Content-Type', 'text/plain'); + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Plant code can't be empty!", + ], 400); + } elseif (Str::length($plantCode) < 4 || ! is_numeric($plantCode) || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Invalid plant code found!', + ], 400); + } elseif ($pumpCode == null || $pumpCode == '' || ! $pumpCode) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump code can't be empty!", + ], 404); + } elseif (Str::length($pumpCode) < 6) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump code '{$pumpCode}' should contain minimum 6 digits!", + ], 404); + } elseif (! ctype_alnum($pumpCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump code '{$pumpCode}' should contain only alpha-numeric values!", + ], 404); + } elseif (! preg_match('/^[a-zA-Z1-9][a-zA-Z0-9]{5,}$/', $pumpCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump code '{$pumpCode}' should not begin with '0'!", + ], 404); + } elseif ($pumpSerial == null || $pumpSerial == '' || ! $pumpSerial) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump serial number can't be empty!", + ], 404); + } elseif (Str::length($pumpSerial) < 9) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump serial number '{$pumpSerial}' should contain minimum 9 digits!", + ], 404); + } elseif (! ctype_alnum($pumpSerial)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump serial number '{$pumpSerial}' should contain only alpha-numeric values!", + ], 404); + } elseif (! preg_match('/^[1-9][a-zA-Z0-9]{8,}$/', $pumpSerial)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump serial number '{$pumpSerial}' should not begin with '0' or letter!", + ], 404); + } elseif ($testedType == null || $testedType == '' || ! $testedType) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Tested type can't be empty!", + ], 404); + } + + $plant = Plant::where('code', $plantCode)->first(); + + if (! $plant) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Plant not found!', + ], 400); + } + + $plantId = $plant->id; + $plantName = $plant->name; + + $item = Item::where('code', $pumpCode)->first(); + + if (! $item) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Pump code not found in item master table!', + ], 404); + } + + $item = Item::where('plant_id', $plantId)->where('code', $pumpCode)->first(); + + if (! $item) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump code not found in item master table for the plant : '$plantName'!", + ], 404); + } + + $itemId = $item->id; + + // $description = $item ? $item->description : ''; + + $pumpTestingMaster = PumpTestingMaster::where('item_id', $itemId)->first(); + + if (! $pumpTestingMaster) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Pump code not found in pump testing master table!', + ], 404); + } + + $pumpTestingMaster = PumpTestingMaster::where('plant_id', $plantId)->where('item_id', $itemId)->first(); + + if (! $pumpTestingMaster) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump code not found in pump testing master table for the plant : '$plantName'!", + ], 404); + } + + $pumpMasterId = $pumpTestingMaster->id; + + $pumpTestingEntry = PumpTestingEntry::where('pump_testing_master_id', $pumpMasterId)->first(); + + if (! $pumpTestingEntry) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Pump code not found in pump testing entry table!', + ], 404); + } + + $pumpTestingEntry = PumpTestingEntry::where('plant_id', $plantId)->where('pump_testing_master_id', $pumpMasterId)->first(); + + if (! $pumpTestingEntry) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump code not found in pump testing entry table for the plant : '$plantName'!", + ], 404); + } + + $entries = $result['pump_entries'] ?? []; + + if (empty($entries)) { + $entries = [ + [ + 'sl_no' => '1', + 'voltage' => '415', + 'frequency' => '50.02', + 'speed' => '2976', + 'head' => '5', + 'flow_reading' => '18.75', + 'current' => '61.8', + 'watt' => '40730', + 'created_by' => 'test', + 'created_at' => '2026-07-16 00:00:00', + ], + [ + 'sl_no' => '2', + 'voltage' => '415', + 'frequency' => '50.05', + 'speed' => '2976', + 'head' => '100', + 'flow_reading' => '18.71', + 'current' => '72.7', + 'watt' => '47100', + 'created_by' => 'test', + 'created_at' => '2026-07-16 00:00:00', + ], + [ + 'sl_no' => '3', + 'voltage' => '415', + 'frequency' => '50.04', + 'speed' => '2975', + 'head' => '150', + 'flow_reading' => '17.65', + 'current' => '76.3', + 'watt' => '48000', + 'created_by' => 'test', + 'created_at' => '2026-07-16 00:00:00', + ], + [ + 'sl_no' => '4', + 'voltage' => '415', + 'frequency' => '50.02', + 'speed' => '2974', + 'head' => '200', + 'flow_reading' => '15.65', + 'current' => '74', + 'watt' => '47760', + 'created_by' => 'test', + 'created_at' => '2026-07-16 00:00:00', + ], + [ + 'sl_no' => '5', + 'voltage' => '415', + 'frequency' => '50.04', + 'speed' => '2977', + 'head' => '250', + 'flow_reading' => '12.51', + 'current' => '68.2', + 'watt' => '45240', + 'created_by' => 'test', + 'created_at' => '2026-07-16 00:00:00', + ], + [ + 'sl_no' => '6', + 'voltage' => '415', + 'frequency' => '50', + 'speed' => '2979', + 'head' => '270', + 'flow_reading' => '11.53', + 'current' => '65.5', + 'watt' => '43050', + 'created_by' => 'test', + 'created_at' => '2026-07-16 00:00:00', + ], + [ + 'sl_no' => '7', + 'voltage' => '415', + 'frequency' => '50.05', + 'speed' => '2983', + 'head' => '300', + 'flow_reading' => '8.65', + 'current' => '57.4', + 'watt' => '37460', + 'created_by' => 'Dhanabalan S', + 'created_at' => '2026-07-17 00:00:00', + ], + [ + 'sl_no' => '8', + 'voltage' => '415', + 'frequency' => '50.03', + 'speed' => '2990', + 'head' => '325', + 'flow_reading' => '0', + 'current' => '35.8', + 'watt' => '21300', + 'created_by' => 'Dhanabalan S', + 'created_at' => '2026-07-17 00:00:00', + ], + ]; + } + + $output = [ + 'tested_date' => $result['tested_date'] ?? '2026-07-16', + // 'tested_type' => $result['tested_type'] ?? 'Pump Performance Test', + 'correction_head' => $result['correction_head'] ?? '5.0', + 'pump_entries' => array_map(function ($entry) { + return [ + 'sl_no' => $entry['sl_no'] ?? '', + 'voltage' => $entry['voltage'] ?? '', + 'frequency' => $entry['frequency'] ?? '', + 'speed' => $entry['speed'] ?? '', + 'head' => $entry['head'] ?? '', + 'flow_reading' => $entry['flow_reading'] ?? '', + 'current' => $entry['current'] ?? '', + 'watt' => $entry['watt'] ?? '', + 'tested_by' => $entry['created_by'] ?? '', + 'created_datetime' => $entry['created_at'] ?? '', + ]; + }, $entries ?? []), + ]; + + return response()->json($output, 200); + } + + public function get_pump_result(Request $request) + { + $expectedUser = env('API_AUTH_USER'); + $expectedPw = env('API_AUTH_PW'); + $header_auth = $request->header('Authorization'); + $expectedToken = $expectedUser.':'.$expectedPw; + + // $data = $request->all(); + if ('Bearer '.$expectedToken != $header_auth) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Invalid authorization token!', + ], 403); + } + + $plantCode = $request->header('plant-code'); + $pumpCode = $request->header('pump-code'); + $pumpSerial = $request->header('pump-serial-number'); + + if ($plantCode == null || $plantCode == '') { + // return response("ERROR: Plant Name can't be empty", 400) + // ->header('Content-Type', 'text/plain'); + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Plant code can't be empty!", + ], 400); + } elseif (Str::length($plantCode) < 4 || ! is_numeric($plantCode) || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Invalid plant code found!', + ], 400); + } elseif ($pumpCode == null || $pumpCode == '' || ! $pumpCode) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump code can't be empty!", + ], 404); + } elseif (Str::length($pumpCode) < 6) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump code '{$pumpCode}' should contain minimum 6 digits!", + ], 404); + } elseif (! ctype_alnum($pumpCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump code '{$pumpCode}' should contain only alpha-numeric values!", + ], 404); + } elseif (! preg_match('/^[a-zA-Z1-9][a-zA-Z0-9]{5,}$/', $pumpCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump code '{$pumpCode}' should not begin with '0'!", + ], 404); + } elseif ($pumpSerial == null || $pumpSerial == '' || ! $pumpSerial) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump serial number can't be empty!", + ], 404); + } elseif (Str::length($pumpSerial) < 9) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump serial number '{$pumpSerial}' should contain minimum 9 digits!", + ], 404); + } elseif (! ctype_alnum($pumpSerial)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump serial number '{$pumpSerial}' should contain only alpha-numeric values!", + ], 404); + } elseif (! preg_match('/^[1-9][a-zA-Z0-9]{8,}$/', $pumpSerial)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump serial number '{$pumpSerial}' should not begin with '0' or letter!", + ], 404); + } + + $plant = Plant::where('code', $plantCode)->first(); + + if (! $plant) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Plant not found!', + ], 400); + } + + $plantId = $plant->id; + $plantName = $plant->name; + + $item = Item::where('code', $pumpCode)->first(); + + if (! $item) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Pump code not found in item master table!', + ], 404); + } + + $item = Item::where('plant_id', $plantId)->where('code', $pumpCode)->first(); + + if (! $item) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Pump code not found in item master table for the plant : '$plantName'!", + ], 404); + } + + $itemId = $item->id; + + $description = $item ? $item->description : ''; + + $category = $item ? $item->category : ''; + + // $pumpTestingMaster = PumpTestingMaster::where('item_id', $itemId)->first(); + + // if (! $pumpTestingMaster) { + // return response()->json([ + // 'status_code' => 'ERROR', + // 'status_description' => 'Pump code not found in pump testing master table!', + // ], 404); + // } + + // $pumpTestingMaster = PumpTestingMaster::where('plant_id', $plantId)->where('item_id', $itemId)->first(); + + // if (! $pumpTestingMaster) { + // return response()->json([ + // 'status_code' => 'ERROR', + // 'status_description' => "Pump code not found in pump testing master table for the plant : '$plantName'!", + // ], 404); + // } + + $entries = $result['pump_entries'] ?? []; + + if (empty($entries)) { + $entries = [ + [ + 'sl_no' => '1', + 'voltage' => '415', + 'frequency' => '50.02', + 'speed' => '2976', + 'head' => '5', + 'flow_reading' => '18.75', + 'current' => '61.8', + 'watt' => '40730', + ], + [ + 'sl_no' => '2', + 'voltage' => '415', + 'frequency' => '50.05', + 'speed' => '2976', + 'head' => '100', + 'flow_reading' => '18.71', + 'current' => '72.7', + 'watt' => '47100', + ], + [ + 'sl_no' => '3', + 'voltage' => '415', + 'frequency' => '50.04', + 'speed' => '2975', + 'head' => '150', + 'flow_reading' => '17.65', + 'current' => '76.3', + 'watt' => '48000', + ], + [ + 'sl_no' => '4', + 'voltage' => '415', + 'frequency' => '50.02', + 'speed' => '2974', + 'head' => '200', + 'flow_reading' => '15.65', + 'current' => '74', + 'watt' => '47760', + ], + [ + 'sl_no' => '5', + 'voltage' => '415', + 'frequency' => '50.04', + 'speed' => '2977', + 'head' => '250', + 'flow_reading' => '12.51', + 'current' => '68.2', + 'watt' => '45240', + ], + [ + 'sl_no' => '6', + 'voltage' => '415', + 'frequency' => '50', + 'speed' => '2979', + 'head' => '270', + 'flow_reading' => '11.53', + 'current' => '65.5', + 'watt' => '43050', + ], + [ + 'sl_no' => '7', + 'voltage' => '415', + 'frequency' => '50.05', + 'speed' => '2983', + 'head' => '300', + 'flow_reading' => '8.65', + 'current' => '57.4', + 'watt' => '37460', + ], + [ + 'sl_no' => '8', + 'voltage' => '415', + 'frequency' => '50.03', + 'speed' => '2990', + 'head' => '325', + 'flow_reading' => '0', + 'current' => '35.8', + 'watt' => '21300', + ], + ]; + } + + $output = [ + 'tested_date' => $result['tested_date'] ?? '2026-07-16', + 'test_type' => $result['test-type'] ?? 'Pump Performance Test', + 'correction_head' => $result['correction_head'] ?? '5.0', + 'pump_entries' => array_map(function ($entry) { + return [ + 'sl_no' => $entry['sl_no'] ?? '', + 'voltage' => $entry['voltage'] ?? '', + 'frequency' => $entry['frequency'] ?? '', + 'speed' => $entry['speed'] ?? '', + 'head' => $entry['head'] ?? '', + 'flow_reading' => $entry['flow_reading'] ?? '', + 'current' => $entry['current'] ?? '', + 'watt' => $entry['watt'] ?? '', + ]; + }, $entries ?? []), + ]; + + return response()->json($output, 200); + } + /** * Update the specified resource in storage. */ -- 2.49.1