Added logic in guard patrol entry page
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 17s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 17s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 21s
Laravel Pint / pint (pull_request) Successful in 1m59s
Laravel Larastan / larastan (pull_request) Failing after 4m58s

This commit is contained in:
dhanabalan
2026-06-18 15:00:11 +05:30
parent 687f4367c4
commit 82cfd81a8a
2 changed files with 207 additions and 65 deletions

View File

@@ -3,6 +3,10 @@
namespace App\Filament\Resources\GuardPatrolEntryResource\Pages;
use App\Filament\Resources\GuardPatrolEntryResource;
use App\Models\CheckPointName;
use App\Models\CheckPointTime;
use App\Models\GuardName;
use App\Models\GuardPatrolEntry;
use Filament\Actions;
use Filament\Facades\Filament;
use Filament\Notifications\Notification;
@@ -29,6 +33,100 @@ class CreateGuardPatrolEntry extends CreateRecord
// public ?array $data = null;
protected function mutateFormDataBeforeCreate(array $data): array
{
$guardId = GuardName::where(
'name',
Filament::auth()->user()?->name
)->value('id');
if (! $guardId) {
Notification::make()
->title('Guard Name Not Matched')
->body('Logged-in user name was not found in Guard Name Master.')
->danger()
->send();
$this->halt();
}
$data['guard_name_id'] = $guardId;
$checkPoint = CheckPointName::where('plant_id', $data['plant_id'])
->where('name', trim($data['check_point_name']))
->value('id');
if (! $checkPoint) {
Notification::make()
->title('Invalid Check Point')
->body('The entered check point name does not exist.')
->danger()
->send();
$this->halt();
}
// $lastScan = GuardPatrolEntry::where('plant_id', $data['plant_id'])
// ->where('guard_name_id', $guardId)
// ->latest('id')
// ->first();
// if ($lastScan) {
// $previousPoint = $lastScan->check_point_name_id;
// $route = CheckPointTime::where('plant_id', $data['plant_id'])
// ->where('check_point1_id', $previousPoint)
// ->where('check_point2_id', $checkPoint->id)
// ->first();
// if (! $route) {
// Notification::make()
// ->title('Wrong Check Point Order')
// ->body('This checkpoint is not the next allowed point.')
// ->danger()
// ->send();
// $this->halt();
// }
// } else {
// // First scan must start from sequence 1
// $firstRoute = CheckPointTime::where('plant_id', $data['plant_id'])
// ->where('check_point2_id', $checkPoint->id)
// ->where('sequence_number', 1)
// ->first();
// if (! $firstRoute) {
// Notification::make()
// ->title('Invalid Starting Point')
// ->body('Patrol must start from the first checkpoint.')
// ->danger()
// ->send();
// $this->halt();
// }
// }
$data['check_point_name_id'] = $checkPoint;
unset($data['check_point_name']);
return $data;
}
public function processCheckPointName()
{