Added request characteristic importer and model_type column added and updated report filter logic
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

This commit is contained in:
dhanabalan
2026-05-11 10:39:20 +05:30
parent 8e2a0e79dc
commit bce19056c7
4 changed files with 610 additions and 11 deletions

View File

@@ -0,0 +1,141 @@
<?php
namespace App\Filament\Imports;
use App\Models\RequestCharacteristic;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;
class RequestCharacteristicImporter extends Importer
{
protected static ?string $model = RequestCharacteristic::class;
public static function getColumns(): array
{
return [
ImportColumn::make('plant')
->requiredMapping()
->exampleHeader('PLANT CODE')
->example('1000')
->label('PLANT CODE')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('machine')
->requiredMapping()
->exampleHeader('WORK CENTER')
->example('RMGLAS01')
->label('WORK CENTER')
->relationship(resolveUsing: 'work_center')
->rules(['required']),
ImportColumn::make('item')
->requiredMapping()
->exampleHeader('ITEM CODE')
->example('630214')
->label('ITEM CODE')
->relationship(resolveUsing: 'code')
->rules(['required']),
ImportColumn::make('characteristicApproverMaster')
->requiredMapping()
->relationship()
->rules(['required']),
ImportColumn::make('aufnr')
->label('AUFNR')
->exampleHeader('AUFNR')
->example('1234567'),
ImportColumn::make('characteristic_name')
->label('CHARACTERISTIC NAME')
->exampleHeader('CHARACTERISTIC NAME')
->example('ZMM_PUMPSET_MODEL'),
ImportColumn::make('current_value')
->label('CURRENT VALUE')
->exampleHeader('CURRENT VALUE')
->example('MVN-32/02 D R'),
ImportColumn::make('update_value')
->label('UPDATE VALUE')
->exampleHeader('UPDATE VALUE')
->example('MVN-32/02 TR3'),
ImportColumn::make('approver_status1')
->label('APPROVER STATUS 1')
->exampleHeader('APPROVER STATUS 1')
->example('Hold'),
ImportColumn::make('approver_status2')
->label('APPROVER STATUS 2')
->exampleHeader('APPROVER STATUS 2')
->example('Approved'),
ImportColumn::make('approver_status3')
->label('APPROVER STATUS 3')
->exampleHeader('APPROVER STATUS 3')
->example('Rejected'),
ImportColumn::make('approver_remark1')
->label('APPROVER REMARK 1')
->exampleHeader('APPROVER REMARK 1')
->example('Hold for review'),
ImportColumn::make('approver_remark2')
->label('APPROVER REMARK 2')
->exampleHeader('APPROVER REMARK 2')
->example('Approved with comments'),
ImportColumn::make('approver_remark3')
->label('APPROVER REMARK 3')
->exampleHeader('APPROVER REMARK 3')
->example('Rejected due to incorrect value'),
ImportColumn::make('work_flow_id')
->label('WORK FLOW ID')
->exampleHeader('WORK FLOW ID')
->example('WF-260303-0001'),
ImportColumn::make('mail_status')
->label('MAIL STATUS')
->exampleHeader('MAIL STATUS')
->example('Sent'),
ImportColumn::make('trigger_at')
->label('TRIGGER AT')
->exampleHeader('MAIL STATUS')
->rules(['datetime']),
ImportColumn::make('approved1_at')
->label('APPROVED1 AT')
->exampleHeader('APPROVED1 AT')
->rules(['datetime']),
ImportColumn::make('approved2_at')
->label('APPROVED2 AT')
->exampleHeader('APPROVED2 AT')
->rules(['datetime']),
ImportColumn::make('approved3_at')
->label('APPROVED3 AT')
->exampleHeader('APPROVED3 AT')
->rules(['datetime']),
ImportColumn::make('created_by')
->label('CREATED BY')
->exampleHeader('CREATED BY')
->example('RAW01234'),
ImportColumn::make('updated_by')
->label('UPDATED BY')
->exampleHeader('UPDATED BY')
->example('RAW01234'),
ImportColumn::make('model_type')
->label('MODEL TYPE')
->exampleHeader('MODEL TYPE')
->example('PUMP'),
];
}
public function resolveRecord(): ?RequestCharacteristic
{
// return RequestCharacteristic::firstOrNew([
// // Update existing records, matching them by `$this->data['column_name']`
// 'email' => $this->data['email'],
// ]);
return new RequestCharacteristic();
}
public static function getCompletedNotificationBody(Import $import): string
{
$body = 'Your request 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;
}
}

