header('Authorization'); $expectedToken = 'Bearer '.$expectedUser.':'.$expectedPw; if ($headerAuth != $expectedToken) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => 'Invalid authorization token!', ], 401); } $userName = $request->header('user-name'); $plantCode = $request->header('plant-code'); Log::info('Testing Line Visualization GET API >>', ['user-name' => $userName, 'plant-code' => $plantCode]); if (! $userName || $userName == null || $userName == '') { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "User name can't be empty!", ], 404); } elseif ($userName == 'jothi') { $userName = 'Admin'; } if (! $plantCode || $plantCode == null || $plantCode == '') { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Plant code can't be empty!", ], 404); } elseif (! is_numeric($plantCode)) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Plant code '{$plantCode}' should contain only numeric values!", ], 400); } elseif (Str::length($plantCode) < 4 || Str::length($plantCode) > 7) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Plant code '{$plantCode}' must be between 4 and 7 digits only!", ], 400); } elseif (! preg_match('/^[1-9]\d{3,6}$/', $plantCode)) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Invalid plant code '{$plantCode}' found!", ], 400); } $plant = Plant::where('code', $plantCode)->first(); if (! $plant) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Plant code '{$plantCode}' not found in plants table!", ], 404); } $plantId = $plant->id; $user = User::where('name', $userName)->first(); if (! $user) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "User name '{$userName}' not found in users table!", ], 404); } $userPlant = User::where('name', $userName)->where('plant_id', $plantId)->first(); if (! $userPlant && ! $user->hasRole('Super Admin')) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "User name '{$userName}' not found for the plant code '{$plantCode}' in users table!", ], 404); } elseif (! $user->hasRole(['Super Admin', 'Testing Line Visualization Manager', 'Testing Line Visualization Supervisor', 'Testing Line Visualization Employee'])) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "User '{$userName}' does not have rights!", ], 404); } $jobAgaPlant = TestingLineVisualization::where('plant_id', $plantId)->first(); if (! $jobAgaPlant) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Reports not found for the plant code '{$plantCode}' in testing line visualization table!", ], 404); } $records = TestingLineVisualization::where('plant_id', $plantId)->orderBy('id')->get(); $response = []; foreach ($records as $row) { $response[] = [ 'test_bed_group' => $row->test_bed_group ?? '', 'line_no' => $row->line_no ?? '', 'pump_model' => $row->pump_model ?? '', 'pump_type' => $row->pump_type ?? '', 'motor_details' => $row->motor_details ?? '', 'test_type' => $row->test_type ?? '', 'flow' => $row->flow ?? '', 'head' => $row->head ?? '', 'run_time' => $row->run_time ?? '', 'status' => $row->live_status ?? '', 'observation_remarks' => $row->observation_remarks ?? '', 'created_by' => ($row->created_by == 'Admin') ? 'jothi' : $row->created_by ?? '', 'created_at' => $row->created_at ? $row->created_at->format('Y-m-d H:i:s') : '', 'updated_by' => ($row->updated_by == 'Admin') ? 'jothi' : $row->updated_by ?? '', 'updated_at' => $row->updated_at ? $row->updated_at->format('Y-m-d H:i:s') : '', ]; } return response()->json([ 'testing_line_visualizations' => $response, ], 200); } /** * Update the specified resource in storage. */ public function update(Request $request, string $id) { // } /** * Remove the specified resource from storage. */ public function destroy(string $id) { // } }