From d6c7e437156ea6a3c39d1db6f39357e902c2023d Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Sat, 29 Nov 2025 12:21:17 +0530 Subject: [PATCH] Updated sfg_number validations as optional and check duplcate only if it exist --- app/Http/Controllers/PdfController.php | 43 ++++++++++++++------------ 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/app/Http/Controllers/PdfController.php b/app/Http/Controllers/PdfController.php index 6efa1347a..ce1cd1e20 100644 --- a/app/Http/Controllers/PdfController.php +++ b/app/Http/Controllers/PdfController.php @@ -633,8 +633,9 @@ class PdfController extends Controller $plantCode = $request->header('plant-code'); $processOrder = $request->header('process-order'); + $data = $request->all(); - Log::info('Process Order POST API >>', ['plant-code' => $plantCode, 'process-order' => $processOrder, 'post-data' => $request->all()]); + Log::info('Process Order POST API >>', ['plant-code' => $plantCode, 'process-order' => $processOrder, 'post-data' => $data]); if ($plantCode == null || $plantCode == '' || ! $plantCode) { return response()->json([ @@ -665,8 +666,6 @@ class PdfController extends Controller $plantId = $plant->id; - $data = $request->all(); - $itemCode = $data['item_code'] ?? ''; $coilNo = $data['coil_number'] ?? ''; $orderQty = $data['order_quantity'] ?? 0; @@ -714,12 +713,12 @@ class PdfController extends Controller ], 404); } - if ($sfgNo == null || $sfgNo == '' || ! $sfgNo) { - return response()->json([ - 'status_code' => 'ERROR', - 'status_description' => "SFG number can't be empty!", - ], 404); - } + // if ($sfgNo == null || $sfgNo == '' || ! $sfgNo) { + // return response()->json([ + // 'status_code' => 'ERROR', + // 'status_description' => "SFG number can't be empty!", + // ], 404); + // } if ($machineId == null || $machineId == '' || ! $machineId) { return response()->json([ @@ -778,19 +777,23 @@ class PdfController extends Controller ], 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; + if ($sfgNo != null && $sfgNo != '' && Str::length($sfgNo) > 0 && $sfgNo) { + $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); + } + } else { + $sfgNo = null; + } + $existing = ProcessOrder::where('plant_id', $plantId) ->where('process_order', $processOrder) ->where('item_id', '!=', $itemId)