Add validation for item codes in updateGR method to ensure they are at least 6 digits and numeric
This commit is contained in:
@@ -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 = [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user