4 Commits

Author SHA1 Message Date
dhanabalan
c309bed7d9 Added mfm reading policy file 2025-07-18 18:24:15 +05:30
dhanabalan
b2dc9e7024 Added mfm reading resource file 2025-07-18 18:23:57 +05:30
dhanabalan
bff2601ddc Added Mfm reading model file 2025-07-18 18:22:54 +05:30
dhanabalan
e80812b82e Added mfm reading migration file 2025-07-18 18:22:31 +05:30
8 changed files with 517 additions and 0 deletions

View File

@@ -0,0 +1,223 @@
<?php
namespace App\Filament\Resources;
use App\Filament\Resources\MfmReadingResource\Pages;
use App\Filament\Resources\MfmReadingResource\RelationManagers;
use App\Models\MfmReading;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class MfmReadingResource extends Resource
{
protected static ?string $model = MfmReading::class;
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
protected static ?string $navigationGroup = 'Power House';
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('plant_id')
->relationship('plant', 'name')
->required(),
Forms\Components\Select::make('mfm_meter_id')
->relationship('mfmMeter', 'name')
->required(),
Forms\Components\TextInput::make('apparent_energy_received'),
Forms\Components\TextInput::make('reactive_energy_received'),
Forms\Components\TextInput::make('active_energy_received'),
Forms\Components\TextInput::make('active_power_r'),
Forms\Components\TextInput::make('active_power_y'),
Forms\Components\TextInput::make('active_power_b'),
Forms\Components\TextInput::make('active_power_total'),
Forms\Components\TextInput::make('voltage_ry'),
Forms\Components\TextInput::make('voltage_yb'),
Forms\Components\TextInput::make('voltage_br'),
Forms\Components\TextInput::make('current_r'),
Forms\Components\TextInput::make('current_y'),
Forms\Components\TextInput::make('current_b'),
Forms\Components\TextInput::make('current_n'),
Forms\Components\TextInput::make('voltage_r_n'),
Forms\Components\TextInput::make('voltage_y_n'),
Forms\Components\TextInput::make('voltage_b_n'),
Forms\Components\TextInput::make('frequency'),
Forms\Components\TextInput::make('power_factor_r'),
Forms\Components\TextInput::make('power_factor_y'),
Forms\Components\TextInput::make('power_factor_b'),
Forms\Components\TextInput::make('power_factor_total'),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('id')
->label('ID')
->alignCenter()
->numeric()
->sortable(),
Tables\Columns\TextColumn::make('plant.name')
->label('Plant')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('mfmMeter.name')
->label('Mfm Meter')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('apparent_energy_received')
->label('Apparent Energy Received')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('reactive_energy_received')
->label('Reactive Energy Received')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('active_energy_received')
->label('Active Energy Received')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('active_power_r')
->label('Active Power R')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('active_power_y')
->label('Active Power Y')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('active_power_b')
->label('Active Power B')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('active_power_total')
->label('Active Power Total')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('voltage_ry')
->label('Voltage RY')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('voltage_yb')
->label('Voltage YB')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('voltage_br')
->label('Voltage BR')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('current_r')
->label('Current R')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('current_y')
->label('Current Y')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('current_b')
->label('Current B')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('current_n')
->label('Current N')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('voltage_r_n')
->label('Voltage R N')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('voltage_y_n')
->label('Voltage Y N')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('voltage_b_n')
->label('Voltage B N')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('frequency')
->label('Frequency')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('power_factor_r')
->label('Power Factor R')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('power_factor_y')
->label('Power Factor Y')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('power_factor_b')
->label('Power Factor B')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('power_factor_total')
->label('Power Factor Total')
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('created_at')
->label('Created At')
->alignCenter()
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('updated_at')
->label('Updated At')
->alignCenter()
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('deleted_at')
->label('Deleted At')
->alignCenter()
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
Tables\Filters\TrashedFilter::make(),
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
Tables\Actions\ForceDeleteBulkAction::make(),
Tables\Actions\RestoreBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListMfmReadings::route('/'),
'create' => Pages\CreateMfmReading::route('/create'),
'view' => Pages\ViewMfmReading::route('/{record}'),
'edit' => Pages\EditMfmReading::route('/{record}/edit'),
];
}
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery()
->withoutGlobalScopes([
SoftDeletingScope::class,
]);
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Filament\Resources\MfmReadingResource\Pages;
use App\Filament\Resources\MfmReadingResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
class CreateMfmReading extends CreateRecord
{
protected static string $resource = MfmReadingResource::class;
}

View File

@@ -0,0 +1,22 @@
<?php
namespace App\Filament\Resources\MfmReadingResource\Pages;
use App\Filament\Resources\MfmReadingResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
class EditMfmReading extends EditRecord
{
protected static string $resource = MfmReadingResource::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\MfmReadingResource\Pages;
use App\Filament\Resources\MfmReadingResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class ListMfmReadings extends ListRecords
{
protected static string $resource = MfmReadingResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

View File

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

51
app/Models/MfmReading.php Normal file
View File

@@ -0,0 +1,51 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class MfmReading extends Model
{
use SoftDeletes;
protected $fillable = [
'plant_id',
'mfm_meter_id',
'apparent_energy_received',
'reactive_energy_received',
'active_energy_received',
'active_power_r',
'active_power_y',
'active_power_b',
'active_power_total',
'voltage_ry',
'voltage_yb',
'voltage_br',
'current_r',
'current_y',
'current_b',
'current_n',
'voltage_r_n',
'voltage_y_n',
'voltage_b_n',
'frequency',
'power_factor_r',
'power_factor_y',
'power_factor_b',
'power_factor_total',
'created_at',
'updated_at',
];
public function plant(): BelongsTo
{
return $this->belongsTo(Plant::class);
}
public function mfmMeter(): BelongsTo
{
return $this->belongsTo(MfmMeter::class, 'mfm_meter_id');
}
}

View File

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

View File

@@ -0,0 +1,65 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
$sql = <<<'SQL'
CREATE TABLE mfm_readings (
id BIGINT GENERATED always AS IDENTITY PRIMARY KEY,
plant_id BIGINT NOT NULL,
mfm_meter_id BIGINT NOT NULL,
apparent_energy_received TEXT DEFAULT NULL,
reactive_energy_received TEXT DEFAULT NULL,
active_energy_received TEXT DEFAULT NULL,
active_power_r TEXT DEFAULT NULL,
active_power_y TEXT DEFAULT NULL,
active_power_b TEXT DEFAULT NULL,
active_power_total TEXT DEFAULT NULL,
voltage_ry TEXT DEFAULT NULL,
voltage_yb TEXT DEFAULT NULL,
voltage_br TEXT DEFAULT NULL,
current_r TEXT DEFAULT NULL,
current_y TEXT DEFAULT NULL,
current_b TEXT DEFAULT NULL,
current_n TEXT DEFAULT NULL,
voltage_r_n TEXT DEFAULT NULL,
voltage_y_n TEXT DEFAULT NULL,
voltage_b_n TEXT DEFAULT NULL,
frequency TEXT DEFAULT NULL,
power_factor_r TEXT DEFAULT NULL,
power_factor_y TEXT DEFAULT NULL,
power_factor_b TEXT DEFAULT NULL,
power_factor_total TEXT DEFAULT NULL,
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
deleted_at TIMESTAMP,
UNIQUE (plant_id, created_at, mfm_meter_id),
FOREIGN KEY (plant_id) REFERENCES plants (id),
FOREIGN KEY (mfm_meter_id) REFERENCES mfm_meters (id)
);
SQL;
DB::statement($sql);
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('mfm_readings');
}
};