Compare commits
13 Commits
4fa053e6e5
...
7d91e8976c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d91e8976c | ||
|
|
c83be6936b | ||
|
|
5a850a11a9 | ||
|
|
35501f2bec | ||
|
|
be47d48931 | ||
|
|
5f79050b3f | ||
|
|
0fa0a9c128 | ||
|
|
bb019e0b13 | ||
|
|
abc50de038 | ||
|
|
044d27336d | ||
|
|
376d0800dd | ||
|
|
e8bac66e51 | ||
|
|
dc32cf623c |
54
app/Filament/Exports/ConfigurationExporter.php
Normal file
54
app/Filament/Exports/ConfigurationExporter.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Exports;
|
||||
|
||||
use App\Models\Configuration;
|
||||
use Filament\Actions\Exports\ExportColumn;
|
||||
use Filament\Actions\Exports\Exporter;
|
||||
use Filament\Actions\Exports\Models\Export;
|
||||
|
||||
class ConfigurationExporter extends Exporter
|
||||
{
|
||||
protected static ?string $model = Configuration::class;
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
ExportColumn::make('no')
|
||||
->label('No')
|
||||
->state(function ($record) use (&$rowNumber) {
|
||||
// Increment and return the row number
|
||||
return ++$rowNumber;
|
||||
}),
|
||||
ExportColumn::make('plant.name')
|
||||
->label('Plant'),
|
||||
ExportColumn::make('line.name')
|
||||
->label('Line'),
|
||||
ExportColumn::make('c_type')
|
||||
->label('Type'),
|
||||
ExportColumn::make('c_group')
|
||||
->label('Group'),
|
||||
ExportColumn::make('c_name')
|
||||
->label('Name'),
|
||||
ExportColumn::make('c_value')
|
||||
->label('Value'),
|
||||
ExportColumn::make('created_at')
|
||||
->label('Created At'),
|
||||
ExportColumn::make('updated_at')
|
||||
->label('Updated At'),
|
||||
ExportColumn::make('deleted_at')
|
||||
->label('Deleted At'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Export $export): string
|
||||
{
|
||||
$body = 'Your configuration 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;
|
||||
}
|
||||
}
|
||||
48
app/Filament/Exports/MachineExporter.php
Normal file
48
app/Filament/Exports/MachineExporter.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Exports;
|
||||
|
||||
use App\Models\Machine;
|
||||
use Filament\Actions\Exports\ExportColumn;
|
||||
use Filament\Actions\Exports\Exporter;
|
||||
use Filament\Actions\Exports\Models\Export;
|
||||
|
||||
class MachineExporter extends Exporter
|
||||
{
|
||||
protected static ?string $model = Machine::class;
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
ExportColumn::make('no')
|
||||
->label('No')
|
||||
->state(function ($record) use (&$rowNumber) {
|
||||
// Increment and return the row number
|
||||
return ++$rowNumber;
|
||||
}),
|
||||
ExportColumn::make('plant.name')
|
||||
->label('Plant'),
|
||||
ExportColumn::make('line.name')
|
||||
->label('Line'),
|
||||
ExportColumn::make('name')
|
||||
->label('Name'),
|
||||
ExportColumn::make('created_at')
|
||||
->label('Created At'),
|
||||
ExportColumn::make('updated_at')
|
||||
->label('Updated At'),
|
||||
ExportColumn::make('deleted_at')
|
||||
->label('Deleted At'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Export $export): string
|
||||
{
|
||||
$body = 'Your machine 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;
|
||||
}
|
||||
}
|
||||
@@ -14,43 +14,82 @@ class MotorTestingMasterExporter extends Exporter
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
ExportColumn::make('id')
|
||||
->label('ID'),
|
||||
ExportColumn::make('plant.name'),
|
||||
ExportColumn::make('item.id'),
|
||||
ExportColumn::make('isi_model'),
|
||||
ExportColumn::make('phase'),
|
||||
ExportColumn::make('hp'),
|
||||
ExportColumn::make('kw'),
|
||||
ExportColumn::make('volt'),
|
||||
ExportColumn::make('current'),
|
||||
ExportColumn::make('rpm'),
|
||||
ExportColumn::make('torque'),
|
||||
ExportColumn::make('frequency'),
|
||||
ExportColumn::make('connection'),
|
||||
ExportColumn::make('ins_res_limit'),
|
||||
ExportColumn::make('ins_res_type'),
|
||||
ExportColumn::make('res_ry_ll'),
|
||||
ExportColumn::make('res_ry_ul'),
|
||||
ExportColumn::make('res_yb_ll'),
|
||||
ExportColumn::make('res_yb_ul'),
|
||||
ExportColumn::make('res_br_ll'),
|
||||
ExportColumn::make('res_br_ul'),
|
||||
ExportColumn::make('lock_volt_limit'),
|
||||
ExportColumn::make('leak_cur_limit'),
|
||||
ExportColumn::make('lock_cur_ll'),
|
||||
ExportColumn::make('lock_cur_ul'),
|
||||
ExportColumn::make('noload_cur_ll'),
|
||||
ExportColumn::make('noload_cur_ul'),
|
||||
ExportColumn::make('noload_pow_ll'),
|
||||
ExportColumn::make('noload_pow_ul'),
|
||||
ExportColumn::make('noload_spd_ll'),
|
||||
ExportColumn::make('noload_spd_ul'),
|
||||
ExportColumn::make('created_at'),
|
||||
ExportColumn::make('updated_at'),
|
||||
ExportColumn::make('deleted_at'),
|
||||
ExportColumn::make('created_by'),
|
||||
ExportColumn::make('updated_by'),
|
||||
ExportColumn::make('no')
|
||||
->label('No')
|
||||
->state(function ($record) use (&$rowNumber) {
|
||||
// Increment and return the row number
|
||||
return ++$rowNumber;
|
||||
}),
|
||||
ExportColumn::make('plant.name')
|
||||
->label('Plant'),
|
||||
ExportColumn::make('item.code')
|
||||
->label('Item Code'),
|
||||
ExportColumn::make('isi_model')
|
||||
->label('ISI Model'),
|
||||
ExportColumn::make('phase')
|
||||
->label('Phase'),
|
||||
ExportColumn::make('hp')
|
||||
->label('HP'),
|
||||
ExportColumn::make('kw')
|
||||
->label('KW'),
|
||||
ExportColumn::make('volt')
|
||||
->label('Volt'),
|
||||
ExportColumn::make('current')
|
||||
->label('Current'),
|
||||
ExportColumn::make('rpm')
|
||||
->label('RPM'),
|
||||
ExportColumn::make('torque')
|
||||
->label('Torque'),
|
||||
ExportColumn::make('frequency')
|
||||
->label('Frequency'),
|
||||
ExportColumn::make('connection')
|
||||
->label('Connection'),
|
||||
ExportColumn::make('ins_res_limit')
|
||||
->label('Insulation Resistance Limit'),
|
||||
ExportColumn::make('ins_res_type')
|
||||
->label('Insulation Resistance Type'),
|
||||
ExportColumn::make('res_ry_ll')
|
||||
->label('Resistance RY LL'),
|
||||
ExportColumn::make('res_ry_ul')
|
||||
->label('Resistance RY UL'),
|
||||
ExportColumn::make('res_yb_ll')
|
||||
->label('Resistance YB LL'),
|
||||
ExportColumn::make('res_yb_ul')
|
||||
->label('Resistance YB UL'),
|
||||
ExportColumn::make('res_br_ll')
|
||||
->label('Resistance BR LL'),
|
||||
ExportColumn::make('res_br_ul')
|
||||
->label('Resistance BR UL'),
|
||||
ExportColumn::make('lock_volt_limit')
|
||||
->label('Lock Volt Limit'),
|
||||
ExportColumn::make('leak_cur_limit')
|
||||
->label('Leak Current Limit'),
|
||||
ExportColumn::make('lock_cur_ll')
|
||||
->label('Lock Current LL'),
|
||||
ExportColumn::make('lock_cur_ul')
|
||||
->label('Lock Current UL'),
|
||||
ExportColumn::make('noload_cur_ll')
|
||||
->label('No Load Current LL'),
|
||||
ExportColumn::make('noload_cur_ul')
|
||||
->label('No Load Current UL'),
|
||||
ExportColumn::make('noload_pow_ll')
|
||||
->label('No Load Power LL'),
|
||||
ExportColumn::make('noload_pow_ul')
|
||||
->label('No Load Power UL'),
|
||||
ExportColumn::make('noload_spd_ll')
|
||||
->label('No Load Speed LL'),
|
||||
ExportColumn::make('noload_spd_ul')
|
||||
->label('No Load Speed UL'),
|
||||
ExportColumn::make('created_at')
|
||||
->label('Created At'),
|
||||
ExportColumn::make('updated_at')
|
||||
->label('Updated At'),
|
||||
ExportColumn::make('deleted_at')
|
||||
->label('Deleted At'),
|
||||
ExportColumn::make('created_by')
|
||||
->label('Created By'),
|
||||
ExportColumn::make('updated_by')
|
||||
->label('Updated By'),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
78
app/Filament/Imports/ConfigurationImporter.php
Normal file
78
app/Filament/Imports/ConfigurationImporter.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\Configuration;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
|
||||
class ConfigurationImporter extends Importer
|
||||
{
|
||||
protected static ?string $model = Configuration::class;
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->relationship(resolveUsing: 'name')
|
||||
->exampleHeader('Plant')
|
||||
->example(['Ransar Industries-I'])
|
||||
->label('Plant')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('line')
|
||||
->requiredMapping()
|
||||
->relationship(resolveUsing: 'name')
|
||||
->exampleHeader('Plant')
|
||||
->example(['4 inch pump line'])
|
||||
->label('Line')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('c_type')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Type')
|
||||
->example(['Testing Panel Readings'])
|
||||
->label('Type')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('c_group')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Group')
|
||||
->example(['LMC_WINDED'])
|
||||
->label('Group')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('c_name')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Name')
|
||||
->example(['MOTOR_PHASE'])
|
||||
->label('Name')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('c_value')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Value')
|
||||
->example(['Single'])
|
||||
->label('Value')
|
||||
->rules(['required']),
|
||||
];
|
||||
}
|
||||
|
||||
public function resolveRecord(): ?Configuration
|
||||
{
|
||||
// return Configuration::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
|
||||
return new Configuration();
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
{
|
||||
$body = 'Your configuration import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
|
||||
|
||||
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
||||
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
}
|
||||
60
app/Filament/Imports/MachineImporter.php
Normal file
60
app/Filament/Imports/MachineImporter.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\Machine;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
|
||||
class MachineImporter extends Importer
|
||||
{
|
||||
protected static ?string $model = Machine::class;
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->relationship(resolveUsing: 'name')
|
||||
->exampleHeader('Plant')
|
||||
->example(['Ransar Industries-I'])
|
||||
->label('Plant')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('line')
|
||||
->requiredMapping()
|
||||
->relationship(resolveUsing: 'name')
|
||||
->exampleHeader('Line')
|
||||
->example(['4 inch pump line'])
|
||||
->label('Line')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('name')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Name')
|
||||
->example(['1600251'])
|
||||
->label('Line')
|
||||
->rules(['required']),
|
||||
];
|
||||
}
|
||||
|
||||
public function resolveRecord(): ?Machine
|
||||
{
|
||||
// return Machine::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
|
||||
return new Machine();
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
{
|
||||
$body = 'Your machine import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
|
||||
|
||||
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
||||
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
|
||||
}
|
||||
|
||||
return $body;
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,23 @@
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Exports\ConfigurationExporter;
|
||||
use App\Filament\Imports\ConfigurationImporter;
|
||||
use App\Filament\Resources\ConfigurationResource\Pages;
|
||||
use App\Filament\Resources\ConfigurationResource\RelationManagers;
|
||||
use App\Models\Configuration;
|
||||
use App\Models\Line;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
|
||||
class ConfigurationResource extends Resource
|
||||
{
|
||||
@@ -26,20 +33,64 @@ class ConfigurationResource extends Resource
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->label('Plant')
|
||||
->relationship('plant', 'name')
|
||||
->required()
|
||||
->reactive(),
|
||||
->reactive()
|
||||
->default(function () {
|
||||
return optional(Configuration::latest()->first())->plant_id;
|
||||
})
|
||||
->disabled(fn (Get $get) => !empty($get('id')))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (!$plantId) {
|
||||
$set('cPlantError', 'Please select a plant first.');
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$set('cPlantError', null);
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('cPlantError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('cPlantError') ? $get('cPlantError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\Select::make('line_id')
|
||||
->label('Line')
|
||||
->required()
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (!$plantId) {
|
||||
return [];
|
||||
}
|
||||
return \App\Models\Line::where('plant_id', $plantId)->pluck('name', 'id')->toArray();
|
||||
})
|
||||
->reactive(),
|
||||
->label('Line')
|
||||
->relationship('line', 'name')
|
||||
->required()
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
if (!$get('plant_id')) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Line::where('plant_id', $get('plant_id'))
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
})
|
||||
->default(function () {
|
||||
return optional(Configuration::latest()->first())->line_id;
|
||||
})
|
||||
->disabled(fn (Get $get) => !empty($get('id')))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$lineId = $get('line_id');
|
||||
if (!$lineId) {
|
||||
$set('cLineError', 'Please select a line first.');
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$set('cLineError', null);
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('cLineError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('cLineError') ? $get('cLineError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\TextInput::make('c_type')
|
||||
->label('Type')
|
||||
->required(),
|
||||
@@ -52,6 +103,9 @@ class ConfigurationResource extends Resource
|
||||
Forms\Components\TextInput::make('c_value')
|
||||
->label('Value')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('id')
|
||||
->hidden()
|
||||
->readOnly(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -70,39 +124,37 @@ class ConfigurationResource extends Resource
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->alignCenter()
|
||||
->label('Plant')
|
||||
->sortable(),
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('line.name')
|
||||
->label('Line')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('c_type')
|
||||
->label('Type')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('c_group')
|
||||
->label('Group')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('c_name')
|
||||
->label('Name')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('c_value')
|
||||
->label('Value')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
->searchable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->dateTime()
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->dateTime()
|
||||
->label('Updated At')
|
||||
->alignCenter()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('deleted_at')
|
||||
->dateTime()
|
||||
->label('Deleted At')
|
||||
@@ -123,6 +175,18 @@ class ConfigurationResource extends Resource
|
||||
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||
Tables\Actions\RestoreBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->headerActions([
|
||||
ImportAction::make()
|
||||
->importer(ConfigurationImporter::class)
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view import configuration');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->exporter(ConfigurationExporter::class)
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view export configuration');
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,16 +2,23 @@
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Exports\MachineExporter;
|
||||
use App\Filament\Imports\MachineImporter;
|
||||
use App\Filament\Resources\MachineResource\Pages;
|
||||
use App\Filament\Resources\MachineResource\RelationManagers;
|
||||
use App\Models\Line;
|
||||
use App\Models\Machine;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
|
||||
class MachineResource extends Resource
|
||||
{
|
||||
@@ -31,21 +38,67 @@ class MachineResource extends Resource
|
||||
->label('Plant')
|
||||
->relationship('plant', 'name')
|
||||
->required()
|
||||
->reactive(),
|
||||
Forms\Components\Select::make('line_id')
|
||||
->label('Line')
|
||||
->required()
|
||||
->options(function (callable $get) {
|
||||
->reactive()
|
||||
->default(function () {
|
||||
return optional(Machine::latest()->first())->plant_id;
|
||||
})
|
||||
->disabled(fn (Get $get) => !empty($get('id')))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (!$plantId) {
|
||||
$set('mPlantError', 'Please select a plant first.');
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$set('mPlantError', null);
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('mPlantError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('mPlantError') ? $get('mPlantError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\Select::make('line_id')
|
||||
->label('Line')
|
||||
->relationship('line', 'name')
|
||||
->required()
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
if (!$get('plant_id')) {
|
||||
return [];
|
||||
}
|
||||
return \App\Models\Line::where('plant_id', $plantId)->pluck('name', 'id')->toArray();
|
||||
|
||||
return Line::where('plant_id', $get('plant_id'))
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
})
|
||||
->reactive(),
|
||||
->default(function () {
|
||||
return optional(Machine::latest()->first())->line_id;
|
||||
})
|
||||
->disabled(fn (Get $get) => !empty($get('id')))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$lineId = $get('line_id');
|
||||
if (!$lineId) {
|
||||
$set('mLineError', 'Please select a line first.');
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$set('mLineError', null);
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('mLineError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('mLineError') ? $get('mLineError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\TextInput::make('name')
|
||||
->label('Name')
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('id')
|
||||
->hidden()
|
||||
->readOnly(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -63,28 +116,26 @@ class MachineResource extends Resource
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->label('Plant')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
->searchable()
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('line.name')
|
||||
->label('Line')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
->searchable()
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label('Name')
|
||||
->alignCenter()
|
||||
->sortable(),
|
||||
->searchable()
|
||||
->alignCenter(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->alignCenter()
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->label('Updated At')
|
||||
->alignCenter()
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('deleted_at')
|
||||
->label('Deleted At')
|
||||
->alignCenter()
|
||||
@@ -105,6 +156,18 @@ class MachineResource extends Resource
|
||||
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||
Tables\Actions\RestoreBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->headerActions([
|
||||
ImportAction::make()
|
||||
->importer(MachineImporter::class)
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view import machine');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->exporter(MachineExporter::class)
|
||||
->visible(function() {
|
||||
return Filament::auth()->user()->can('view export machine');
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,31 +36,32 @@ class MotorTestingMasterResource extends Resource
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->label('Plant')
|
||||
->relationship('plant', 'name')
|
||||
->required()
|
||||
->reactive()
|
||||
->default(function () {
|
||||
return optional(Item::latest()->first())->plant_id;
|
||||
})
|
||||
->disabled(fn (Get $get) => !empty($get('id')))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (!$plantId) {
|
||||
$set('mTmError', 'Please select a plant first.');
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$set('mTmError', null);
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('mTmError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('mTmError') ? $get('mTmError') : null)
|
||||
->hintColor('danger'),
|
||||
->required()
|
||||
->reactive()
|
||||
->default(function () {
|
||||
return optional(MotorTestingMaster::latest()->first())->plant_id;
|
||||
})
|
||||
->disabled(fn (Get $get) => !empty($get('id')))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (!$plantId) {
|
||||
$set('mTmError', 'Please select a plant first.');
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$set('mTmError', null);
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('mTmError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('mTmError') ? $get('mTmError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\Select::make('item_id')
|
||||
->label('Item')
|
||||
->label('Item Code')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (!$plantId) {
|
||||
@@ -108,6 +109,12 @@ class MotorTestingMasterResource extends Resource
|
||||
}
|
||||
})
|
||||
->selectablePlaceholder(false)
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
|
||||
if ($state == 'Single' && $get('connection') == 'Star-Delta') {
|
||||
$set('phase', 'Three');
|
||||
}
|
||||
})
|
||||
->default('Single')
|
||||
->required()
|
||||
->reactive(),
|
||||
@@ -151,6 +158,11 @@ class MotorTestingMasterResource extends Resource
|
||||
->toArray();
|
||||
}
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set) {
|
||||
if ($state == 'Star-Delta') {
|
||||
$set('phase', 'Three');
|
||||
}
|
||||
})
|
||||
->required()
|
||||
->default('Star')
|
||||
->reactive(),
|
||||
@@ -215,6 +227,9 @@ class MotorTestingMasterResource extends Resource
|
||||
Forms\Components\Hidden::make('updated_by')
|
||||
->default(fn () => Filament::auth()->user()?->name)
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('id')
|
||||
->hidden()
|
||||
->readOnly(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ use App\Models\Configuration;
|
||||
use App\Models\Item;
|
||||
use App\Models\Line;
|
||||
use App\Models\Machine;
|
||||
use App\Models\MotorTestingMaster;
|
||||
use App\Models\Plant;
|
||||
use App\Models\QualityValidation;
|
||||
use App\Models\StickerMaster;
|
||||
@@ -22,6 +23,7 @@ use Filament\Forms\Components\DateTimePicker;
|
||||
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\BulkAction;
|
||||
@@ -46,17 +48,40 @@ class TestingPanelReadingResource extends Resource
|
||||
return $form
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->label('Plant')
|
||||
->relationship('plant', 'name')
|
||||
->required()
|
||||
->reactive()
|
||||
// When plant changes, reset the dependent fields
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('line_id', null);
|
||||
$set('item_id', null);
|
||||
$set('machine_id', null);
|
||||
}),
|
||||
->default(function () {
|
||||
return optional(TestingPanelReading::latest()->first())->plant_id;
|
||||
})
|
||||
->disabled(fn (Get $get) => !empty($get('id')))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (!$plantId) {
|
||||
$set('line_id', null);
|
||||
$set('item_id', null);
|
||||
$set('machine_id', null);
|
||||
$set('tPrError', 'Please select a plant first.');
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$set('line_id', null);
|
||||
$set('item_id', null);
|
||||
$set('machine_id', null);
|
||||
$set('tPrError', null);
|
||||
}
|
||||
})
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('tPrError') ? 'border-red-500' : '',
|
||||
])
|
||||
->hint(fn ($get) => $get('tPrError') ? $get('tPrError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\Select::make('line_id')
|
||||
->label('Line')
|
||||
->relationship('line', 'name')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (!$plantId) {
|
||||
@@ -66,26 +91,16 @@ class TestingPanelReadingResource extends Resource
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
})
|
||||
->default(function () {
|
||||
return optional(TestingPanelReading::latest()->first())->line_id;
|
||||
})
|
||||
->disabled(fn (Get $get) => !empty($get('id')))
|
||||
->required()
|
||||
->reactive()
|
||||
->afterStateUpdated(fn (callable $set) => $set('item_id', null)),
|
||||
Forms\Components\Select::make('item_id')
|
||||
->label('Item')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (!$plantId) {
|
||||
return [];
|
||||
}
|
||||
// Adjust this query as per your item-plant relationship
|
||||
return Item::where('plant_id', $plantId)
|
||||
->pluck('code', 'id')
|
||||
->toArray();
|
||||
})
|
||||
->required()
|
||||
->searchable()
|
||||
->reactive(),
|
||||
Forms\Components\Select::make('machine_id')
|
||||
->label('Machine')
|
||||
->relationship('machine', 'name')
|
||||
->options(function (callable $get) {
|
||||
$lineId = $get('line_id');
|
||||
if (!$lineId) {
|
||||
@@ -96,8 +111,33 @@ class TestingPanelReadingResource extends Resource
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
})
|
||||
->default(function () {
|
||||
return optional(TestingPanelReading::latest()->first())->machine_id;
|
||||
})
|
||||
->disabled(fn (Get $get) => !empty($get('id')))
|
||||
->required()
|
||||
->reactive(),
|
||||
Forms\Components\Select::make('motor_testing_master_id')
|
||||
->label('Item Code')
|
||||
->relationship('motorTestingMaster', 'item.code')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (!$plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// return MotorTestingMaster::with('item')
|
||||
// ->whereHas('motorTestingMasters', function ($query) use ($plantId) {
|
||||
// $query->where('plant_id', $plantId);
|
||||
// })->pluck('item.code', 'id')->toArray();
|
||||
// // ->get();
|
||||
|
||||
return Item::where('plant_id', $plantId)->whereHas('motorTestingMasters')->pluck('code', 'id')->toArray();
|
||||
// return Item::whereHas('motorTestingMasters')->pluck('code', 'id')->toArray();
|
||||
})
|
||||
->required()
|
||||
->searchable()
|
||||
->reactive(),
|
||||
Forms\Components\TextInput::make('output')
|
||||
->label('Output')
|
||||
->required(),
|
||||
@@ -190,7 +230,9 @@ class TestingPanelReadingResource extends Resource
|
||||
->label('Tested By'),
|
||||
Forms\Components\TextInput::make('updated_by')
|
||||
->label('Updated By'),
|
||||
|
||||
Forms\Components\TextInput::make('id')
|
||||
->hidden()
|
||||
->readOnly(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -432,13 +474,15 @@ class TestingPanelReadingResource extends Resource
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
|
||||
$query = Item::query();
|
||||
return Item::where('plant_id', $plantId)->whereHas('motorTestingMasters')->pluck('code', 'id')->toArray();
|
||||
|
||||
if ($plantId) {
|
||||
$query->where('plant_id', $plantId);
|
||||
}
|
||||
// $query = Item::query();
|
||||
|
||||
return $query->pluck('code', 'id')->toArray();
|
||||
// if ($plantId) {
|
||||
// $query->where('plant_id', $plantId);
|
||||
// }
|
||||
|
||||
// return $query->pluck('code', 'id')->toArray();
|
||||
})
|
||||
->reactive(),
|
||||
Select::make('machine_name')
|
||||
|
||||
@@ -32,6 +32,12 @@ class Item extends Model
|
||||
{
|
||||
return $this->hasMany(ProductionQuantity::class);
|
||||
}
|
||||
|
||||
public function motorTestingMasters()
|
||||
{
|
||||
return $this->hasMany(MotorTestingMaster::class);
|
||||
}
|
||||
|
||||
public function testingPanelReadings()
|
||||
{
|
||||
return $this->hasMany(TestingPanelReading::class);
|
||||
|
||||
@@ -52,6 +52,12 @@ class MotorTestingMaster extends Model
|
||||
|
||||
public function item(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Item::class);
|
||||
return $this->belongsTo(Item::class, 'item_id', 'id');
|
||||
// return $this->belongsTo(Item::class);
|
||||
}
|
||||
|
||||
public function testingPanelReadings()
|
||||
{
|
||||
return $this->hasMany(TestingPanelReading::class, 'motor_testing_master_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,5 +60,10 @@ class PermissionSeeder extends Seeder
|
||||
Permission::updateOrCreate(['name' => 'view import testing panel reading']);
|
||||
Permission::updateOrCreate(['name' => 'view export testing panel reading']);
|
||||
|
||||
Permission::updateOrCreate(['name' => 'view import machine']);
|
||||
Permission::updateOrCreate(['name' => 'view export machine']);
|
||||
Permission::updateOrCreate(['name' => 'view import configuration']);
|
||||
Permission::updateOrCreate(['name' => 'view export configuration']);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user