Added temp stop characteristics resources, importer, and exporter files
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
This commit is contained in:
77
app/Filament/Exports/TempStopCharacteristicExporter.php
Normal file
77
app/Filament/Exports/TempStopCharacteristicExporter.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Exports;
|
||||
|
||||
use App\Models\TempStopCharacteristic;
|
||||
use Filament\Actions\Exports\ExportColumn;
|
||||
use Filament\Actions\Exports\Exporter;
|
||||
use Filament\Actions\Exports\Models\Export;
|
||||
|
||||
class TempStopCharacteristicExporter extends Exporter
|
||||
{
|
||||
protected static ?string $model = TempStopCharacteristic::class;
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
// ExportColumn::make('id')
|
||||
// ->label('ID'),
|
||||
ExportColumn::make('no')
|
||||
->label('NO')
|
||||
->state(function ($record) use (&$rowNumber) {
|
||||
// Increment and return the row number
|
||||
return ++$rowNumber;
|
||||
}),
|
||||
ExportColumn::make('plant.code')
|
||||
->label('PLANT CODE'),
|
||||
ExportColumn::make('machine.work_center')
|
||||
->label('WORK CENTER'),
|
||||
ExportColumn::make('machine_name')
|
||||
->label('MACHINE NAME'),
|
||||
ExportColumn::make('has_stop_flow_id')
|
||||
->label('HAS STOP FLOW ID'),
|
||||
ExportColumn::make('item.code')
|
||||
->label('ITEM CODE'),
|
||||
ExportColumn::make('aufnr')
|
||||
->label('JOB NUMBER'),
|
||||
ExportColumn::make('gernr')
|
||||
->label('SERIAL NUMBER'),
|
||||
ExportColumn::make('zmm_heading')
|
||||
->label('ZMM HEADING'),
|
||||
ExportColumn::make('model_type')
|
||||
->label('MODEL TYPE'),
|
||||
ExportColumn::make('characteristic_field')
|
||||
->label('MASTER CHARACTERISTIC FIELD'),
|
||||
ExportColumn::make('samlight_logged_name')
|
||||
->label('SAMLIGHT LOGGED NAME'),
|
||||
ExportColumn::make('stopped_at')
|
||||
->label('STOPPED AT'),
|
||||
ExportColumn::make('stopped_by')
|
||||
->label('STOPPED BY'),
|
||||
ExportColumn::make('has_stop_flow_id')
|
||||
->label('HAS STOP FLOW ID'),
|
||||
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 temp stop characteristic 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;
|
||||
}
|
||||
}
|
||||
111
app/Filament/Imports/TempStopCharacteristicImporter.php
Normal file
111
app/Filament/Imports/TempStopCharacteristicImporter.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\TempStopCharacteristic;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
|
||||
class TempStopCharacteristicImporter extends Importer
|
||||
{
|
||||
protected static ?string $model = TempStopCharacteristic::class;
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->label('PLANT CODE')
|
||||
->exampleHeader('PLANT CODE')
|
||||
->example('1000')
|
||||
->relationship(resolveUsing: 'code')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('machine')
|
||||
->requiredMapping()
|
||||
->label('WORK CENTER')
|
||||
->exampleHeader('WORK CENTER')
|
||||
->example('RMGLAS01')
|
||||
->relationship(resolveUsing: 'work_center')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('machine_name')
|
||||
->label('MACHINE NAME')
|
||||
->exampleHeader('MACHINE NAME')
|
||||
->example('RMGLAS01')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('item')
|
||||
->requiredMapping()
|
||||
->exampleHeader('ITEM CODE')
|
||||
->example('630214')
|
||||
->label('ITEM CODE')
|
||||
->relationship(resolveUsing: 'code')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('aufnr')
|
||||
->label('JOB NUMBER')
|
||||
->exampleHeader('JOB NUMBER')
|
||||
->example('1234567'),
|
||||
ImportColumn::make('gernr')
|
||||
->label('SERIAL NUMBER')
|
||||
->exampleHeader('SERIAL NUMBER')
|
||||
->example('1234567890123'),
|
||||
ImportColumn::make('zmm_heading')
|
||||
->exampleHeader('ZMM HEADING')
|
||||
->example('ZMM001')
|
||||
->label('ZMM HEADING'),
|
||||
ImportColumn::make('model_type')
|
||||
->label('MODEL TYPE')
|
||||
->exampleHeader('MODEL TYPE')
|
||||
->example('PUMP'),
|
||||
ImportColumn::make('characteristic_field')
|
||||
->label('MASTER CHARACTERISTIC FIELD')
|
||||
->exampleHeader('MASTER CHARACTERISTIC FIELD')
|
||||
->example('NIL'),
|
||||
ImportColumn::make('samlight_logged_name')
|
||||
->label('SAMLIGHT LOGGED NAME')
|
||||
->exampleHeader('SAMLIGHT LOGGED NAME')
|
||||
->example('User'),
|
||||
ImportColumn::make('stopped_at')
|
||||
->label('STOPPED AT')
|
||||
->exampleHeader('STOPPED AT')
|
||||
->example('01-09-2026 12:00:00')
|
||||
->rules(['datetime']),
|
||||
ImportColumn::make('stopped_by')
|
||||
->label('STOPPED BY')
|
||||
->exampleHeader('STOPPED BY')
|
||||
->example('RAW01234'),
|
||||
ImportColumn::make('has_stop_flow_id')
|
||||
->label('HAS STOP FLOW ID')
|
||||
->exampleHeader('HAS STOP FLOW ID')
|
||||
->example('2'),
|
||||
ImportColumn::make('created_by')
|
||||
->label('CREATED BY')
|
||||
->exampleHeader('CREATED BY')
|
||||
->example('RAW01234'),
|
||||
ImportColumn::make('updated_by')
|
||||
->label('UPDATED BY')
|
||||
->exampleHeader('UPDATED BY')
|
||||
->example('RAW01234'),
|
||||
];
|
||||
}
|
||||
|
||||
public function resolveRecord(): ?TempStopCharacteristic
|
||||
{
|
||||
// return TempStopCharacteristic::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
|
||||
return new TempStopCharacteristic;
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
{
|
||||
$body = 'Your temp stop characteristic 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;
|
||||
}
|
||||
}
|
||||
793
app/Filament/Resources/TempStopCharacteristicResource.php
Normal file
793
app/Filament/Resources/TempStopCharacteristicResource.php
Normal file
@@ -0,0 +1,793 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Exports\TempStopCharacteristicExporter;
|
||||
use App\Filament\Imports\TempStopCharacteristicImporter;
|
||||
use App\Filament\Resources\TempStopCharacteristicResource\Pages;
|
||||
use App\Models\Item;
|
||||
use App\Models\Machine;
|
||||
use App\Models\Plant;
|
||||
use App\Models\TempStopCharacteristic;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class TempStopCharacteristicResource extends Resource
|
||||
{
|
||||
protected static ?string $model = TempStopCharacteristic::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Laser Marking';
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
Section::make('')
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->label('Plant Name')
|
||||
->relationship('plant', 'name')
|
||||
->reactive()
|
||||
->searchable()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||
})
|
||||
->required()
|
||||
->default(function () {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? null : optional(TempStopCharacteristic::latest()->first())->plant_id ?? null;
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('item_id', null);
|
||||
$set('aufnr', null);
|
||||
$set('gernr', null);
|
||||
$set('machine_id', null);
|
||||
$set('machine_name', null);
|
||||
$set('has_stop_flow_id', '2');
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->disabled(fn (Get $get) => ! empty($get('id'))),
|
||||
Forms\Components\Select::make('item_id')
|
||||
->label('Item Code')
|
||||
// ->relationship('item', 'id')
|
||||
->reactive()
|
||||
->required()
|
||||
->searchable()
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Item::where('plant_id', $plantId)->pluck('code', 'id');
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('aufnr', null);
|
||||
$set('gernr', null);
|
||||
$set('has_stop_flow_id', '2');
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->default(function () {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? null : optional(TempStopCharacteristic::latest()->first())->item_id ?? null;
|
||||
})
|
||||
->disabled(fn (Get $get) => ! empty($get('id'))),
|
||||
Forms\Components\Select::make('machine_id')
|
||||
->label('Work Center')
|
||||
// ->relationship('machine', 'name')
|
||||
->reactive()
|
||||
->searchable()
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Machine::where('plant_id', $plantId)->pluck('work_center', 'id');
|
||||
})
|
||||
->required()
|
||||
->default(function () {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? null : optional(TempStopCharacteristic::latest()->first())->machine_id ?? null;
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('machine_name', null);
|
||||
$set('has_stop_flow_id', '2');
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->disabled(fn (Get $get) => ! empty($get('id'))),
|
||||
Forms\Components\TextInput::make('machine_name')
|
||||
->label('Machine Name')
|
||||
->reactive()
|
||||
->nullable()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('has_stop_flow_id', '2');
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->required()
|
||||
->disabled(fn (Get $get) => ! empty($get('id'))),
|
||||
Forms\Components\TextInput::make('aufnr')
|
||||
->label('Job Number')
|
||||
->reactive()
|
||||
->numeric()
|
||||
->minlength(7)
|
||||
->maxlength(10)
|
||||
->required(function (callable $get) {
|
||||
$item = $get('item_id');
|
||||
if ($item) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('gernr', null);
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->default(function () {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? null : optional(TempStopCharacteristic::latest()->first())->aufnr ?? null;
|
||||
})
|
||||
->readOnly(fn ($get) => ($get('item_id') == null))
|
||||
->disabled(fn (Get $get) => ! empty($get('id'))),
|
||||
Forms\Components\TextInput::make('gernr')
|
||||
->label('Serial Number')
|
||||
->reactive()
|
||||
->minLength(13)
|
||||
->readOnly(fn (callable $get) => ! $get('aufnr'))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->required()
|
||||
->disabled(fn (Get $get) => ! empty($get('id'))),
|
||||
Forms\Components\TextInput::make('zmm_heading')
|
||||
->label('Zmm Heading')
|
||||
->reactive()
|
||||
->nullable()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->required()
|
||||
->disabled(fn (Get $get) => ! empty($get('id'))),
|
||||
Forms\Components\Select::make('model_type')
|
||||
->label('Model Type')
|
||||
->reactive()
|
||||
->nullable()
|
||||
->searchable()
|
||||
->required()
|
||||
->options(function () {
|
||||
return [
|
||||
'MOTOR' => 'MOTOR',
|
||||
'PUMP' => 'PUMP',
|
||||
'NAME_PLATE' => 'NAME_PLATE',
|
||||
'UNKNOWN' => 'UNKNOWN',
|
||||
];
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->default('MOTOR')
|
||||
->disabled(fn (Get $get) => ! empty($get('id'))),
|
||||
Forms\Components\TextInput::make('characteristic_field')
|
||||
->label('Master Characteristic Field')
|
||||
->reactive()
|
||||
->nullable()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->required()
|
||||
->disabled(fn (Get $get) => ! empty($get('id'))),
|
||||
Forms\Components\TextInput::make('samlight_logged_name')
|
||||
->label('SAMLight Logged Name')
|
||||
->reactive()
|
||||
->nullable()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->disabled(fn (Get $get) => ! empty($get('id'))),
|
||||
Forms\Components\DateTimePicker::make('stopped_at')
|
||||
->label('Stopped At')
|
||||
->default(now())
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('stopped_by')
|
||||
->label('Stopped By')
|
||||
->reactive()
|
||||
->default(Filament::auth()->user()?->name)
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('has_stop_flow_id')
|
||||
->label('Has Stop Flow ID')
|
||||
->reactive()
|
||||
->default('2')
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$curId = $get('id');
|
||||
if (! $curId) {
|
||||
$set('has_stop_flow_id', '2');
|
||||
}
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\Hidden::make('created_by')
|
||||
->label('Created By')
|
||||
->default(Filament::auth()->user()?->name),
|
||||
Forms\Components\Hidden::make('updated_by')
|
||||
->label('Updated By')
|
||||
->default(Filament::auth()->user()?->name),
|
||||
Forms\Components\TextInput::make('id')
|
||||
->hidden()
|
||||
->readOnly(),
|
||||
])
|
||||
->columns(['default' => 1, 'sm' => 2]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('No.')
|
||||
->label('No.')
|
||||
->getStateUsing(function ($record, $livewire, $column, $rowLoop) {
|
||||
$paginator = $livewire->getTableRecords();
|
||||
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
|
||||
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
|
||||
|
||||
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->label('Plant Name')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('machine.work_center')
|
||||
->label('Work Center')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('machine_name')
|
||||
->label('Machine Name')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('item.code')
|
||||
->label('Item Code')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('aufnr')
|
||||
->label('Job Number')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('gernr')
|
||||
->label('Serial Number')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('zmm_heading')
|
||||
->label('Zmm Heading')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('model_type')
|
||||
->label('Model Type')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('characteristic_field')
|
||||
->label('Master Characteristic Field')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->formatStateUsing(fn (string $state): string => strtoupper(__($state)))
|
||||
->extraAttributes(['class' => 'uppercase'])
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('samlight_logged_name')
|
||||
->label('SAMLIGHT LOGGED NAME')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('stopped_at')
|
||||
->label('Stopped At')
|
||||
->dateTime()
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('stopped_by')
|
||||
->label('Stopped By')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('has_stop_flow_id')
|
||||
->label('Has Stop Flow ID')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->dateTime()
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_by')
|
||||
->label('Created By')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->label('Updated At')
|
||||
->dateTime()
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('updated_by')
|
||||
->label('Updated By')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('deleted_at')
|
||||
->label('Deleted At')
|
||||
->dateTime()
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->searchPlaceholder('Search Job / Serial Number')
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
Filter::make('advanced_filters')
|
||||
->label('Advanced Filters')
|
||||
->form([
|
||||
Select::make('Plant')
|
||||
->label('Search by Plant Name')
|
||||
->nullable()
|
||||
->searchable()
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return Plant::where('id', $userHas)->pluck('name', 'id')->toArray();
|
||||
} else {
|
||||
return Plant::whereHas('tempStopCharacteristics', 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): void {
|
||||
$set('machine', null);
|
||||
$set('item_id', null);
|
||||
// $set('aufnr', null);
|
||||
}),
|
||||
Select::make('machine')
|
||||
->label('Search by Work Center')
|
||||
->nullable()
|
||||
->searchable()
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
|
||||
if (empty($plantId)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Machine::whereHas('tempStopCharacteristics', function ($query) use ($plantId) {
|
||||
if ($plantId) {
|
||||
$query->where('plant_id', $plantId);
|
||||
}
|
||||
})->pluck('work_center', 'id');
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get): void {
|
||||
// $set('item_id', null);
|
||||
// $set('aufnr', null);
|
||||
}),
|
||||
TextInput::make('machine_name')
|
||||
->label('Machine Name')
|
||||
->placeholder('Enter Machine Name'),
|
||||
Select::make('item_id')
|
||||
->label('Search by Item Code')
|
||||
->nullable()
|
||||
->searchable()
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
|
||||
if (empty($plantId)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Item::whereHas('tempStopCharacteristics', function ($query) use ($plantId) {
|
||||
if ($plantId) {
|
||||
$query->where('plant_id', $plantId);
|
||||
}
|
||||
})->pluck('code', 'id');
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get): void {
|
||||
// $set('aufnr', null);
|
||||
}),
|
||||
TextInput::make('aufnr')
|
||||
->label('Job Number')
|
||||
->placeholder('Enter Job Number')
|
||||
->numeric()
|
||||
->maxlength(10),
|
||||
TextInput::make('gernr')
|
||||
->label('Serial Number')
|
||||
->placeholder('Enter Serial Number')
|
||||
->numeric(),
|
||||
TextInput::make('zmm_heading')
|
||||
->label('Zmm Heading')
|
||||
->placeholder('Enter Zmm Heading'),
|
||||
Select::make('model_type')
|
||||
->label('Search by Model Type')
|
||||
->nullable()
|
||||
->searchable()
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
$plantId = $get('Plant');
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return TempStopCharacteristic::where('plant_id', $userHas)->pluck('model_type', 'model_type')->toArray();
|
||||
} elseif ($plantId) {
|
||||
return TempStopCharacteristic::where('plant_id', $plantId)->select('model_type')->distinct()->pluck('model_type', 'model_type');
|
||||
} else {
|
||||
return TempStopCharacteristic::select('model_type')->distinct()->pluck('model_type', 'model_type');
|
||||
}
|
||||
}),
|
||||
TextInput::make('characteristic_field')
|
||||
->label('Master Characteristic Field')
|
||||
->placeholder('Enter Master Characteristic Field'),
|
||||
TextInput::make('samlight_logged_name')
|
||||
->label('Samlight Logged Name')
|
||||
->placeholder('Enter Samlight Logged Name'),
|
||||
Select::make('stopped_by')
|
||||
->label('Search by Stopped By')
|
||||
->nullable()
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
if (! $plantId) {
|
||||
return TempStopCharacteristic::whereNotNull('stopped_by')->select('stopped_by')->distinct()->pluck('stopped_by', 'stopped_by');
|
||||
} else {
|
||||
return TempStopCharacteristic::where('plant_id', $plantId)->whereNotNull('stopped_by')->select('stopped_by')->distinct()->pluck('stopped_by', 'stopped_by');
|
||||
}
|
||||
})
|
||||
->searchable()
|
||||
->reactive(),
|
||||
DateTimePicker::make('stopped_from')
|
||||
->label('Stopped From')
|
||||
->placeholder('Select From DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
DateTimePicker::make('stopped_to')
|
||||
->label('Stopped To')
|
||||
->placeholder('Select To DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
Select::make('created_by')
|
||||
->label('Search by Created By')
|
||||
->nullable()
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
if (! $plantId) {
|
||||
return TempStopCharacteristic::whereNotNull('created_by')->select('created_by')->distinct()->pluck('created_by', 'created_by');
|
||||
} else {
|
||||
return TempStopCharacteristic::where('plant_id', $plantId)->whereNotNull('created_by')->select('created_by')->distinct()->pluck('created_by', 'created_by');
|
||||
}
|
||||
})
|
||||
->searchable()
|
||||
->reactive(),
|
||||
DateTimePicker::make('created_from')
|
||||
->label('Created From')
|
||||
->placeholder('Select From DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
DateTimePicker::make('created_to')
|
||||
->label('Created To')
|
||||
->placeholder('Select To DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
Select::make('updated_by')
|
||||
->label('Search by Updated By')
|
||||
->nullable()
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
if (! $plantId) {
|
||||
return TempStopCharacteristic::whereNotNull('updated_by')->select('updated_by')->distinct()->pluck('updated_by', 'updated_by');
|
||||
} else {
|
||||
return TempStopCharacteristic::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),
|
||||
TextInput::make('has_stop_flow_id')
|
||||
->label('Has Stop Flow ID')
|
||||
->placeholder('Enter Has Stop Flow ID'),
|
||||
])
|
||||
->query(function ($query, array $data) {
|
||||
// Hide all records initially if no filters are applied
|
||||
if (empty($data['Plant']) && empty($data['machine']) && empty($data['machine_name']) && empty($data['item_id']) && empty($data['aufnr']) && empty($data['gernr']) && empty($data['zmm_heading']) && empty($data['model_type']) && empty($data['characteristic_field']) && empty($data['samlight_logged_name']) && empty($data['stopped_by']) && empty($data['stopped_from']) && empty($data['stopped_to']) && empty($data['created_by']) && empty($data['created_from']) && empty($data['created_to']) && empty($data['updated_by']) && empty($data['updated_from']) && empty($data['updated_to']) && empty($data['has_stop_flow_id'])) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
|
||||
if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['machine'])) {
|
||||
$query->where('machine_id', $data['machine']);
|
||||
}
|
||||
|
||||
if (! empty($data['machine_name'])) {
|
||||
$query->where('machine_name', 'like', '%'.$data['machine_name'].'%');
|
||||
}
|
||||
|
||||
if (! empty($data['item_id'])) {
|
||||
$query->where('item_id', $data['item_id']);
|
||||
}
|
||||
|
||||
if (! empty($data['aufnr'])) {
|
||||
$query->where('aufnr', 'like', '%'.$data['aufnr'].'%');
|
||||
}
|
||||
|
||||
if (! empty($data['gernr'])) {
|
||||
$query->where('gernr', 'like', '%'.$data['gernr'].'%');
|
||||
}
|
||||
|
||||
if (! empty($data['zmm_heading'])) {
|
||||
$query->where('zmm_heading', 'like', '%'.$data['zmm_heading'].'%');
|
||||
}
|
||||
|
||||
if (! empty($data['model_type'])) {
|
||||
$query->where('model_type', $data['model_type']);
|
||||
}
|
||||
|
||||
if (! empty($data['characteristic_field'])) {
|
||||
$query->where('characteristic_field', 'like', '%'.$data['characteristic_field'].'%');
|
||||
}
|
||||
|
||||
if (! empty($data['samlight_logged_name'])) {
|
||||
$query->where('samlight_logged_name', 'like', '%'.$data['samlight_logged_name'].'%');
|
||||
}
|
||||
|
||||
if (! empty($data['stopped_by'])) {
|
||||
$query->where('stopped_by', $data['stopped_by']);
|
||||
}
|
||||
|
||||
if (! empty($data['stopped_from'])) {
|
||||
$query->where('stopped_at', '>=', $data['stopped_from']);
|
||||
}
|
||||
|
||||
if (! empty($data['stopped_to'])) {
|
||||
$query->where('stopped_at', '<=', $data['stopped_to']);
|
||||
}
|
||||
|
||||
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']);
|
||||
}
|
||||
|
||||
if (! empty($data['has_stop_flow_id'])) {
|
||||
$query->where('has_stop_flow_id', 'like', '%'.$data['has_stop_flow_id'].'%');
|
||||
}
|
||||
|
||||
})
|
||||
->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['machine'])) {
|
||||
$indicators[] = 'Work Center: '.Machine::where('id', $data['machine'])->value('work_center');
|
||||
}
|
||||
|
||||
if (! empty($data['machine_name'])) {
|
||||
$indicators[] = 'Machine Name: '.$data['machine_name'];
|
||||
}
|
||||
|
||||
if (! empty($data['item_id'])) {
|
||||
$indicators[] = 'Item Code: '.Item::where('id', $data['item_id'])->value('code');
|
||||
}
|
||||
|
||||
if (! empty($data['aufnr'])) {
|
||||
$indicators[] = 'Job No: '.$data['aufnr'];
|
||||
}
|
||||
|
||||
if (! empty($data['gernr'])) {
|
||||
$indicators[] = 'Serial No: '.$data['gernr'];
|
||||
}
|
||||
|
||||
if (! empty($data['zmm_heading'])) {
|
||||
$indicators[] = 'Zmm Heading: '.$data['zmm_heading'];
|
||||
}
|
||||
|
||||
if (! empty($data['model_type'])) {
|
||||
$indicators[] = 'Model Type: '.$data['model_type'];
|
||||
}
|
||||
|
||||
if (! empty($data['characteristic_field'])) {
|
||||
$indicators[] = 'Master Characteristic Field: '.$data['characteristic_field'];
|
||||
}
|
||||
|
||||
if (! empty($data['work_flow_id'])) {
|
||||
$indicators[] = 'Work Flow ID: '.$data['work_flow_id'];
|
||||
}
|
||||
|
||||
if (! empty($data['samlight_logged_name'])) {
|
||||
$indicators[] = 'Samlight Logged Name: '.$data['samlight_logged_name'];
|
||||
}
|
||||
|
||||
if (! empty($data['stopped_by'])) {
|
||||
$indicators[] = 'Stopped By: '.$data['stopped_by'];
|
||||
}
|
||||
|
||||
if (! empty($data['stopped_from'])) {
|
||||
$indicators[] = 'Stopped From: '.$data['stopped_from'];
|
||||
}
|
||||
|
||||
if (! empty($data['stopped_to'])) {
|
||||
$indicators[] = 'Stopped To: '.$data['stopped_to'];
|
||||
}
|
||||
|
||||
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'];
|
||||
}
|
||||
|
||||
if (! empty($data['has_stop_flow_id'])) {
|
||||
$indicators[] = 'Stop Flow ID: '.$data['has_stop_flow_id'];
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
}),
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
Tables\Actions\ViewAction::make(),
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||
Tables\Actions\RestoreBulkAction::make(),
|
||||
]),
|
||||
])
|
||||
->headerActions([
|
||||
ImportAction::make()
|
||||
->label('Import Temp Stop Characteristics')
|
||||
->color('warning')
|
||||
->importer(TempStopCharacteristicImporter::class)
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view import temp stop characteristics');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->label('Export Temp Stop Characteristics')
|
||||
->color('warning')
|
||||
->exporter(TempStopCharacteristicExporter::class)
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view export temp stop characteristics');
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListTempStopCharacteristics::route('/'),
|
||||
'create' => Pages\CreateTempStopCharacteristic::route('/create'),
|
||||
'view' => Pages\ViewTempStopCharacteristic::route('/{record}'),
|
||||
'edit' => Pages\EditTempStopCharacteristic::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getEloquentQuery(): Builder
|
||||
{
|
||||
return parent::getEloquentQuery()
|
||||
->withoutGlobalScopes([
|
||||
SoftDeletingScope::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\TempStopCharacteristicResource\Pages;
|
||||
|
||||
use App\Filament\Resources\TempStopCharacteristicResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateTempStopCharacteristic extends CreateRecord
|
||||
{
|
||||
protected static string $resource = TempStopCharacteristicResource::class;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\TempStopCharacteristicResource\Pages;
|
||||
|
||||
use App\Filament\Resources\TempStopCharacteristicResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditTempStopCharacteristic extends EditRecord
|
||||
{
|
||||
protected static string $resource = TempStopCharacteristicResource::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\TempStopCharacteristicResource\Pages;
|
||||
|
||||
use App\Filament\Resources\TempStopCharacteristicResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListTempStopCharacteristics extends ListRecords
|
||||
{
|
||||
protected static string $resource = TempStopCharacteristicResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\TempStopCharacteristicResource\Pages;
|
||||
|
||||
use App\Filament\Resources\TempStopCharacteristicResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewTempStopCharacteristic extends ViewRecord
|
||||
{
|
||||
protected static string $resource = TempStopCharacteristicResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\EditAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user