From 64003ca776ada522254c894e40bc7aeacad0749c Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Sat, 27 Sep 2025 16:51:18 +0530 Subject: [PATCH] Add validation for item codes in updateGR method to ensure they are at least 6 digits and numeric --- app/Http/Controllers/PdfController.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/app/Http/Controllers/PdfController.php b/app/Http/Controllers/PdfController.php index af89740..b077cc3 100644 --- a/app/Http/Controllers/PdfController.php +++ b/app/Http/Controllers/PdfController.php @@ -134,6 +134,30 @@ class PdfController extends Controller ], 400); } + $invalidLengthItemCodes = []; + + foreach ($data['item_codes'] as $item) { + $itemCode = $item['item_code'] ?? null; + + // Skip if item code is missing + if (!$itemCode) { + continue; + } + + // Check if item code is less than 6 digits or not numeric + if (strlen($itemCode) < 6 || !ctype_digit($itemCode)) { + $invalidLengthItemCodes[] = $itemCode; + } + } + if (count($invalidLengthItemCodes) > 0) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Some item codes are invalid: must be at least 6 digits!', + 'invalid_item_codes' => array_values($invalidLengthItemCodes) + ], 400); + } + + $invalidItemCodes = []; $invalidPlantItems = [];