Added logic in create quality validation page
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
Gemini PR Review / Gemini PR Review (pull_request) Successful in 22s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 13s
Laravel Larastan / larastan (pull_request) Failing after 3m20s
Laravel Pint / pint (pull_request) Failing after 3m49s
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
Gemini PR Review / Gemini PR Review (pull_request) Successful in 22s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 13s
Laravel Larastan / larastan (pull_request) Failing after 3m20s
Laravel Pint / pint (pull_request) Failing after 3m49s
This commit is contained in:
@@ -3,22 +3,50 @@
|
|||||||
namespace App\Filament\Resources\QualityValidationResource\Pages;
|
namespace App\Filament\Resources\QualityValidationResource\Pages;
|
||||||
|
|
||||||
use App\Filament\Resources\QualityValidationResource;
|
use App\Filament\Resources\QualityValidationResource;
|
||||||
use App\Models\AlertMailRule;
|
use App\Livewire\ProductionCheckList;
|
||||||
use App\Models\Plant;
|
use App\Models\ProductCharacteristicsMaster;
|
||||||
|
use App\Models\ProductionCharacteristic;
|
||||||
|
use App\Models\QualityValidation;
|
||||||
use Filament\Actions;
|
use Filament\Actions;
|
||||||
use Filament\Forms\Components\Component;
|
use Filament\Forms\Components\Component;
|
||||||
use Filament\Resources\Pages\CreateRecord;
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Filament\Actions\Action;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
|
||||||
class CreateQualityValidation extends CreateRecord
|
class CreateQualityValidation extends CreateRecord
|
||||||
{
|
{
|
||||||
protected static string $resource = QualityValidationResource::class;
|
protected static string $resource = QualityValidationResource::class;
|
||||||
|
public $showChecklist = false;
|
||||||
|
public $checklist;
|
||||||
|
|
||||||
public $plantId;
|
public $skipChecklistValidation = false;
|
||||||
|
|
||||||
|
public bool $shouldSkipChecklist = false;
|
||||||
|
|
||||||
|
public $existingRecords = [];
|
||||||
|
|
||||||
|
protected $listeners = [
|
||||||
|
'checklistUpdated' => 'setChecklist',
|
||||||
|
'checklist-cancelled' => 'handleChecklistCancel',
|
||||||
|
'checklist-saved' => 'checkListSaved',
|
||||||
|
// 'trigger-create' => 'doCreate',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function setChecklist($checklist)
|
||||||
|
{
|
||||||
|
$this->data['checklist'] = $checklist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function doCreate()
|
||||||
|
{
|
||||||
|
$this->create();
|
||||||
|
}
|
||||||
|
|
||||||
public function mount(): void
|
public function mount(): void
|
||||||
{
|
{
|
||||||
parent::mount();
|
parent::mount();
|
||||||
|
|
||||||
session()->forget([
|
session()->forget([
|
||||||
'last_selected_plant_id',
|
'last_selected_plant_id',
|
||||||
'last_selected_line',
|
'last_selected_line',
|
||||||
@@ -26,6 +54,71 @@ class CreateQualityValidation extends CreateRecord
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function handleChecklistCancel()
|
||||||
|
{
|
||||||
|
$this->skipChecklistValidation = true;
|
||||||
|
$this->showChecklist = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function mutateFormDataBeforeCreate(array $data): array
|
||||||
|
{
|
||||||
|
if ($this->shouldSkipChecklist) {
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->checkIfHasCharacteristics($data)) {
|
||||||
|
$this->showChecklist = true;
|
||||||
|
|
||||||
|
$this->halt();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function checkIfHasCharacteristics(array $data)
|
||||||
|
{
|
||||||
|
$plantId = $data['plant_id'] ?? null;
|
||||||
|
$itemCode = $data['item_id'] ?? null;
|
||||||
|
$lineId = $data['line_id'] ?? null;
|
||||||
|
|
||||||
|
if (!$plantId || !$itemCode || !$lineId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$item = \App\Models\Item::where('code', $itemCode)
|
||||||
|
->where('plant_id', $plantId)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$categoryName = trim($item->category) ?? null;
|
||||||
|
|
||||||
|
if (!$item) {
|
||||||
|
$this->existingRecords = collect();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->existingRecords = ProductCharacteristicsMaster::where('plant_id', $plantId)
|
||||||
|
->where('category', $categoryName)
|
||||||
|
->where('line_id', $lineId)
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkListSaved()
|
||||||
|
{
|
||||||
|
$this->showChecklist = false;
|
||||||
|
|
||||||
|
$plantId = $this->data['plant_id'] ?? null;
|
||||||
|
$lineId = $this->data['line_id'] ?? null;
|
||||||
|
$productionOrder = $this->data['production_order'] ?? null;
|
||||||
|
|
||||||
|
return redirect()->to(
|
||||||
|
static::getResource()::getUrl('create', [
|
||||||
|
'plant_id' => $this->data['plant_id'] ?? null,
|
||||||
|
'line_id' => $this->data['line_id'] ?? null,
|
||||||
|
'production_order' => $this->data['production_order'] ?? null,
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected function beforeCreate(): void
|
protected function beforeCreate(): void
|
||||||
{
|
{
|
||||||
$errors = [];
|
$errors = [];
|
||||||
@@ -101,18 +194,84 @@ class CreateQualityValidation extends CreateRecord
|
|||||||
$errors['part_validation5_error'] = ['Fix the errors before submitting.'];
|
$errors['part_validation5_error'] = ['Fix the errors before submitting.'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!empty($errors)) {
|
if (!empty($errors)) {
|
||||||
throw ValidationException::withMessages($errors);
|
throw ValidationException::withMessages($errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->checkExisting();
|
||||||
|
|
||||||
|
$checklist = $this->data['data']['checklist'] ?? [];
|
||||||
|
|
||||||
|
if (count($this->existingRecords) > 0){
|
||||||
|
|
||||||
|
$this->showChecklist = true;
|
||||||
|
$this->halt();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$this->showChecklist = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkExisting()
|
||||||
|
{
|
||||||
|
$plant_id = $this->data['plant_id'] ?? null;
|
||||||
|
$item_code = $this->data['item_id'] ?? null;
|
||||||
|
$line_id = $this->data['line_id'] ?? null;
|
||||||
|
|
||||||
|
|
||||||
|
$item = \App\Models\Item::where('code', $item_code)->where('plant_id', $plant_id)->first();
|
||||||
|
|
||||||
|
if (!$item) {
|
||||||
|
$this->existingRecords = collect();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// $item_id = $item->id;
|
||||||
|
$categoryName = trim($item->category) ?? null;
|
||||||
|
|
||||||
|
$this->existingRecords = ProductCharacteristicsMaster::where('plant_id', $plant_id)
|
||||||
|
->where('category', $categoryName)
|
||||||
|
->where('line_id', $line_id)
|
||||||
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function afterCreate(): void
|
protected function afterCreate(): void
|
||||||
{
|
{
|
||||||
// Get the value from the hidden field 'plant'
|
// Get the value from the hidden field 'plant'
|
||||||
$plant = $this->form->getState()['plant'] ?? null;
|
$plant = $this->form->getState()['plant'] ?? null;
|
||||||
$line = $this->form->getState()['line'] ?? null;
|
$line = $this->form->getState()['line'] ?? null;
|
||||||
$production = $this->form->getState()['production'] ?? null;
|
$production = $this->form->getState()['production'] ?? null;
|
||||||
|
|
||||||
|
// $this->skipChecklistValidation = false;
|
||||||
|
// $this->showChecklist = false;
|
||||||
|
// $this->checklist = [];
|
||||||
|
|
||||||
|
// $this->form->fill();
|
||||||
|
|
||||||
|
// reset checklist
|
||||||
|
$this->checklist = [];
|
||||||
|
|
||||||
|
$this->skipChecklistValidation = false;
|
||||||
|
$this->showChecklist = false;
|
||||||
|
|
||||||
|
$this->form->fill([]);
|
||||||
|
|
||||||
|
$this->data = [];
|
||||||
|
|
||||||
|
$this->resetValidation();
|
||||||
|
$this->resetErrorBag();
|
||||||
|
|
||||||
|
$this->form->fill([
|
||||||
|
'plant_id' => null,
|
||||||
|
'line_id' => null,
|
||||||
|
'production_order' => null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
// $this->dispatch('focus-item-id');
|
||||||
|
session()->flash('focus_item_id_after_redirect', true);
|
||||||
|
logger('Focus flag set in session');
|
||||||
|
|
||||||
if ($plant) {
|
if ($plant) {
|
||||||
session(['last_selected_plant_id' => $plant]);
|
session(['last_selected_plant_id' => $plant]);
|
||||||
}
|
}
|
||||||
@@ -124,13 +283,14 @@ class CreateQualityValidation extends CreateRecord
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function getRedirectUrl(): string
|
protected function getRedirectUrl(): string
|
||||||
{
|
{
|
||||||
//return $this->getResource()::getUrl('create'); // Stay on Create Page after saving
|
//return $this->getResource()::getUrl('create'); // Stay on Create Page after savin
|
||||||
|
|
||||||
return $this->getResource()::getUrl('create', [
|
return $this->getResource()::getUrl('create', [
|
||||||
'plant_id' => $this->data['plant_id'] ?? null,
|
'plant_id' => $this->data['plant_id'] ?? null,
|
||||||
|
'line_id' => $this->data['line_id'] ?? null,
|
||||||
|
'production_order' => $this->data['production_order'] ?? null,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user