diff --git a/app/Http/Controllers/PdfController.php b/app/Http/Controllers/PdfController.php index 7ba6148a..3e3ff151 100644 --- a/app/Http/Controllers/PdfController.php +++ b/app/Http/Controllers/PdfController.php @@ -314,6 +314,78 @@ class PdfController extends Controller } + public function getCoilDetails(Request $request){ + $expectedUser = env('API_AUTH_USER'); + $expectedPw = env('API_AUTH_PW'); + $header_auth = $request->header('Authorization'); + $expectedToken = $expectedUser.':'.$expectedPw; + + if ('Bearer '.$expectedToken != $header_auth) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Invalid authorization token!', + ], 404); + } + + $plantCode = $request->header('plant-code'); + + $processOrder = $request->header('process-order'); + + if (! $plantCode) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Plant Code value can't be empty", + ], 404); + } elseif (! $processOrder) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Process Order cannot be empty!', + ], 404); + } + + if (!str_contains($processOrder, '-')) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Invalid Process Order", + ], 404); + } + + + $plant = Plant::where('code', $plantCode)->first(); + $plantId = $plant->id; + + if (! $plant) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Plant Code '{$plantCode}' not found!", + ], 404); + } + + $parts = explode('-', $processOrder); + $processOrder = $parts[0]; // 261010002154 + $coilNo = $parts[1]; // 001 + + $processOrderExist = ProcessOrder::where('process_order', $processOrder)->where('plant_id', $plantId)->where('coil_number', $coilNo)->first(); + + if ($processOrderExist) { + $itemId = $processOrderExist->item_id; + + $item = Item::where('id', $itemId)->first(); + $itemCode = $item->code; + + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Process order '$processOrder' with coil number '$coilNo' found against item '$itemCode'", + ], 404); + } + else{ + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Process order '$processOrder' with coil number '$coilNo' not found'", + ], 404); + } + } + /** * Store a newly created resource in storage. */