From ece0a9e22646cb7e10b8a166c499d39f260722dd Mon Sep 17 00:00:00 2001 From: dhanabalan Date: Fri, 30 Jan 2026 18:34:05 +0530 Subject: [PATCH] Added validation logic against characteristics approver master --- .../Controllers/CharacteristicsController.php | 94 ++++++++++++++----- 1 file changed, 72 insertions(+), 22 deletions(-) diff --git a/app/Http/Controllers/CharacteristicsController.php b/app/Http/Controllers/CharacteristicsController.php index 1c8182e..0ec7c4a 100644 --- a/app/Http/Controllers/CharacteristicsController.php +++ b/app/Http/Controllers/CharacteristicsController.php @@ -2875,7 +2875,7 @@ class CharacteristicsController extends Controller // $pendingCharacteristics = []; // foreach ($characteristics as $char) { - // $charName = strtolower($char['characteristic_name']) ?? null; + // $charName = strtoupper($char['characteristic_name']) ?? null; // $pendingExists = RequestCharacteristic::where('aufnr', $jobNo) // ->where('characteristic_name', $charName) // ->latest() @@ -2948,7 +2948,7 @@ class CharacteristicsController extends Controller // 'item_id' => $ItemId, // 'characteristic_approver_master_id' => $charId, // 'aufnr' => $jobNo, - // 'characteristic_name' => strtolower($char['characteristic_name']), + // 'characteristic_name' => strtoupper($char['characteristic_name']),//strtolower // 'current_value' => $char['current_value'], // 'update_value' => $char['update_value'], // 'created_by' => $userName, @@ -3037,7 +3037,7 @@ class CharacteristicsController extends Controller } if ($charField == null || $charField == '') { - $charField = 'nil'; + $charField = 'NIL'; } $plant = Plant::where('code', $plantCode)->first(); @@ -3132,6 +3132,24 @@ class CharacteristicsController extends Controller $MachineId = $machineAgaPlant->id; + $iCode = Item::where('code', $itemCode)->first(); + if (! $iCode) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' not found!", + ], 404); + } + + $iCodeAgaPlant = Item::where('code', $itemCode)->where('plant_id', $plantId)->first(); + if (! $iCodeAgaPlant) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' not found for the plant code '{$plantCode}'!", + ], 404); + } + + $ItemId = $iCodeAgaPlant->id; + $pCode = CharacteristicApproverMaster::where('plant_id', $plantId)->first(); if (! $pCode) { return response()->json([ @@ -3172,46 +3190,76 @@ class CharacteristicsController extends Controller ], 404); } - $mNameAgaWorkCenter = CharacteristicApproverMaster::where('machine_name', $machineName)->where('machine_id', $MachineId)->first(); - if (! $mNameAgaWorkCenter) { + $cField = CharacteristicApproverMaster::where('characteristic_field', $charField)->first(); + if (! $cField) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Master characteristic field value '{$charField}' not found in characteristic approver master!", + ], 404); + } + + $cFieldAgaPlant = CharacteristicApproverMaster::where('characteristic_field', $charField)->where('plant_id', $plantId)->first(); + if (! $cFieldAgaPlant) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Master characteristic field value '{$charField}' not found for the plant code '{$plantCode}' in characteristic approver master!", + ], 404); + } + + $mNameAndWorkCenter = CharacteristicApproverMaster::where('machine_name', $machineName)->where('machine_id', $MachineId)->first(); + if (! $mNameAndWorkCenter) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Machine name '{$machineName}' and work center '{$workCenter}' not found in characteristic approver master!", ], 404); } - $mNameAgaWorkCenterForPlant = CharacteristicApproverMaster::where('machine_name', $machineName)->where('machine_id', $MachineId)->where('plant_id', $plantId)->first(); - if (! $mNameAgaWorkCenterForPlant) { + $mNameAndWorkCenterAgaPlant = CharacteristicApproverMaster::where('machine_name', $machineName)->where('machine_id', $MachineId)->where('plant_id', $plantId)->first(); + if (! $mNameAndWorkCenterAgaPlant) { return response()->json([ 'status_code' => 'ERROR', 'status_description' => "Machine name '{$machineName}' and work center '{$workCenter}' not found for the plant code '{$plantCode}' in characteristic approver master!", ], 404); } - $charId = $mNameAgaWorkCenterForPlant->id; - - $iCode = Item::where('code', $itemCode)->first(); - if (! $iCode) { + $cFieldAndWorkCent = CharacteristicApproverMaster::where('characteristic_field', $charField)->where('machine_id', $MachineId)->first(); + if (! $cFieldAndWorkCent) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Item code '{$itemCode}' not found!", + 'status_description' => "Master characteristic field value '{$charField}' not found for the work center '{$workCenter}' in characteristic approver master!", ], 404); } - $iCodeAgaPlant = Item::where('code', $itemCode)->where('plant_id', $plantId)->first(); - if (! $iCodeAgaPlant) { + $cFieldAndWorkCentAgaPlant = CharacteristicApproverMaster::where('characteristic_field', $charField)->where('machine_id', $MachineId)->where('plant_id', $plantId)->first(); + if (! $cFieldAndWorkCentAgaPlant) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => "Item code '{$itemCode}' not found for the plant code '{$plantCode}'!", + 'status_description' => "Master characteristic field value '{$charField}' and work center '{$workCenter}' not found for the plant code '{$plantCode}' in characteristic approver master!", ], 404); } - $ItemId = $iCodeAgaPlant->id; + $cFieldAndMach = CharacteristicApproverMaster::where('characteristic_field', $charField)->where('machine_name', $machineName)->first(); + if (! $cFieldAndMach) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Master characteristic field value '{$charField}' not found for the machine name '{$machineName}' in characteristic approver master!", + ], 404); + } + + $cFieldAndWorkCentAndMachAgaPlant = CharacteristicApproverMaster::where('characteristic_field', $charField)->where('machine_id', $MachineId)->where('machine_name', $machineName)->where('plant_id', $plantId)->first(); + if (! $cFieldAndWorkCentAndMachAgaPlant) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Master characteristic field value '{$charField}', work center '{$workCenter}', and machine name '{$machineName}' not found for the plant code '{$plantCode}' in characteristic approver master!", + ], 404); + } + + $charId = $cFieldAndWorkCentAndMachAgaPlant->id; $pendingCharacteristics = []; foreach ($characteristics as $char) { - $charName = strtolower($char['characteristic_name']) ?? null; + $charName = strtoupper($char['characteristic_name']) ?? null; $pendingExists = RequestCharacteristic::where('plant_id', $plantId)->where('aufnr', $jobNo)->where('characteristic_name', $charName)->latest()->first(); if ($pendingExists) { @@ -3292,7 +3340,7 @@ class CharacteristicsController extends Controller 'item_id' => $ItemId, 'characteristic_approver_master_id' => $charId, 'aufnr' => $jobNo, - 'characteristic_name' => strtolower($char['characteristic_name']), + 'characteristic_name' => strtoupper($char['characteristic_name']), // strtolower 'current_value' => $char['current_value'], 'update_value' => $char['update_value'], 'created_by' => $userName, @@ -3720,6 +3768,8 @@ class CharacteristicsController extends Controller ], 404); } + $workFlowId = strtoupper($workFlowId); + if (! $workFlowId) { $records = RequestCharacteristic::with('approver')->where([ @@ -3782,14 +3832,14 @@ class CharacteristicsController extends Controller ], 404); } - if (! str_ends_with(strtolower($filename), '.pdf')) { - $filename .= '.pdf'; - } + // if (! str_ends_with(strtolower($filename), '.pdf')) { + // $filename .= '.pdf'; + // } if (! Storage::disk('local')->exists($filePath)) { return response()->json([ 'status_code' => 'ERROR', - 'status_description' => 'Pdf File not found for the provided work flow id number!', + 'status_description' => "Pdf File not found for the provided 'Work Flow ID' number!", ], 404); }