View File

@@ -6,6 +6,7 @@ use App\Filament\Exports\CharacteristicApproverMasterExporter;
use App\Filament\Imports\CharacteristicApproverMasterImporter; use App\Filament\Imports\CharacteristicApproverMasterImporter;
use App\Filament\Resources\CharacteristicApproverMasterResource\Pages; use App\Filament\Resources\CharacteristicApproverMasterResource\Pages;
use App\Models\CharacteristicApproverMaster; use App\Models\CharacteristicApproverMaster;
use App\Models\Item;
use App\Models\Machine; use App\Models\Machine;
use App\Models\Plant; use App\Models\Plant;
use Filament\Facades\Filament; use Filament\Facades\Filament;
@@ -20,6 +21,10 @@ use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Validation\Rule; use Illuminate\Validation\Rule;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Tables\Filters\Filter;
class CharacteristicApproverMasterResource extends Resource class CharacteristicApproverMasterResource extends Resource
{ {
@@ -392,7 +397,203 @@ class CharacteristicApproverMasterResource extends Resource
]) ])
->filters([ ->filters([
Tables\Filters\TrashedFilter::make(), 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('requestCharacteristics', 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('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('requestCharacteristics', 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);
}),
Select::make('approver_type')
->label('Approver Type')
->options([
'Characteristic' => 'Characteristic',
'Quality' => 'Quality',
])
->placeholder('Select Type')
->afterStateUpdated(function ($state, callable $set) {
$set('name1', null);
$set('name2', null);
$set('name3', null);
}),
TextInput::make('machine_name')
->label('Machine Name')
->placeholder('Enter Machine Name'),
TextInput::make('characteristic_field')
->label('Characteristic Field')
->placeholder('Enter Characteristic Field'),
TextInput::make('name1')
->label('Approver Name 1')
->placeholder('Enter Approver Name 2')
->afterStateUpdated(function ($state, callable $set) {
$set('name2', null);
$set('name3', null);
}),
TextInput::make('name2')
->label('Approver Name 2')
->placeholder('Enter Approver Name 2')
->afterStateUpdated(function ($state, callable $set) {
$set('name3', null);
}),
TextInput::make('name3')
->label('Approver Name 3')
->placeholder('Enter Approver Name 2'),
DateTimePicker::make(name: '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),
])
->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['characteristic_field']) && empty($data['approver_type']) && empty($data['name1']) && empty($data['name2']) && empty($data['name3']) && empty($data['created_from']) && empty($data['created_to'])) {
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['characteristic_field'])) {
$query->where('characteristic_field', 'like', '%'.$data['characteristic_field'].'%');
}
if (! empty($data['approver_type'])) {
$query->where('approver_type', 'like', '%'.$data['approver_type'].'%');
}
if (! empty($data['name1'])) {
$query->where('name1', 'like', '%'.$data['name1'].'%');
}
if (! empty($data['name2'])) {
$query->where('name2', 'like', '%'.$data['name2'].'%');
}
if (! empty($data['name3'])) {
$query->where('name3', 'like', '%'.$data['name3'].'%');
}
if (! empty($data['created_from'])) {
$query->where('created_at', '>=', $data['created_from']);
}
if (! empty($data['created_to'])) {
$query->where('created_at', '<=', $data['created_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['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['characteristic_field'])) {
$indicators[] = 'Characteristic Field: '.$data['characteristic_field'];
}
if (! empty($data['approver_type'])) {
$indicators[] = 'Approver Type: '.$data['approver_type'];
}
if (! empty($data['name1'])) {
$indicators[] = 'Approver Name 1: '.$data['name1'];
}
if (! empty($data['name2'])) {
$indicators[] = 'Approver Name 2: '.$data['name2'];
}
if (! empty($data['name3'])) {
$indicators[] = 'Approver Name 3: '.$data['name3'];
}
if (! empty($data['created_from'])) {
$indicators[] = 'From: '.$data['created_from'];
}
if (! empty($data['created_to'])) {
$indicators[] = 'To: '.$data['created_to'];
}
return $indicators;
}),
]) ])
->filtersFormMaxHeight('280px')
->actions([ ->actions([
Tables\Actions\ViewAction::make(), Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(), Tables\Actions\EditAction::make(),

View File

@@ -2028,6 +2028,12 @@ class ClassCharacteristicResource extends Resource
TextInput::make('gernr') TextInput::make('gernr')
->label('Serial Number') ->label('Serial Number')
->placeholder('Enter Serial Number'), ->placeholder('Enter Serial Number'),
TextInput::make('zmm_heading')
->label('Heading')
->placeholder('Enter Heading'),
TextInput::make('model_type')
->label('Model Type')
->placeholder('Enter Model Type'),
DateTimePicker::make(name: 'created_from') DateTimePicker::make(name: 'created_from')
->label('Created From') ->label('Created From')
->placeholder('Select From DateTime') ->placeholder('Select From DateTime')
@@ -2041,7 +2047,7 @@ class ClassCharacteristicResource extends Resource
]) ])
->query(function ($query, array $data) { ->query(function ($query, array $data) {
// Hide all records initially if no filters are applied // Hide all records initially if no filters are applied
if (empty($data['Plant']) && empty($data['machine']) && empty($data['item_id']) && empty($data['aufnr']) && empty($data['gernr']) && empty($data['created_from']) && empty($data['created_to'])) { if (empty($data['Plant']) && empty($data['machine']) && empty($data['item_id']) && empty($data['aufnr']) && empty($data['gernr']) && empty($data['zmm_heading']) && empty($data['model_type']) && empty($data['created_from']) && empty($data['created_to'])) {
return $query->whereRaw('1 = 0'); return $query->whereRaw('1 = 0');
} }
@@ -2071,6 +2077,14 @@ class ClassCharacteristicResource extends Resource
$query->where('gernr', 'like', '%'.$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', 'like', '%'.$data['model_type'].'%');
}
if (! empty($data['created_from'])) { if (! empty($data['created_from'])) {
$query->where('created_at', '>=', $data['created_from']); $query->where('created_at', '>=', $data['created_from']);
} }
@@ -2108,6 +2122,14 @@ class ClassCharacteristicResource extends Resource
$indicators[] = 'Serial Number: '.$data['gernr']; $indicators[] = 'Serial Number: '.$data['gernr'];
} }
if (! empty($data['zmm_heading'])) {
$indicators[] = 'Heading: '.$data['zmm_heading'];
}
if (! empty($data['model_type'])) {
$indicators[] = 'Model Type: '.$data['model_type'];
}
if (! empty($data['created_from'])) { if (! empty($data['created_from'])) {
$indicators[] = 'From: '.$data['created_from']; $indicators[] = 'From: '.$data['created_from'];
} }

View File

@@ -3,12 +3,14 @@
namespace App\Filament\Resources; namespace App\Filament\Resources;
use App\Filament\Exports\RequestCharacteristicExporter; use App\Filament\Exports\RequestCharacteristicExporter;
use App\Filament\Imports\RequestCharacteristicImporter;
use App\Filament\Resources\RequestCharacteristicResource\Pages; use App\Filament\Resources\RequestCharacteristicResource\Pages;
use App\Models\CharacteristicApproverMaster; use App\Models\CharacteristicApproverMaster;
use App\Models\Item; use App\Models\Item;
use App\Models\Machine; use App\Models\Machine;
use App\Models\Plant; use App\Models\Plant;
use App\Models\RequestCharacteristic; use App\Models\RequestCharacteristic;
use App\Models\StickerMaster;
use Closure; use Closure;
use Filament\Facades\Filament; use Filament\Facades\Filament;
use Filament\Forms; use Filament\Forms;
@@ -19,6 +21,7 @@ use Filament\Forms\Components\TextInput;
use Filament\Forms\Form; use Filament\Forms\Form;
use Filament\Forms\Get; use Filament\Forms\Get;
use Filament\Forms\Set; use Filament\Forms\Set;
use Filament\Notifications\Notification;
use Filament\Resources\Resource; use Filament\Resources\Resource;
use Filament\Tables; use Filament\Tables;
use Filament\Tables\Actions\ExportAction; use Filament\Tables\Actions\ExportAction;
@@ -27,6 +30,7 @@ use Filament\Tables\Filters\Filter;
use Filament\Tables\Table; use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope; use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
use Illuminate\Validation\Rule; use Illuminate\Validation\Rule;
@@ -128,6 +132,16 @@ class RequestCharacteristicResource extends Resource
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}) })
->disabled(fn ($get) => self::isFieldDisabled($get)), ->disabled(fn ($get) => self::isFieldDisabled($get)),
Forms\Components\Hidden::make('show_validation_image')
->reactive()
->default(false),
Forms\Components\Hidden::make('validation1_image_url')
->reactive(),
Forms\Components\View::make('components.part-validation-error-icon')
->statePath('validation1_image_url')
->visible(fn ($get) => $get('show_validation_image') == true)
->reactive(),
Forms\Components\TextInput::make('work_flow_id') Forms\Components\TextInput::make('work_flow_id')
->label('Work Flow ID') ->label('Work Flow ID')
->readOnly() ->readOnly()
@@ -139,7 +153,42 @@ class RequestCharacteristicResource extends Resource
return self::isNewWorkFlow($get); return self::isNewWorkFlow($get);
} }
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}), })
->suffixAction(
Forms\Components\Actions\Action::make('toggleValidationImage')
->icon(fn (callable $get) => $get('show_validation_image') ? 'heroicon-o-eye-slash' : 'heroicon-o-eye')
->tooltip('View Validation Image')
->action(function (callable $get, $set) {
$currentState = $get('show_validation_image');
$set('show_validation_image', ! $currentState);
if ($currentState == true) {
$set('validation1_image_url', null);
return;
}
$workFlowId = $get('work_flow_id');
if (!$workFlowId) {
Notification::make()
->title('Missing Workflow ID')
->body('Please select a Workflow ID.')
->danger()
->send();
return;
}
// Build filename
$fileName = "{$workFlowId}.png";
$imageUrl = route('workflow.image', [
'filename' => $fileName,
]);
$set('validation1_image_url', $imageUrl);
})
),
// ->rule(function (callable $get) { // ->rule(function (callable $get) {
// return Rule::unique('request_characteristics', 'work_flow_id') // return Rule::unique('request_characteristics', 'work_flow_id')
// ->where('plant_id', $get('plant_id')) // ->where('plant_id', $get('plant_id'))
@@ -312,7 +361,7 @@ class RequestCharacteristicResource extends Resource
Forms\Components\Select::make('characteristic_approver_master_id') Forms\Components\Select::make('characteristic_approver_master_id')
->label('Master Characteristic Field') ->label('Master Characteristic Field')
// ->relationship('characteristicApproverMaster', 'characteristic_field') // ->relationship('characteristicApproverMaster', 'characteristic_field')
->columnSpan(2) // ->columnSpan(2)
->reactive() ->reactive()
->nullable() ->nullable()
->searchable() ->searchable()
@@ -340,6 +389,17 @@ class RequestCharacteristicResource extends Resource
$set('updated_by', Filament::auth()->user()?->name); $set('updated_by', Filament::auth()->user()?->name);
}) })
->required(), ->required(),
Forms\Components\TextInput::make('model_type')
->label('Model Type')
->reactive()
->nullable()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$set('characteristic_name', null);
$set('current_value', null);
$set('update_value', null);
$set('updated_by', Filament::auth()->user()?->name);
})
->required(),
// ->disabled(fn ($get) => self::isFieldDisabled($get)) // ->disabled(fn ($get) => self::isFieldDisabled($get))
Section::make('Request Characteristic Details') Section::make('Request Characteristic Details')
// ->columnSpan(['default' => 2, 'sm' => 4]) // ->columnSpan(['default' => 2, 'sm' => 4])
@@ -500,6 +560,7 @@ class RequestCharacteristicResource extends Resource
Forms\Components\TextInput::make('approver_remark1') Forms\Components\TextInput::make('approver_remark1')
->label('Approver Remark') ->label('Approver Remark')
->live() ->live()
->maxLength(60)
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$appStat = $get('approver_status1'); $appStat = $get('approver_status1');
if ($appStat && $state) { if ($appStat && $state) {
@@ -615,6 +676,7 @@ class RequestCharacteristicResource extends Resource
Forms\Components\TextInput::make('approver_remark2') Forms\Components\TextInput::make('approver_remark2')
->label('Approver Remark') ->label('Approver Remark')
->live() ->live()
->maxLength(60)
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$appStat = $get('approver_status2'); $appStat = $get('approver_status2');
if ($appStat && $state) { if ($appStat && $state) {
@@ -727,6 +789,7 @@ class RequestCharacteristicResource extends Resource
Forms\Components\TextInput::make('approver_remark3') Forms\Components\TextInput::make('approver_remark3')
->label('Approver Remark') ->label('Approver Remark')
->live() ->live()
->maxLength(60)
->afterStateUpdated(function ($state, callable $set, callable $get) { ->afterStateUpdated(function ($state, callable $set, callable $get) {
$appStat = $get('approver_status3'); $appStat = $get('approver_status3');
if ($appStat && $state) { if ($appStat && $state) {
@@ -916,6 +979,11 @@ class RequestCharacteristicResource extends Resource
->formatStateUsing(fn (string $state): string => strtoupper(__($state))) ->formatStateUsing(fn (string $state): string => strtoupper(__($state)))
->extraAttributes(['class' => 'uppercase']) ->extraAttributes(['class' => 'uppercase'])
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('model_type')
->label('Model Type')
->alignCenter()
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('characteristic_name') Tables\Columns\TextColumn::make('characteristic_name')
->label('Characteristic Name') ->label('Characteristic Name')
->default('-') ->default('-')
@@ -956,12 +1024,14 @@ class RequestCharacteristicResource extends Resource
default => 'gray', default => 'gray',
}) })
->alignCenter() ->alignCenter()
->default('-')
->searchable() ->searchable()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('approver_remark1') Tables\Columns\TextColumn::make('approver_remark1')
->label('Approver Remark 1') ->label('Approver Remark 1')
// ->color('success') // ->color('success')
->alignCenter() ->alignCenter()
->default('-')
->searchable() ->searchable()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('approved1_at') Tables\Columns\TextColumn::make('approved1_at')
@@ -984,12 +1054,14 @@ class RequestCharacteristicResource extends Resource
default => 'gray', default => 'gray',
}) })
->alignCenter() ->alignCenter()
->default('-')
->searchable() ->searchable()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('approver_remark2') Tables\Columns\TextColumn::make('approver_remark2')
->label('Approver Remark 2') ->label('Approver Remark 2')
// ->color('success') // ->color('success')
->alignCenter() ->alignCenter()
->default('-')
->searchable() ->searchable()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('approved2_at') Tables\Columns\TextColumn::make('approved2_at')
@@ -1012,12 +1084,14 @@ class RequestCharacteristicResource extends Resource
default => 'gray', default => 'gray',
}) })
->alignCenter() ->alignCenter()
->default('-')
->searchable() ->searchable()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('approver_remark3') Tables\Columns\TextColumn::make('approver_remark3')
->label('Approver Remark 3') ->label('Approver Remark 3')
// ->color('success') // ->color('success')
->alignCenter() ->alignCenter()
->default('-')
->searchable() ->searchable()
->sortable(), ->sortable(),
Tables\Columns\TextColumn::make('approved3_at') Tables\Columns\TextColumn::make('approved3_at')
@@ -1160,6 +1234,67 @@ class RequestCharacteristicResource extends Resource
->numeric() ->numeric()
->minlength(7) ->minlength(7)
->maxlength(10), ->maxlength(10),
TextInput::make('work_flow_id')
->label('Work Flow ID')
->placeholder('Enter Work Flow ID'),
TextInput::make('machine_name')
->label('Machine Name')
->placeholder('Enter Machine Name'),
Select::make('request_type')
->label('Request Type')
->options([
'Characteristic' => 'Characteristic',
'Quality' => 'Quality',
])
->placeholder('Select Request Type'),
TextInput::make('master_characteristic_field')
->label('Master Characteristic Field')
->placeholder('Enter Master Characteristic Field'),
TextInput::make('model_type')
->label('Model Type')
->placeholder('Enter Model Type'),
Select::make('approver_status')
->label('Approver Status')
->options([
'Approved' => 'Approved',
'Hold' => 'Hold',
'Rejected' => 'Rejected',
])
->placeholder('Select Status')
->afterStateUpdated(function ($state, callable $set) {
$set('approver_status1', null);
$set('approver_status2', null);
$set('approver_status3', null);
}),
Select::make('approver_status1')
->label('Approver Status 1')
->options([
'Approved' => 'Approved',
'Hold' => 'Hold',
'Rejected' => 'Rejected',
])
->placeholder('Select Status')
->afterStateUpdated(function ($state, callable $set) {
$set('approver_status2', null);
$set('approver_status3', null);
}),
Select::make('approver_status2')
->label('Approver Status 2')
->options([
'Approved' => 'Approved',
'Hold' => 'Hold',
'Rejected' => 'Rejected',
])
->placeholder('Select Status'),
Select::make('approver_status3')
->label('Approver Status 3')
->options([
'Approved' => 'Approved',
'Hold' => 'Hold',
'Rejected' => 'Rejected',
])
->placeholder('Select Status'),
DateTimePicker::make(name: 'created_from') DateTimePicker::make(name: 'created_from')
->label('Created From') ->label('Created From')
->placeholder('Select From DateTime') ->placeholder('Select From DateTime')
@@ -1173,7 +1308,7 @@ class RequestCharacteristicResource extends Resource
]) ])
->query(function ($query, array $data) { ->query(function ($query, array $data) {
// Hide all records initially if no filters are applied // Hide all records initially if no filters are applied
if (empty($data['Plant']) && empty($data['machine']) && empty($data['item_id']) && empty($data['aufnr']) && empty($data['created_from']) && empty($data['created_to'])) { if (empty($data['Plant']) && empty($data['machine']) && empty($data['item_id']) && empty($data['aufnr']) && empty($data['model_type']) && empty($data['work_flow_id']) && empty($data['machine_name']) && empty($data['request_type']) && empty($data['master_characteristic_field'])&& empty($data['approver_status1']) && empty($data['approver_status2']) && empty($data['approver_status3']) && empty($data['approver_status']) && empty($data['created_from']) && empty($data['created_to'])) {
return $query->whereRaw('1 = 0'); return $query->whereRaw('1 = 0');
} }
@@ -1199,6 +1334,70 @@ class RequestCharacteristicResource extends Resource
$query->where('aufnr', 'like', '%'.$data['aufnr'].'%'); $query->where('aufnr', 'like', '%'.$data['aufnr'].'%');
} }
if (! empty($data['model_type'])) {
$query->where('model_type', 'like', '%'.$data['model_type'].'%');
}
if (! empty($data['work_flow_id'])) {
$query->where('work_flow_id', 'like', '%'.$data['work_flow_id'].'%');
}
if (!empty($data['machine_name'])) {
$query->whereHas('characteristicApproverMaster', function ($q) use ($data) {
$q->where('characteristic_approver_masters.machine_name', '=', (string) $data['machine_name']);
});
}
if (!empty($data['request_type'])) {
$query->whereHas('characteristicApproverMaster', function ($q) use ($data) {
$q->where('characteristic_approver_masters.approver_type', '=', (string) $data['request_type']);
});
}
if (!empty($data['master_characteristic_field'])) {
$query->whereHas('characteristicApproverMaster', function ($q) use ($data) {
$q->where('characteristic_approver_masters.characteristic_field', '=', (string) $data['master_characteristic_field']);
});
}
if (! empty($data['approver_status1'])) {
$query->where('approver_status1', 'like', '%'.$data['approver_status1'].'%');
}
if (! empty($data['approver_status2'])) {
$query->where('approver_status2', 'like', '%'.$data['approver_status2'].'%');
}
if (! empty($data['approver_status3'])) {
$query->where('approver_status3', 'like', '%'.$data['approver_status3'].'%');
}
if (!empty($data['approver_status'])) {
$status = $data['approver_status'];
$query->whereRaw("
CASE
-- If status3 exists, it must be considered first
WHEN approver_status3 IS NOT NULL AND approver_status3 != ''
THEN approver_status3
-- then status2 overrides only if status3 is empty
WHEN approver_status2 IS NOT NULL AND approver_status2 != ''
THEN approver_status2
-- finally status1 only if both 2 and 3 are empty
WHEN approver_status1 IS NOT NULL AND approver_status1 != ''
THEN approver_status1
ELSE NULL
END = ?
", [$status]);
}
if (! empty($data['created_from'])) { if (! empty($data['created_from'])) {
$query->where('created_at', '>=', $data['created_from']); $query->where('created_at', '>=', $data['created_from']);
} }
@@ -1232,6 +1431,42 @@ class RequestCharacteristicResource extends Resource
$indicators[] = 'Job No: '.$data['aufnr']; $indicators[] = 'Job No: '.$data['aufnr'];
} }
if (! empty($data['model_type'])) {
$indicators[] = 'Model Type: '.$data['model_type'];
}
if (! empty($data['work_flow_id'])) {
$indicators[] = 'Work Flow ID: '.$data['work_flow_id'];
}
if (! empty($data['machine_name'])) {
$indicators[] = 'Machine Name: '.$data['machine_name'];
}
if (! empty($data['request_type'])) {
$indicators[] = 'Request Type: '.$data['request_type'];
}
if (! empty($data['master_characteristic_field'])) {
$indicators[] = 'Master Characteristic Field: '.$data['master_characteristic_field'];
}
if (! empty($data['approver_status'])) {
$indicators[] = 'Approver Status: '.$data['approver_status'];
}
if (! empty($data['approver_status1'])) {
$indicators[] = 'Approver Status 1: '.$data['approver_status1'];
}
if (! empty($data['approver_status2'])) {
$indicators[] = 'Approver Status 2: '.$data['approver_status2'];
}
if (! empty($data['approver_status3'])) {
$indicators[] = 'Approver Status 3: '.$data['approver_status3'];
}
if (! empty($data['created_from'])) { if (! empty($data['created_from'])) {
$indicators[] = 'From: '.$data['created_from']; $indicators[] = 'From: '.$data['created_from'];
} }
@@ -1256,13 +1491,13 @@ class RequestCharacteristicResource extends Resource
]), ]),
]) ])
->headerActions([ ->headerActions([
// ImportAction::make() ImportAction::make()
// ->label('Import Request Characteristics') ->label('Import Request Characteristics')
// ->color('warning') ->color('warning')
// ->importer(RequestCharacteristicImporter::class) ->importer(RequestCharacteristicImporter::class)
// ->visible(function () { ->visible(function () {
// return Filament::auth()->user()->can('view import request characteristic'); return Filament::auth()->user()->can('view import request characteristic');
// }), }),
ExportAction::make() ExportAction::make()
->label('Export Request Characteristics') ->label('Export Request Characteristics')
->color('warning') ->color('warning')