Merge pull request 'Updated error response codes in updateGR and related methods to return 404 for various validation errors and Added sfg_number duplicate warning' (#13) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 11s

Reviewed-on: #13
This commit was merged in pull request #13.
This commit is contained in:
2025-11-27 03:08:14 +00:00

View File

@@ -35,7 +35,7 @@ class PdfController extends Controller
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Invalid authorization token!', 'status_description' => 'Invalid authorization token!',
], 403); ], 404);
} }
$data = $request->all(); $data = $request->all();
@@ -46,12 +46,12 @@ class PdfController extends Controller
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Plant code can't be empty!", 'status_description' => "Plant code can't be empty!",
], 400); ], 404);
} elseif (Str::length($data['plant_code']) < 4 || ! is_numeric($data['plant_code']) || ! preg_match('/^[1-9]\d{3,}$/', $data['plant_code'])) {// !ctype_digit($data['plant_code']) } elseif (Str::length($data['plant_code']) < 4 || ! is_numeric($data['plant_code']) || ! preg_match('/^[1-9]\d{3,}$/', $data['plant_code'])) {// !ctype_digit($data['plant_code'])
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Invalid plant code found!', 'status_description' => 'Invalid plant code found!',
], 400); ], 404);
} }
$plant = Plant::where('code', $data['plant_code'])->first(); $plant = Plant::where('code', $data['plant_code'])->first();
@@ -59,7 +59,7 @@ class PdfController extends Controller
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Plant not found!', 'status_description' => 'Plant not found!',
], 400); ], 404);
} }
$plantId = $plant->id; $plantId = $plant->id;
@@ -67,7 +67,7 @@ class PdfController extends Controller
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "GR Number can't be empty!", 'status_description' => "GR Number can't be empty!",
], 400); ], 404);
} }
$grExists = GRMaster::where('plant_id', $plantId) $grExists = GRMaster::where('plant_id', $plantId)
@@ -87,7 +87,7 @@ class PdfController extends Controller
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Scanned by can't be empty!", 'status_description' => "Scanned by can't be empty!",
], 400); ], 404);
} }
$user = User::where('name', $data['scanned_by']) $user = User::where('name', $data['scanned_by'])
@@ -109,7 +109,7 @@ class PdfController extends Controller
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Duplicate item codes found in request!', 'status_description' => 'Duplicate item codes found in request!',
'duplicate_item_codes' => array_values($duplicateItemCodes), 'duplicate_item_codes' => array_values($duplicateItemCodes),
], 400); ], 404);
} }
$allSerials = []; $allSerials = [];
@@ -129,7 +129,7 @@ class PdfController extends Controller
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Duplicate serial numbers found in request!', 'status_description' => 'Duplicate serial numbers found in request!',
'duplicate_serial_numbers' => array_values($duplicateSerials), 'duplicate_serial_numbers' => array_values($duplicateSerials),
], 400); ], 404);
} }
$invalidLengthItemCodes = []; $invalidLengthItemCodes = [];
@@ -152,7 +152,7 @@ class PdfController extends Controller
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Some item codes are invalid: must be at least 6 digits!', 'status_description' => 'Some item codes are invalid: must be at least 6 digits!',
'invalid_item_codes' => array_values($invalidLengthItemCodes), 'invalid_item_codes' => array_values($invalidLengthItemCodes),
], 400); ], 404);
} }
$invalidItemCodes = []; $invalidItemCodes = [];
@@ -187,7 +187,7 @@ class PdfController extends Controller
'status_description' => 'Some item codes are invalid!', 'status_description' => 'Some item codes are invalid!',
'not_found_items' => array_values($invalidItemCodes), 'not_found_items' => array_values($invalidItemCodes),
'not_in_plant' => array_values($invalidPlantItems), 'not_in_plant' => array_values($invalidPlantItems),
], 400); ], 404);
} }
$missingSerialsByItem = []; $missingSerialsByItem = [];
@@ -226,7 +226,7 @@ class PdfController extends Controller
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Some serial numbers not found in DB for given plant, GR number, and item!', 'status_description' => 'Some serial numbers not found in DB for given plant, GR number, and item!',
'missing_serials' => $missingSerialsByItem, 'missing_serials' => $missingSerialsByItem,
], 400); ], 404);
} }
$alreadyCompleted = []; $alreadyCompleted = [];
@@ -259,7 +259,7 @@ class PdfController extends Controller
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Below serial numbers are already completed', 'status_description' => 'Below serial numbers are already completed',
'serial_numbers' => $alreadyCompleted, 'serial_numbers' => $alreadyCompleted,
], 400); ], 404);
} }
// { // {
// $itemCode = $item['item_code']; // $itemCode = $item['item_code'];
@@ -270,7 +270,7 @@ class PdfController extends Controller
// return response()->json([ // return response()->json([
// 'status_code' => 'ERROR', // 'status_code' => 'ERROR',
// 'status_description' => "Item code: $itemCode not found" // 'status_description' => "Item code: $itemCode not found"
// ], 400); // ], 404);
// } // }
// $itemPlant = Item::where('plant_id', $plantId) // $itemPlant = Item::where('plant_id', $plantId)
@@ -279,7 +279,7 @@ class PdfController extends Controller
// return response()->json([ // return response()->json([
// 'status_code' => 'ERROR', // 'status_code' => 'ERROR',
// 'status_description' => "Item code: $itemCode not found for the plant: $data[plant_code]" // 'status_description' => "Item code: $itemCode not found for the plant: $data[plant_code]"
// ], 400); // ], 404);
// } // }
// $itemId = $itemObj->id; // $itemId = $itemObj->id;
@@ -330,13 +330,13 @@ class PdfController extends Controller
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Invalid authorization token!', 'status_description' => 'Invalid authorization token!',
], 403); ], 404);
} }
$filename = $request->header('process-order'); $filename = $request->header('process-order');
if (! $filename) { if (! $filename) {
return response()->json(['error' => 'Missing file-name header'], 400); return response()->json(['error' => 'Missing file-name header'], 404);
} }
$filename = basename($filename); $filename = basename($filename);
@@ -377,7 +377,7 @@ class PdfController extends Controller
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Invalid authorization token!', 'status_description' => 'Invalid authorization token!',
], 403); ], 404);
} }
$filename = $request->header('gr-number'); $filename = $request->header('gr-number');
@@ -386,8 +386,8 @@ class PdfController extends Controller
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Gr Number cannot be empty!', 'status_description' => 'Gr Number cannot be empty!',
], 403); ], 404);
// return response()->json(['error' => 'Missing file-name header'], 400); // return response()->json(['error' => 'Missing file-name header'], 404);
} }
$filename = basename($filename); $filename = basename($filename);
@@ -404,7 +404,7 @@ class PdfController extends Controller
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Pdf File not found for the provided GrNumber!', 'status_description' => 'Pdf File not found for the provided GrNumber!',
], 403); ], 404);
} }
$file = Storage::disk('local')->get($filePath); $file = Storage::disk('local')->get($filePath);
@@ -428,7 +428,7 @@ class PdfController extends Controller
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Invalid authorization token!', 'status_description' => 'Invalid authorization token!',
], 403); ], 404);
} }
$plantCode = $request->header('plant-code'); $plantCode = $request->header('plant-code');
@@ -444,7 +444,7 @@ class PdfController extends Controller
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'GR Number cannot be empty!', 'status_description' => 'GR Number cannot be empty!',
], 403); ], 404);
} }
$plant = Plant::where('code', $plantCode)->first(); $plant = Plant::where('code', $plantCode)->first();
@@ -526,7 +526,7 @@ class PdfController extends Controller
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Invalid authorization token!', 'status_description' => 'Invalid authorization token!',
], 403); ], 404);
} }
$plantCode = $request->header('plant-code'); $plantCode = $request->header('plant-code');
@@ -542,7 +542,7 @@ class PdfController extends Controller
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Process Order cannot be empty!', 'status_description' => 'Process Order cannot be empty!',
], 403); ], 404);
} }
$plant = Plant::where('code', $plantCode)->first(); $plant = Plant::where('code', $plantCode)->first();
@@ -596,14 +596,14 @@ class PdfController extends Controller
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Process order '{$processOrder}' for plant '{$plantCode}' has already reached its order quantity.", 'status_description' => "Process order '{$processOrder}' for plant '{$plantCode}' has already reached its order quantity.",
], 400); ], 404);
} }
// if ($totalReceivedQty > $proOrdAgPlant->order_quantity) { // if ($totalReceivedQty > $proOrdAgPlant->order_quantity) {
// return response()->json([ // return response()->json([
// 'status_code' => 'ERROR', // 'status_code' => 'ERROR',
// 'status_description' => "Process order '{$processOrder}' for plant '{$plantCode}' received quantity is more than its order quantity." // 'status_description' => "Process order '{$processOrder}' for plant '{$plantCode}' received quantity is more than its order quantity."
// ], 400); // ], 404);
// } // }
return response()->json([ return response()->json([
@@ -628,7 +628,7 @@ class PdfController extends Controller
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Invalid authorization token!', 'status_description' => 'Invalid authorization token!',
], 403); ], 404);
} }
Log::info('Process Order POST API called >>', ['request_data' => $request->all()]); Log::info('Process Order POST API called >>', ['request_data' => $request->all()]);
@@ -640,19 +640,19 @@ class PdfController extends Controller
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Plant code can't be empty!", 'status_description' => "Plant code can't be empty!",
], 400); ], 404);
} elseif (! is_numeric($plantCode) || Str::length($plantCode) < 4 || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) { // !ctype_digit($data['plant_code']) } elseif (! is_numeric($plantCode) || Str::length($plantCode) < 4 || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) { // !ctype_digit($data['plant_code'])
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Invalid plant code found!', 'status_description' => 'Invalid plant code found!',
], 400); ], 404);
} }
if (! $processOrder) { if (! $processOrder) {
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Process-order are required!', 'status_description' => 'Process-order are required!',
], 400); ], 404);
} }
$plant = Plant::where('code', $plantCode)->first(); $plant = Plant::where('code', $plantCode)->first();
@@ -745,17 +745,17 @@ class PdfController extends Controller
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "User name '{$createdBy}' not found!", 'status_description' => "User name '{$createdBy}' not found!",
], 403); ], 404);
} elseif (! $userPlant && ! $user->hasRole('Super Admin')) { } elseif (! $userPlant && ! $user->hasRole('Super Admin')) {
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "User name '{$createdBy}' not found for the plant code '{$plantCode}'!", 'status_description' => "User name '{$createdBy}' not found for the plant code '{$plantCode}'!",
], 403); ], 404);
} elseif (! $user->hasRole('Super Admin') && ! $user->hasRole('Process Employee') && ! $user->hasRole('Process Supervisor')) { } elseif (! $user->hasRole('Super Admin') && ! $user->hasRole('Process Employee') && ! $user->hasRole('Process Supervisor')) {
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'User does not have rights!', 'status_description' => 'User does not have rights!',
], 403); ], 404);
} }
$item = Item::where('code', $itemCode)->first(); $item = Item::where('code', $itemCode)->first();
@@ -778,6 +778,17 @@ class PdfController extends Controller
], 404); ], 404);
} }
$existing = ProcessOrder::where('plant_id', $plantId)
->where('sfg_number', $sfgNo)
->first();
if ($existing) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "SFG number '{$sfgNo}' already exist for the plant code '{$plantCode}'!",
], 404);
}
$itemId = $itemPlant->id; $itemId = $itemPlant->id;
$existing = ProcessOrder::where('plant_id', $plantId) $existing = ProcessOrder::where('plant_id', $plantId)
@@ -789,7 +800,7 @@ class PdfController extends Controller
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Process order '{$processOrder}' already has item_code '{$existing->item->code}' for the plant code '{$plantCode}'!", 'status_description' => "Process order '{$processOrder}' already has item_code '{$existing->item->code}' for the plant code '{$plantCode}'!",
], 409); ], 404);
} }
$existing = ProcessOrder::where('plant_id', $plantId) $existing = ProcessOrder::where('plant_id', $plantId)
@@ -801,7 +812,7 @@ class PdfController extends Controller
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Process order '{$processOrder}' with coil number '{$coilNo}' already exist for the plant code '{$plantCode}'!", 'status_description' => "Process order '{$processOrder}' with coil number '{$coilNo}' already exist for the plant code '{$plantCode}'!",
], 409); ], 404);
} }
$alreadyReceived = ProcessOrder::where('plant_id', $plantId) $alreadyReceived = ProcessOrder::where('plant_id', $plantId)