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
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
This commit is contained in:
@@ -3,12 +3,14 @@
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Exports\RequestCharacteristicExporter;
|
||||
use App\Filament\Imports\RequestCharacteristicImporter;
|
||||
use App\Filament\Resources\RequestCharacteristicResource\Pages;
|
||||
use App\Models\CharacteristicApproverMaster;
|
||||
use App\Models\Item;
|
||||
use App\Models\Machine;
|
||||
use App\Models\Plant;
|
||||
use App\Models\RequestCharacteristic;
|
||||
use App\Models\StickerMaster;
|
||||
use Closure;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
@@ -19,6 +21,7 @@ use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Forms\Set;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
@@ -27,6 +30,7 @@ use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
@@ -128,6 +132,16 @@ class RequestCharacteristicResource extends Resource
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->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')
|
||||
->label('Work Flow ID')
|
||||
->readOnly()
|
||||
@@ -139,7 +153,42 @@ class RequestCharacteristicResource extends Resource
|
||||
return self::isNewWorkFlow($get);
|
||||
}
|
||||
$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) {
|
||||
// return Rule::unique('request_characteristics', 'work_flow_id')
|
||||
// ->where('plant_id', $get('plant_id'))
|
||||
@@ -312,7 +361,7 @@ class RequestCharacteristicResource extends Resource
|
||||
Forms\Components\Select::make('characteristic_approver_master_id')
|
||||
->label('Master Characteristic Field')
|
||||
// ->relationship('characteristicApproverMaster', 'characteristic_field')
|
||||
->columnSpan(2)
|
||||
// ->columnSpan(2)
|
||||
->reactive()
|
||||
->nullable()
|
||||
->searchable()
|
||||
@@ -340,6 +389,17 @@ class RequestCharacteristicResource extends Resource
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
})
|
||||
->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))
|
||||
Section::make('Request Characteristic Details')
|
||||
// ->columnSpan(['default' => 2, 'sm' => 4])
|
||||
@@ -500,6 +560,7 @@ class RequestCharacteristicResource extends Resource
|
||||
Forms\Components\TextInput::make('approver_remark1')
|
||||
->label('Approver Remark')
|
||||
->live()
|
||||
->maxLength(60)
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$appStat = $get('approver_status1');
|
||||
if ($appStat && $state) {
|
||||
@@ -615,6 +676,7 @@ class RequestCharacteristicResource extends Resource
|
||||
Forms\Components\TextInput::make('approver_remark2')
|
||||
->label('Approver Remark')
|
||||
->live()
|
||||
->maxLength(60)
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$appStat = $get('approver_status2');
|
||||
if ($appStat && $state) {
|
||||
@@ -727,6 +789,7 @@ class RequestCharacteristicResource extends Resource
|
||||
Forms\Components\TextInput::make('approver_remark3')
|
||||
->label('Approver Remark')
|
||||
->live()
|
||||
->maxLength(60)
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$appStat = $get('approver_status3');
|
||||
if ($appStat && $state) {
|
||||
@@ -916,6 +979,11 @@ class RequestCharacteristicResource extends Resource
|
||||
->formatStateUsing(fn (string $state): string => strtoupper(__($state)))
|
||||
->extraAttributes(['class' => 'uppercase'])
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('model_type')
|
||||
->label('Model Type')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('characteristic_name')
|
||||
->label('Characteristic Name')
|
||||
->default('-')
|
||||
@@ -956,12 +1024,14 @@ class RequestCharacteristicResource extends Resource
|
||||
default => 'gray',
|
||||
})
|
||||
->alignCenter()
|
||||
->default('-')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('approver_remark1')
|
||||
->label('Approver Remark 1')
|
||||
// ->color('success')
|
||||
->alignCenter()
|
||||
->default('-')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('approved1_at')
|
||||
@@ -984,12 +1054,14 @@ class RequestCharacteristicResource extends Resource
|
||||
default => 'gray',
|
||||
})
|
||||
->alignCenter()
|
||||
->default('-')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('approver_remark2')
|
||||
->label('Approver Remark 2')
|
||||
// ->color('success')
|
||||
->alignCenter()
|
||||
->default('-')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('approved2_at')
|
||||
@@ -1012,12 +1084,14 @@ class RequestCharacteristicResource extends Resource
|
||||
default => 'gray',
|
||||
})
|
||||
->alignCenter()
|
||||
->default('-')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('approver_remark3')
|
||||
->label('Approver Remark 3')
|
||||
// ->color('success')
|
||||
->alignCenter()
|
||||
->default('-')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('approved3_at')
|
||||
@@ -1160,6 +1234,67 @@ class RequestCharacteristicResource extends Resource
|
||||
->numeric()
|
||||
->minlength(7)
|
||||
->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')
|
||||
->label('Created From')
|
||||
->placeholder('Select From DateTime')
|
||||
@@ -1173,7 +1308,7 @@ class RequestCharacteristicResource extends Resource
|
||||
])
|
||||
->query(function ($query, array $data) {
|
||||
// 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');
|
||||
}
|
||||
|
||||
@@ -1199,6 +1334,70 @@ class RequestCharacteristicResource extends Resource
|
||||
$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'])) {
|
||||
$query->where('created_at', '>=', $data['created_from']);
|
||||
}
|
||||
@@ -1232,6 +1431,42 @@ class RequestCharacteristicResource extends Resource
|
||||
$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'])) {
|
||||
$indicators[] = 'From: '.$data['created_from'];
|
||||
}
|
||||
@@ -1256,13 +1491,13 @@ class RequestCharacteristicResource extends Resource
|
||||
]),
|
||||
])
|
||||
->headerActions([
|
||||
// ImportAction::make()
|
||||
// ->label('Import Request Characteristics')
|
||||
// ->color('warning')
|
||||
// ->importer(RequestCharacteristicImporter::class)
|
||||
// ->visible(function () {
|
||||
// return Filament::auth()->user()->can('view import request characteristic');
|
||||
// }),
|
||||
ImportAction::make()
|
||||
->label('Import Request Characteristics')
|
||||
->color('warning')
|
||||
->importer(RequestCharacteristicImporter::class)
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view import request characteristic');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->label('Export Request Characteristics')
|
||||
->color('warning')
|
||||
|
||||
Reference in New Issue
Block a user