diff --git a/app/Http/Controllers/StickerMasterController.php b/app/Http/Controllers/StickerMasterController.php index 51cabf25..f199078b 100644 --- a/app/Http/Controllers/StickerMasterController.php +++ b/app/Http/Controllers/StickerMasterController.php @@ -175,7 +175,7 @@ class StickerMasterController extends Controller $plantCode = $request->header('plant-code'); $itemCode = $request->header('item-code'); - if ($plantCode == null || $plantCode == '') { + if ($plantCode == null || $plantCode == '' || ! $plantCode) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Plant code can't be empty!", @@ -183,28 +183,38 @@ class StickerMasterController extends Controller } elseif (! is_numeric($plantCode)) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => 'Plant code should contain only numeric values!', + '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 must be between 4 and 7 digits only!', + '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 found!', + 'status_description' => "Invalid plant code '{$plantCode}' found!", ], 400); - } elseif ($itemCode == null || $itemCode == '') { + } elseif ($itemCode == null || $itemCode == '' || ! $itemCode) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Item Code can't be empty!", - ], 400); - } elseif (Str::length($itemCode) < 6 || ! ctype_alnum($itemCode)) { + 'status_description' => "Item code can't be empty!", + ], 404); + } elseif (Str::length($itemCode) < 6) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => 'Invalid item code found!', - ], 400); + 'status_description' => "Item code '{$itemCode}' should contain minimum 6 digits!", + ], 404); + } elseif (! ctype_alnum($itemCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' should contain only alpha-numeric values!", + ], 404); + } elseif (! preg_match('/^[a-zA-Z1-9][a-zA-Z0-9]{5,}$/', $itemCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' should not begin with '0'!", + ], 404); } $plant = Plant::where('code', $plantCode)->first(); @@ -212,18 +222,17 @@ class StickerMasterController extends Controller if (! $plant) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => 'Plant Code not found!', + 'status_description' => "Plant code '{$plantCode}' not found in plants table!", ], 400); } $plantId = $plant->id; $item = Item::where('code', $itemCode)->first(); - if (! $item) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => 'Item Code not found in item table!', + 'status_description' => "Item code '{$itemCode}' not found in items table!", ], 404); } @@ -232,7 +241,7 @@ class StickerMasterController extends Controller if (! $item) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Item Code not found for the plant : '$plant->name' in item table!", + 'status_description' => "Item code '{$itemCode}' not found for the plant code '{$plantCode}' in items table!", ], 404); } @@ -249,7 +258,7 @@ class StickerMasterController extends Controller if (! $stickerMaster) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => 'Item Code not found in sticker master table!', + 'status_description' => "Item code '{$itemCode}' not found in sticker master table!", ], 404); }