Merge pull request 'ranjith-dev' (#928) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 31s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 31s
Reviewed-on: #928
This commit was merged in pull request #928.
This commit is contained in:
85
app/Filament/Exports/PumpTestingEntryExporter.php
Normal file
85
app/Filament/Exports/PumpTestingEntryExporter.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Exports;
|
||||
|
||||
use App\Models\PumpTestingEntry;
|
||||
use Filament\Actions\Exports\ExportColumn;
|
||||
use Filament\Actions\Exports\Exporter;
|
||||
use Filament\Actions\Exports\Models\Export;
|
||||
|
||||
class PumpTestingEntryExporter extends Exporter
|
||||
{
|
||||
protected static ?string $model = PumpTestingEntry::class;
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
static $rowNumber = 0;
|
||||
|
||||
return [
|
||||
ExportColumn::make('no')
|
||||
->label('NO')
|
||||
->state(function ($record) use (&$rowNumber) {
|
||||
// Increment and return the row number
|
||||
return ++$rowNumber;
|
||||
}),
|
||||
ExportColumn::make('plant.code')
|
||||
->label('PLANT CODE'),
|
||||
ExportColumn::make('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;
|
||||
}
|
||||
}
|
||||
113
app/Filament/Exports/PumpTestingMasterExporter.php
Normal file
113
app/Filament/Exports/PumpTestingMasterExporter.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Exports;
|
||||
|
||||
use App\Models\PumpTestingMaster;
|
||||
use Filament\Actions\Exports\ExportColumn;
|
||||
use Filament\Actions\Exports\Exporter;
|
||||
use Filament\Actions\Exports\Models\Export;
|
||||
|
||||
class PumpTestingMasterExporter extends Exporter
|
||||
{
|
||||
protected static ?string $model = PumpTestingMaster::class;
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
static $rowNumber = 0;
|
||||
|
||||
return [
|
||||
ExportColumn::make('no')
|
||||
->label('NO')
|
||||
->state(function ($record) use (&$rowNumber) {
|
||||
// Increment and return the row number
|
||||
return ++$rowNumber;
|
||||
}),
|
||||
ExportColumn::make('plant.code')
|
||||
->label('PLANT CODE'),
|
||||
ExportColumn::make('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;
|
||||
}
|
||||
}
|
||||
758
app/Filament/Resources/PumpTestingEntryResource.php
Normal file
758
app/Filament/Resources/PumpTestingEntryResource.php
Normal file
@@ -0,0 +1,758 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Exports\PumpTestingEntryExporter;
|
||||
use App\Filament\Resources\PumpTestingEntryResource\Pages;
|
||||
use App\Models\Configuration;
|
||||
use App\Models\Item;
|
||||
use App\Models\Plant;
|
||||
use App\Models\PumpTestingEntry;
|
||||
use App\Models\PumpTestingMaster;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Forms\Set;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class PumpTestingEntryResource extends Resource
|
||||
{
|
||||
protected static ?string $model = PumpTestingEntry::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Pump Testing Panel';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Section::make('')
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->label('Plant Name')
|
||||
->relationship('plant', 'name')
|
||||
->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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PumpTestingEntryResource\Pages;
|
||||
|
||||
use App\Filament\Resources\PumpTestingEntryResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreatePumpTestingEntry extends CreateRecord
|
||||
{
|
||||
protected static string $resource = PumpTestingEntryResource::class;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PumpTestingEntryResource\Pages;
|
||||
|
||||
use App\Filament\Resources\PumpTestingEntryResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditPumpTestingEntry extends EditRecord
|
||||
{
|
||||
protected static string $resource = PumpTestingEntryResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\ViewAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
Actions\ForceDeleteAction::make(),
|
||||
Actions\RestoreAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PumpTestingEntryResource\Pages;
|
||||
|
||||
use App\Filament\Resources\PumpTestingEntryResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListPumpTestingEntries extends ListRecords
|
||||
{
|
||||
protected static string $resource = PumpTestingEntryResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PumpTestingEntryResource\Pages;
|
||||
|
||||
use App\Filament\Resources\PumpTestingEntryResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewPumpTestingEntry extends ViewRecord
|
||||
{
|
||||
protected static string $resource = PumpTestingEntryResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\EditAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
991
app/Filament/Resources/PumpTestingMasterResource.php
Normal file
991
app/Filament/Resources/PumpTestingMasterResource.php
Normal file
@@ -0,0 +1,991 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Exports\PumpTestingMasterExporter;
|
||||
use App\Filament\Resources\PumpTestingMasterResource\Pages;
|
||||
use App\Models\Configuration;
|
||||
use App\Models\Item;
|
||||
use App\Models\Plant;
|
||||
use App\Models\PumpTestingMaster;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class PumpTestingMasterResource extends Resource
|
||||
{
|
||||
protected static ?string $model = PumpTestingMaster::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Pump Testing Panel';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Section::make('')
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->label('Plant Name')
|
||||
->relationship('plant', 'name')
|
||||
->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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PumpTestingMasterResource\Pages;
|
||||
|
||||
use App\Filament\Resources\PumpTestingMasterResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreatePumpTestingMaster extends CreateRecord
|
||||
{
|
||||
protected static string $resource = PumpTestingMasterResource::class;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PumpTestingMasterResource\Pages;
|
||||
|
||||
use App\Filament\Resources\PumpTestingMasterResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditPumpTestingMaster extends EditRecord
|
||||
{
|
||||
protected static string $resource = PumpTestingMasterResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\ViewAction::make(),
|
||||
Actions\DeleteAction::make(),
|
||||
Actions\ForceDeleteAction::make(),
|
||||
Actions\RestoreAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PumpTestingMasterResource\Pages;
|
||||
|
||||
use App\Filament\Resources\PumpTestingMasterResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListPumpTestingMasters extends ListRecords
|
||||
{
|
||||
protected static string $resource = PumpTestingMasterResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\PumpTestingMasterResource\Pages;
|
||||
|
||||
use App\Filament\Resources\PumpTestingMasterResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewPumpTestingMaster extends ViewRecord
|
||||
{
|
||||
protected static string $resource = PumpTestingMasterResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\EditAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -84,15 +84,15 @@ 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()
|
||||
// {
|
||||
// return $this->hasMany(PumpTestingEntry::class, 'plant_id', 'id');
|
||||
// }
|
||||
public function pumpTestingEntries()
|
||||
{
|
||||
return $this->hasMany(PumpTestingEntry::class, 'plant_id', 'id');
|
||||
}
|
||||
|
||||
public function guardNames()
|
||||
{
|
||||
|
||||
43
app/Models/PumpTestingEntry.php
Normal file
43
app/Models/PumpTestingEntry.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class PumpTestingEntry extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'plant_id',
|
||||
'pump_testing_master_id',
|
||||
'tested_date',
|
||||
'tested_type',
|
||||
'pump_serial_number',
|
||||
'correction_head',
|
||||
'sl_no',
|
||||
'voltage',
|
||||
'frequency',
|
||||
'speed',
|
||||
'head',
|
||||
'flow_reading',
|
||||
'current',
|
||||
'watt',
|
||||
'created_at',
|
||||
'created_by',
|
||||
'updated_at',
|
||||
'updated_by',
|
||||
];
|
||||
|
||||
public function plant(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Plant::class);
|
||||
}
|
||||
|
||||
public function pumpTestingMasters(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PumpTestingMaster::class, 'pump_testing_master_id', 'id');
|
||||
}
|
||||
}
|
||||
62
app/Models/PumpTestingMaster.php
Normal file
62
app/Models/PumpTestingMaster.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class PumpTestingMaster extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
'plant_id',
|
||||
'item_id',
|
||||
'head',
|
||||
'head_type',
|
||||
'discharge',
|
||||
'discharge_type',
|
||||
'motor_efficiency',
|
||||
'pump_efficiency',
|
||||
'speed',
|
||||
'frequency',
|
||||
'i_max',
|
||||
'p_input',
|
||||
'delivery_size',
|
||||
'no_of_stages',
|
||||
'size',
|
||||
'maximum_head',
|
||||
'motor_type',
|
||||
'motor_code',
|
||||
'kw_hp',
|
||||
'connection_type',
|
||||
'voltage',
|
||||
'phase',
|
||||
'oh_minimum',
|
||||
'oh_maximum',
|
||||
'current_minimum',
|
||||
'current_maximum',
|
||||
'class_of_insulation',
|
||||
'testing_code',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
];
|
||||
|
||||
public function plant(): BelongsTo
|
||||
{
|
||||
return $this->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');
|
||||
}
|
||||
}
|
||||
105
app/Policies/PumpTestingEntryPolicy.php
Normal file
105
app/Policies/PumpTestingEntryPolicy.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\PumpTestingEntry;
|
||||
use App\Models\User;
|
||||
|
||||
class PumpTestingEntryPolicy
|
||||
{
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return $user->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');
|
||||
}
|
||||
}
|
||||
105
app/Policies/PumpTestingMasterPolicy.php
Normal file
105
app/Policies/PumpTestingMasterPolicy.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\PumpTestingMaster;
|
||||
use App\Models\User;
|
||||
|
||||
class PumpTestingMasterPolicy
|
||||
{
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return $user->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');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$sql = <<<'SQL'
|
||||
CREATE TABLE pump_testing_masters (
|
||||
id BIGINT GENERATED always AS IDENTITY PRIMARY KEY,
|
||||
|
||||
plant_id BIGINT NOT NULL,
|
||||
item_id BIGINT NOT NULL,
|
||||
|
||||
head TEXT DEFAULT NULL,
|
||||
head_type TEXT DEFAULT NULL,
|
||||
discharge TEXT DEFAULT NULL,
|
||||
discharge_type TEXT DEFAULT NULL,
|
||||
motor_efficiency TEXT DEFAULT NULL,
|
||||
pump_efficiency TEXT DEFAULT NULL,
|
||||
speed TEXT DEFAULT NULL,
|
||||
frequency TEXT DEFAULT NULL,
|
||||
i_max TEXT DEFAULT NULL,
|
||||
p_input TEXT DEFAULT NULL,
|
||||
delivery_size TEXT DEFAULT NULL,
|
||||
no_of_stages TEXT DEFAULT NULL,
|
||||
size TEXT DEFAULT NULL,
|
||||
maximum_head TEXT DEFAULT NULL,
|
||||
motor_type TEXT DEFAULT NULL,
|
||||
motor_code TEXT DEFAULT NULL,
|
||||
kw_hp TEXT DEFAULT NULL,
|
||||
connection_type TEXT DEFAULT NULL,
|
||||
voltage TEXT DEFAULT NULL,
|
||||
phase TEXT DEFAULT NULL,
|
||||
oh_minimum TEXT DEFAULT NULL,
|
||||
oh_maximum TEXT DEFAULT NULL,
|
||||
current_minimum TEXT DEFAULT NULL,
|
||||
current_maximum TEXT DEFAULT NULL,
|
||||
class_of_insulation TEXT DEFAULT NULL,
|
||||
testing_code TEXT DEFAULT NULL,
|
||||
|
||||
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
deleted_at TIMESTAMP,
|
||||
|
||||
created_by TEXT NOT NULL,
|
||||
updated_by TEXT NOT NULL,
|
||||
|
||||
UNIQUE (plant_id, item_id),
|
||||
|
||||
FOREIGN KEY (item_id) REFERENCES items (id),
|
||||
FOREIGN KEY (plant_id) REFERENCES plants (id)
|
||||
);
|
||||
SQL;
|
||||
|
||||
DB::statement($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('pump_testing_masters');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$sql = <<<'SQL'
|
||||
CREATE TABLE pump_testing_entries (
|
||||
id BIGINT GENERATED always AS IDENTITY PRIMARY KEY,
|
||||
|
||||
plant_id BIGINT NOT NULL,
|
||||
pump_testing_master_id BIGINT NOT NULL,
|
||||
|
||||
tested_date DATE NOT NULL DEFAULT CURRENT_DATE,
|
||||
tested_type TEXT DEFAULT NULL,
|
||||
pump_serial_number TEXT DEFAULT NULL,
|
||||
correction_head TEXT DEFAULT NULL,
|
||||
sl_no TEXT DEFAULT NULL,
|
||||
voltage TEXT DEFAULT NULL,
|
||||
frequency TEXT DEFAULT NULL,
|
||||
speed TEXT DEFAULT NULL,
|
||||
head TEXT DEFAULT NULL,
|
||||
flow_reading TEXT DEFAULT NULL,
|
||||
current TEXT DEFAULT NULL,
|
||||
watt TEXT DEFAULT NULL,
|
||||
|
||||
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||
deleted_at TIMESTAMP,
|
||||
|
||||
created_by TEXT NOT NULL,
|
||||
updated_by TEXT NOT NULL,
|
||||
|
||||
UNIQUE (plant_id, pump_testing_master_id, tested_type, pump_serial_number, sl_no),
|
||||
|
||||
FOREIGN KEY (pump_testing_master_id) REFERENCES pump_testing_masters (id),
|
||||
FOREIGN KEY (plant_id) REFERENCES plants (id)
|
||||
);
|
||||
SQL;
|
||||
|
||||
DB::statement($sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('pump_testing_entries');
|
||||
}
|
||||
};
|
||||
@@ -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']);
|
||||
|
||||
Reference in New Issue
Block a user