From eb343f1d0ce84b7de5860c246e4b41664a350b92 Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Wed, 28 Jan 2026 16:07:33 +0530 Subject: [PATCH] Updated alignment for controller --- app/Http/Controllers/MachineController.php | 89 +++++++++------------- 1 file changed, 37 insertions(+), 52 deletions(-) diff --git a/app/Http/Controllers/MachineController.php b/app/Http/Controllers/MachineController.php index a7a2b63..69d0fa9 100644 --- a/app/Http/Controllers/MachineController.php +++ b/app/Http/Controllers/MachineController.php @@ -33,29 +33,28 @@ class MachineController extends Controller public function get_all_data(Request $request) { $expectedUser = env('API_AUTH_USER'); - $expectedPw = env('API_AUTH_PW'); - $header_auth = $request->header('Authorization'); - $expectedToken = $expectedUser . ':' . $expectedPw; + $expectedPw = env('API_AUTH_PW'); + $header_auth = $request->header('Authorization'); + $expectedToken = $expectedUser.':'.$expectedPw; - if ("Bearer " . $expectedToken != $header_auth) - { + if ('Bearer '.$expectedToken != $header_auth) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => 'Invalid authorization token!' + 'status_description' => 'Invalid authorization token!', ], 403); } $machines = Machine::with('plant')->with('workGroupMaster')->orderBy('plant_id')->get(); - $machinesData = $machines->map(function($machine) { + $machinesData = $machines->map(function ($machine) { return [ - 'plant_code' => $machine->plant ? (String)$machine->plant->code : "", - 'group_work_center' => $machine->workGroupMaster ? (String)$machine->workGroupMaster->name : "", - 'work_center' => $machine->work_center ?? "", + 'plant_code' => $machine->plant ? (string) $machine->plant->code : '', + 'group_work_center' => $machine->workGroupMaster ? (string) $machine->workGroupMaster->name : '', + 'work_center' => $machine->work_center ?? '', ]; }); return response()->json([ - 'machines' => $machinesData + 'machines' => $machinesData, ]); } @@ -65,80 +64,70 @@ class MachineController extends Controller public function get_data(Request $request) { $expectedUser = env('API_AUTH_USER'); - $expectedPw = env('API_AUTH_PW'); - $header_auth = $request->header('Authorization'); - $expectedToken = $expectedUser . ':' . $expectedPw; + $expectedPw = env('API_AUTH_PW'); + $header_auth = $request->header('Authorization'); + $expectedToken = $expectedUser.':'.$expectedPw; - if ("Bearer " . $expectedToken != $header_auth) - { + if ('Bearer '.$expectedToken != $header_auth) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => 'Invalid authorization token!' + 'status_description' => 'Invalid authorization token!', ], 403); } $plantCode = $request->header('plant-code'); $lineName = $request->header('line-name'); - if ($plantCode == null || $plantCode == '') - { + if ($plantCode == null || $plantCode == '') { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Plant code can't be empty!" + 'status_description' => "Plant code can't be empty!", ], 400); - } - else if (Str::length($plantCode) < 4 || !is_numeric($plantCode) || !preg_match('/^[1-9]\d{3,}$/', $plantCode)) - { + } elseif (Str::length($plantCode) < 4 || ! is_numeric($plantCode) || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Invalid plant code found!" + 'status_description' => 'Invalid plant code found!', ], 400); - } - else if ($lineName == null || $lineName == '' || Str::length($lineName) <= 0) - { + } elseif ($lineName == null || $lineName == '' || Str::length($lineName) <= 0) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Line name can't be empty!" + 'status_description' => "Line name can't be empty!", ], 400); } $plant = Plant::where('code', $plantCode)->first(); - if (!$plant) - { + if (! $plant) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Plant Code '{$plantCode}' not found!" + 'status_description' => "Plant Code '{$plantCode}' not found!", ], 400); } $plantId = $plant->id; $line = Line::where('name', $lineName)->first(); - if (!$line) - { + if (! $line) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Line Name '{$lineName}' not found!" + 'status_description' => "Line Name '{$lineName}' not found!", ], 400); } $line = Line::where('name', $lineName)->where('plant_id', $plantId)->first(); - if (!$line) - { + if (! $line) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Line Name '{$lineName}' not found for the plant!" + 'status_description' => "Line Name '{$lineName}' not found for the plant!", ], 400); } - $lineId = $line->id;//no_of_operation + $lineId = $line->id; // no_of_operation $lineWorkGroup1Id = $line->work_group1_id; $lineWorkGroup2Id = $line->work_group2_id; - if ($line->no_of_operation == null || $line->no_of_operation == '' || $line->no_of_operation == 0 || !is_numeric($line->no_of_operation)) - { + if ($line->no_of_operation == null || $line->no_of_operation == '' || $line->no_of_operation == 0 || ! is_numeric($line->no_of_operation)) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Group work center not found for the plant & line!" + 'status_description' => 'Group work center not found for the plant & line!', ], 400); } @@ -146,26 +135,22 @@ class MachineController extends Controller $lineWorkGroupIds = []; for ($i = 1; $i <= $line->no_of_operation; $i++) { $curWorkGroupId = $line->{"work_group{$i}_id"}; - if (in_array($curWorkGroupId, $lineWorkGroupIds)) - { + if (in_array($curWorkGroupId, $lineWorkGroupIds)) { continue; - } - else - { + } else { $lineWorkGroupIds[] = $curWorkGroupId; } $test[] = [ - 'group_work_center' => WorkGroupMaster::where('id', $curWorkGroupId)->first()->name ?? "", - 'operation_number' => WorkGroupMaster::where('id', $curWorkGroupId)->first()->operation_number ?? "", - 'work_centers' => Machine::where('plant_id', $plantId)->where('work_group_master_id', $curWorkGroupId)->orderBy('work_center')->pluck('work_center')->toArray() ?? [], + 'group_work_center' => WorkGroupMaster::where('id', $curWorkGroupId)->first()->name ?? '', + 'operation_number' => WorkGroupMaster::where('id', $curWorkGroupId)->first()->operation_number ?? '', + 'work_centers' => Machine::where('plant_id', $plantId)->where('work_group_master_id', $curWorkGroupId)->orderBy('work_center')->pluck('work_center')->toArray() ?? [], ]; } - if($lineWorkGroupIds) - { + if ($lineWorkGroupIds) { return response()->json([ - 'machines' => $test + 'machines' => $test, ]); } // $machines = Machine::with('plant')->with('workGroupMaster')->orderBy('plant_id')->get();