From ff6713e1d6c068cfc3cc202a7877f9ed67734871 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Sat, 4 Apr 2026 21:40:41 +0530 Subject: [PATCH] Updated role from Design to Laser and hasWorkFlowId updated against work flow status --- .../Controllers/CharacteristicsController.php | 225 ++++++++++++++++-- 1 file changed, 203 insertions(+), 22 deletions(-) diff --git a/app/Http/Controllers/CharacteristicsController.php b/app/Http/Controllers/CharacteristicsController.php index 10c4bee..c36c053 100644 --- a/app/Http/Controllers/CharacteristicsController.php +++ b/app/Http/Controllers/CharacteristicsController.php @@ -14,7 +14,6 @@ use App\Models\RequestCharacteristic; use App\Models\StickerMaster; use App\Models\User; use App\Models\WorkGroupMaster; -use Filament\Facades\Filament; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Response; @@ -326,7 +325,7 @@ class CharacteristicsController extends Controller 'status_code' => 'ERROR', 'status_description' => "User name '{$userName}' not found for the plant code '{$plantCode}'!", ], 403); - } elseif (! $user->hasRole(['Super Admin', 'Design Manager', 'Design Supervisor', 'Design Employee'])) { + } elseif (! $user->hasRole(['Super Admin', 'Laser Manager', 'Laser Supervisor', 'Laser Employee'])) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'User does not have rights!', @@ -638,7 +637,7 @@ class CharacteristicsController extends Controller if (! $userPlant && ! $user->hasRole('Super Admin')) { $missingUsersPlant[$field] = $markUser; - } elseif (! $user->hasRole(['Super Admin', 'Design Manager', 'Design Supervisor', 'Design Employee'])) { + } elseif (! $user->hasRole(['Super Admin', 'Laser Manager', 'Laser Supervisor', 'Laser Employee'])) { $missingUsersRight[$field] = $markUser; } } @@ -1171,7 +1170,7 @@ class CharacteristicsController extends Controller 'status_code' => 'ERROR', 'status_description' => "User '{$userName}' not found for Plant '{$plantCode}'!", ], 403); - } elseif (! $user->hasRole(['Super Admin', 'Design Manager', 'Design Supervisor', 'Design Employee'])) { + } elseif (! $user->hasRole(['Super Admin', 'Laser Manager', 'Laser Supervisor', 'Laser Employee'])) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'User does not have rights!', @@ -1345,7 +1344,7 @@ class CharacteristicsController extends Controller if (! $userPlant && ! $user->hasRole('Super Admin')) { $missingUsersPlant[$field] = $markUser; - } elseif (! $user->hasRole(['Super Admin', 'Design Manager', 'Design Supervisor', 'Design Employee'])) { + } elseif (! $user->hasRole(['Super Admin', 'Laser Manager', 'Laser Supervisor', 'Laser Employee'])) { $missingUsersRight[$field] = $markUser; } } @@ -1640,7 +1639,7 @@ class CharacteristicsController extends Controller if (! $userPlant && ! $user->hasRole('Super Admin')) { $missingUsersPlant[$field] = $markUser; - } elseif (! $user->hasRole(['Super Admin', 'Design Manager', 'Design Supervisor', 'Design Employee'])) { + } elseif (! $user->hasRole(['Super Admin', 'Laser Manager', 'Laser Supervisor', 'Laser Employee'])) { $missingUsersRight[$field] = $markUser; } } @@ -1929,7 +1928,7 @@ class CharacteristicsController extends Controller 'status_code' => 'ERROR', 'status_description' => 'User name not found for the plant!', ], 403); - } elseif (! $user->hasRole(['Super Admin', 'Design Manager', 'Design Supervisor', 'Design Employee'])) { + } elseif (! $user->hasRole(['Super Admin', 'Laser Manager', 'Laser Supervisor', 'Laser Employee'])) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'User does not have rights!', @@ -2435,7 +2434,7 @@ class CharacteristicsController extends Controller 'status_code' => 'ERROR', 'status_description' => 'User Name not found for the plant!', ], 403); - } elseif (! $user->hasRole(['Super Admin', 'Design Manager', 'Design Supervisor', 'Design Employee'])) { + } elseif (! $user->hasRole(['Super Admin', 'Laser Manager', 'Laser Supervisor', 'Laser Employee'])) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'User does not have rights!', @@ -3446,7 +3445,7 @@ class CharacteristicsController extends Controller 'status_code' => 'ERROR', 'status_description' => "User name '{$userName}' not found for the plant code '{$plantCode}'!", ], 403); - } elseif (! $user->hasRole(['Super Admin', 'Design Manager', 'Design Supervisor', 'Design Employee'])) { + } elseif (! $user->hasRole(['Super Admin', 'Laser Manager', 'Laser Supervisor', 'Laser Employee'])) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'User does not have rights!', @@ -3593,7 +3592,137 @@ class CharacteristicsController extends Controller ], 404); } - // ..Both Has Pending and Completed Logic + // ..completed Logic and pending logic for characteristics and quality + + $classRow = ClassCharacteristic::where('plant_id', $plantId) + ->where('machine_id', $MachineId) + ->where('aufnr', $jobNo) + ->first(); + + if ($classRow) { + if (! empty($characteristics)) { + $requestChars = RequestCharacteristic::where('plant_id', $plantId) + ->where('machine_id', $MachineId) + ->where('aufnr', $jobNo) + ->get(); + + if (! $requestChars->isEmpty()) { + $hasPending = false; + $allApproved = true; + + foreach ($requestChars as $row) { + + $isApproved = ( + $row->approver_status1 == 'Approved' || $row->approver_status1 == 'Rejected' || + $row->approver_status2 == 'Approved' || $row->approver_status2 == 'Rejected' || + $row->approver_status3 == 'Approved' || $row->approver_status2 == 'Rejected' + ); + + $isPending = ! empty($row->mail_status) && + ( + empty($row->approver_status1) || $row->approver_status1 == 'Hold' || + empty($row->approver_status2) || $row->approver_status2 == 'Hold' || + empty($row->approver_status3) || $row->approver_status3 == 'Hold' + ); + + if ($isPending) { + $hasPending = true; + $allApproved = false; + break; + } + + if (! $isApproved) { + $allApproved = false; + } + } + + $current = $classRow->has_work_flow_id ?? '0'; + + if ($hasPending) { + if ($current == '0') { + $newValue = '1'; + } elseif ($current == '1') { + $newValue = '1'; + } elseif ($current == '2') { + $newValue = '3'; + } elseif ($current == '3') { + $newValue = '3'; + } + } elseif ($allApproved) { + if ($current == '0') { + $newValue = '0'; + } elseif ($current == '1') { + $newValue = '0'; + } elseif ($current == '2') { + $newValue = '2'; + } elseif ($current == '3') { + $newValue = '2'; + } + } + + ClassCharacteristic::where('plant_id', $plantId) + ->where('machine_id', $MachineId) + ->where('aufnr', $jobNo) + ->update([ + 'has_work_flow_id' => $newValue, + 'updated_at' => now(), + 'updated_by' => $userName, + ]); + } + } elseif (empty($characteristics)) { + + $requestChar = RequestCharacteristic::where('plant_id', $plantId) + ->where('machine_id', $MachineId) + ->where('aufnr', $jobNo) + ->latest() + ->first(); + + if ($requestChar) { + + $current = $requestChar->has_work_flow_id ?? '0'; + + $isApproved = + $requestChar->approver_status1 == 'Approved' || + $requestChar->approver_status2 == 'Approved' || + $requestChar->approver_status3 == 'Approved'; + + if ($isApproved) { + if ($current == '0') { + $newValue = '0'; + } elseif ($current == '1') { + $newValue = '1'; + } elseif ($current == '2') { + $newValue = '0'; + } elseif ($current == '3') { + $newValue = '1'; + } + } elseif ( + $requestChar->approver_status1 == 'Hold' || $requestChar->approver_status1 == 'Rejected' || $requestChar->approver_status1 == null || $requestChar->approver_status1 == '' || + $requestChar->approver_status2 == 'Hold' || $requestChar->approver_status2 == 'Rejected' || $requestChar->approver_status2 == null || $requestChar->approver_status2 == '' || + $requestChar->approver_status3 == 'Hold' || $requestChar->approver_status3 == 'Rejected' || $requestChar->approver_status3 == null || $requestChar->approver_status3 == '' + ) { + if ($current == '0') { + $newValue = '2'; + } elseif ($current == '1') { + $newValue = '3'; + } elseif ($current == '2') { + $newValue = '2'; + } elseif ($current == '3') { + $newValue = '3'; + } + } + } + + ClassCharacteristic::where('plant_id', $plantId) + ->where('machine_id', $MachineId) + ->where('aufnr', $jobNo) + ->update([ + 'has_work_flow_id' => $newValue, + 'updated_at' => now(), + 'updated_by' => $userName, + ]); + } + } foreach ($characteristics as $char) { $charNameUpp = strtoupper($char['characteristic_name']) ?? null; @@ -3780,11 +3909,15 @@ class CharacteristicsController extends Controller $classChar = ClassCharacteristic::where('plant_id', $plantId)->where('machine_id', $MachineId)->where('aufnr', $jobNo)->first(); - $hasWorkFlowId = $classChar->has_work_flow_id ?? null; + $hasWorkFlowId = $classChar?->has_work_flow_id; $updatedWorkId = null; - if ($hasWorkFlowId != '' || $hasWorkFlowId != null) { + if ($classChar) { + + if ($hasWorkFlowId == '' || $hasWorkFlowId == null) { + $hasWorkFlowId = '0'; + } if ($hasWorkFlowId == '0') { if ($requestType == 'Characteristic') { @@ -3811,16 +3944,16 @@ class CharacteristicsController extends Controller $updatedWorkId = '3'; } } - } - ClassCharacteristic::where('plant_id', $plantId) - ->where('machine_id', $MachineId) - ->where('aufnr', $jobNo) - ->update([ - 'has_work_flow_id' => $updatedWorkId, - 'updated_at' => now(), - 'updated_by' => Filament::auth()->user->name(), - ]); + ClassCharacteristic::where('plant_id', $plantId) + ->where('machine_id', $MachineId) + ->where('aufnr', $jobNo) + ->update([ + 'has_work_flow_id' => $updatedWorkId, + 'updated_at' => now(), + 'updated_by' => $userName, + ]); + } return response()->json([ 'work_flow_ids' => [$workFlowIds], @@ -3947,6 +4080,54 @@ class CharacteristicsController extends Controller ], 404); } + $classChar = ClassCharacteristic::where('plant_id', $plantId)->where('machine_id', $MachineId)->where('aufnr', $jobNo)->latest()->first(); + + $hasWorkFlowId = $classChar?->has_work_flow_id ?? null; + + $updatedWorkId = null; + + if ($classChar) { + + if ($hasWorkFlowId == '' || $hasWorkFlowId == null) { + $hasWorkFlowId = '0'; + } + + if ($hasWorkFlowId == '0') { + if ($requestType == 'Characteristic') { + $updatedWorkId = '1'; + } elseif ($requestType == 'Quality') { + $updatedWorkId = '2'; + } + } elseif ($hasWorkFlowId == '1') { + if ($requestType == 'Characteristic') { + $updatedWorkId = '1'; + } elseif ($requestType == 'Quality') { + $updatedWorkId = '3'; + } + } elseif ($hasWorkFlowId == '2') { + if ($requestType == 'Characteristic') { + $updatedWorkId = '3'; + } elseif ($requestType == 'Quality') { + $updatedWorkId = '2'; + } + } elseif ($hasWorkFlowId == '3') { + if ($requestType == 'Characteristic') { + $updatedWorkId = '3'; + } elseif ($requestType == 'Quality') { + $updatedWorkId = '3'; + } + } + + ClassCharacteristic::where('plant_id', $plantId) + ->where('machine_id', $MachineId) + ->where('aufnr', $jobNo) + ->update([ + 'has_work_flow_id' => $updatedWorkId, + 'updated_at' => now(), + 'updated_by' => $userName, + ]); + } + return response()->json([ 'work_flow_ids' => [$approvalId], ], 200); @@ -4100,7 +4281,7 @@ class CharacteristicsController extends Controller 'status_code' => 'ERROR', 'status_description' => "User name '{$userName}' not found for the plant code '{$plantCode}'!", ], 404); - } elseif (! $user->hasRole(['Super Admin', 'Design Manager', 'Design Supervisor', 'Design Employee'])) { + } elseif (! $user->hasRole(['Super Admin', 'Laser Manager', 'Laser Supervisor', 'Laser Employee'])) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'User does not have rights!',