Added rework_winded column in Motor Testing Panel Post API and Refactored validations in TestingPanelController
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 15s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 20s
Laravel Pint / pint (pull_request) Successful in 5m26s
Laravel Larastan / larastan (pull_request) Failing after 6m4s

This commit is contained in:
dhanabalan
2026-10-03 18:05:21 +05:30
parent 693a97cf78
commit 393153b898

View File

@@ -48,21 +48,67 @@ class TestingPanelController extends Controller
$data = $request->all();
if ($data['plant_code'] == null || $data['plant_code'] == '') {
// return response("ERROR: Please provide a valid plant code.", 400)
// ->header('Content-Type', 'text/plain');
$plantCode = $data['plant_code'] ?? null;
$groupWorkCenter = $data['line_name'] ?? null;
$workCenter = $data['machine_name'] ?? null;
if ($plantCode == null || $plantCode == '' || ! $plantCode) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Plant code can't be empty!",
], 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'])
], 400);
} elseif (! is_numeric($plantCode)) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => 'Invalid plant code found!',
'status_description' => "Plant code '{$plantCode}' should contain only numeric values!",
], 400);
} elseif (Str::length($plantCode) < 4 || Str::length($plantCode) > 7) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Plant code '{$plantCode}' must be between 4 and 7 digits only!",
], 400);
} elseif (! preg_match('/^[1-9]\d{3,6}$/', $plantCode)) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Invalid plant code '{$plantCode}' found!",
], 400);
}
if ($groupWorkCenter == null || $groupWorkCenter == '' || ! $groupWorkCenter) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Group work center can't be empty!",
], 404);
} elseif (Str::length($groupWorkCenter) < 6) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Group work center '{$groupWorkCenter}' should contain minimum 6 characters!",
], 404);
} elseif (! ctype_alnum($groupWorkCenter)) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Group work center '{$groupWorkCenter}' should contain only alpha-numeric values!",
], 404);
}
$plant = Plant::where('code', $data['plant_code'])->first();
if ($workCenter == null || $workCenter == '' || ! $workCenter) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Work center can't be empty!",
], 404);
} elseif (Str::length($workCenter) < 6) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Work center '{$workCenter}' should contain minimum 6 characters!",
], 404);
} elseif (! ctype_alnum($workCenter)) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Work center '{$workCenter}' should contain only alpha-numeric values!",
], 404);
}
$plant = Plant::where('code', $plantCode)->first();
if (! $plant) {
// return response("Plant not found.", 400)->header('Content-Type', 'text/plain');
return response()->json([
@@ -74,19 +120,7 @@ class TestingPanelController extends Controller
$plantId = $plant->id;
$plantName = $plant->name;
if ($data['line_name'] == null || $data['line_name'] == '') {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Group work center can't be empty!",
], 404);
} elseif (Str::length($data['line_name']) < 0) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => 'Invalid group work center found!',
], 404);
}
$gWorkCenter = WorkGroupMaster::where('name', $data['line_name'])->first();
$gWorkCenter = WorkGroupMaster::where('name', $groupWorkCenter)->first();
if (! $gWorkCenter) {
return response()->json([
'status_code' => 'ERROR',
@@ -94,30 +128,18 @@ class TestingPanelController extends Controller
], 404);
}
$gWorkCenter = WorkGroupMaster::where('name', $data['line_name'])->where('plant_id', $plantId)->first();
$gWorkCenter = WorkGroupMaster::where('name', $groupWorkCenter)->where('plant_id', $plantId)->first();
if (! $gWorkCenter) {
// return response( "Line not found for the specified plant : {$data['plant_code']}",400)->header('Content-Type', 'text/plain');
// return response( "Line not found for the specified plant : {$plantCode}",400)->header('Content-Type', 'text/plain');
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Group work center not found for the specified plant : '{$data['plant_code']}'!",
'status_description' => "Group work center not found for the specified plant : '{$plantCode}'!",
], 404);
}
$gWorkCenterId = $gWorkCenter->id;
if ($data['machine_name'] == null || $data['machine_name'] == '') {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Work center can't be empty!",
], 404);
} elseif (Str::length($data['machine_name']) < 0) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => 'Invalid work center found!',
], 404);
}
$machine = Machine::where('work_center', $data['machine_name'])->first();
$machine = Machine::where('work_center', $workCenter)->first();
if (! $machine) {
return response()->json([
'status_code' => 'ERROR',
@@ -125,29 +147,29 @@ class TestingPanelController extends Controller
], 404);
}
$machine = Machine::where('work_center', $data['machine_name'])->where('plant_id', $plantId)->first();
$machine = Machine::where('work_center', $workCenter)->where('plant_id', $plantId)->first();
if (! $machine) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Work center not found for the specified plant : '{$data['plant_code']}'!",
'status_description' => "Work center not found for the specified plant : '{$plantCode}'!",
], 404);
}
$machine = Machine::where('work_center', $data['machine_name'])->where('work_group_master_id', $gWorkCenterId)->first();
$machine = Machine::where('work_center', $workCenter)->where('work_group_master_id', $gWorkCenterId)->first();
if (! $machine) {
// return response("Machine not found for the specified line : {$data['line_name']}", 400)->header('Content-Type', 'text/plain');
// return response("Machine not found for the specified line : {$groupWorkCenter}", 400)->header('Content-Type', 'text/plain');
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Work center not found for the specified Group work center : '{$data['line_name']}'!",
'status_description' => "Work center not found for the specified Group work center : '{$groupWorkCenter}'!",
], 404);
}
$machine = Machine::where('work_center', $data['machine_name'])->where('plant_id', $plantId)->where('work_group_master_id', $gWorkCenterId)->first();
$machine = Machine::where('work_center', $workCenter)->where('plant_id', $plantId)->where('work_group_master_id', $gWorkCenterId)->first();
if (! $machine) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Work center not found for the specified Plant : '{$data['plant_code']}' and Group work center : '{$data['line_name']}'!",
'status_description' => "Work center not found for the specified Plant : '{$plantCode}' and Group work center : '{$groupWorkCenter}'!",
], 404);
}
@@ -255,7 +277,7 @@ class TestingPanelController extends Controller
$newUpdateCount = ($lastUpdateCount == null || $lastUpdateCount == '') ? 0 : (int) $lastUpdateCount?->update_count + 1; // $maxUpdateCount?->update_count
$updateCountString = (string) $newUpdateCount;
// $updateCountString = (string) $newUpdateCount;
$row = [
'plant_id' => $plantId,
@@ -302,13 +324,14 @@ class TestingPanelController extends Controller
'result' => $serial['result'] ?? null,
'remark' => $serial['remark'] ?? null,
'rework_count' => $serial['rework_count'] ?? 0,
'rework_winded' => $serial['rework_winded'] ?? 0,
'output_flag' => $serial['output_flag'] ?? 0,
'tested_by' => $serial['tested_by'] ?? null,
'updated_by' => $serial['updated_by'] ?? null,
'tested_by' => (($serial['tested_by'] == 'jothi') ? 'Admin' : $serial['tested_by']) ?? null,
'updated_by' => (($serial['updated_by'] == 'jothi') ? 'Admin' : $serial['updated_by']) ?? null,
'created_at' => $serial['created_at'] ?? null,
'updated_at' => $serial['updated_at'] ?? $serial['created_at'],
'scanned_at' => $serial['scanned_at'] ?? null,
'update_count' => $updateCountString,
'update_count' => (string) $newUpdateCount,
];
// Insert the new record
@@ -365,9 +388,9 @@ class TestingPanelController extends Controller
$data = $request->all();
$plantCode = $data['plant_code'] ?? '';
$itemCode = $data['item_code'] ?? '';
$serialNumber = $data['serial_number'] ?? '';
$plantCode = $data['plant_code'] ?? null;
$itemCode = $data['item_code'] ?? null;
$serialNumber = $data['serial_number'] ?? null;
$testStatus = $data['test_status'] ?? 'F';
if ($plantCode == null || $plantCode == '' || ! $plantCode) {
@@ -686,22 +709,67 @@ class TestingPanelController extends Controller
}
$data = $request->all();
$plantCode = $data['plant_code'] ?? null;
$groupWorkCenter = $data['line_name'] ?? null;
$workCenter = $data['machine_name'] ?? null;
if ($data['plant_code'] == null || $data['plant_code'] == '') {
// return response("ERROR: Please provide a valid plant code.", 400)
// ->header('Content-Type', 'text/plain');
if ($plantCode == null || $plantCode == '' || ! $plantCode) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Plant code can't be empty!",
], 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'])
], 400);
} elseif (! is_numeric($plantCode)) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => 'Invalid plant code found!',
'status_description' => "Plant code '{$plantCode}' should contain only numeric values!",
], 400);
} elseif (Str::length($plantCode) < 4 || Str::length($plantCode) > 7) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Plant code '{$plantCode}' must be between 4 and 7 digits only!",
], 400);
} elseif (! preg_match('/^[1-9]\d{3,6}$/', $plantCode)) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Invalid plant code '{$plantCode}' found!",
], 400);
}
if ($groupWorkCenter == null || $groupWorkCenter == '' || ! $groupWorkCenter) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Group work center can't be empty!",
], 404);
} elseif (Str::length($groupWorkCenter) < 6) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Group work center '{$groupWorkCenter}' should contain minimum 6 characters!",
], 404);
} elseif (! ctype_alnum($groupWorkCenter)) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Group work center '{$groupWorkCenter}' should contain only alpha-numeric values!",
], 404);
}
$plant = Plant::where('code', $data['plant_code'])->first();
if ($workCenter == null || $workCenter == '' || ! $workCenter) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Work center can't be empty!",
], 404);
} elseif (Str::length($workCenter) < 6) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Work center '{$workCenter}' should contain minimum 6 characters!",
], 404);
} elseif (! ctype_alnum($workCenter)) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Work center '{$workCenter}' should contain only alpha-numeric values!",
], 404);
}
$plant = Plant::where('code', $plantCode)->first();
if (! $plant) {
// return response("Plant not found.", 400)->header('Content-Type', 'text/plain');
return response()->json([
@@ -713,19 +781,7 @@ class TestingPanelController extends Controller
$plantId = $plant->id;
$plantName = $plant->name;
if ($data['line_name'] == null || $data['line_name'] == '') {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Group work center can't be empty!",
], 404);
} elseif (Str::length($data['line_name']) < 0) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => 'Invalid group work center found!',
], 404);
}
$gWorkCenter = WorkGroupMaster::where('name', $data['line_name'])->first();
$gWorkCenter = WorkGroupMaster::where('name', $groupWorkCenter)->first();
if (! $gWorkCenter) {
return response()->json([
'status_code' => 'ERROR',
@@ -733,30 +789,18 @@ class TestingPanelController extends Controller
], 404);
}
$gWorkCenter = WorkGroupMaster::where('name', $data['line_name'])->where('plant_id', $plantId)->first();
$gWorkCenter = WorkGroupMaster::where('name', $groupWorkCenter)->where('plant_id', $plantId)->first();
if (! $gWorkCenter) {
// return response( "Line not found for the specified plant : {$data['plant_code']}",400)->header('Content-Type', 'text/plain');
// return response( "Line not found for the specified plant : {$plantCode}",400)->header('Content-Type', 'text/plain');
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Group work center not found for the specified plant : '{$data['plant_code']}'!",
'status_description' => "Group work center not found for the specified plant : '{$plantCode}'!",
], 404);
}
$gWorkCenterId = $gWorkCenter->id;
if ($data['machine_name'] == null || $data['machine_name'] == '') {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Work center can't be empty!",
], 404);
} elseif (Str::length($data['machine_name']) < 0) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => 'Invalid work center found!',
], 404);
}
$machine = Machine::where('work_center', $data['machine_name'])->first();
$machine = Machine::where('work_center', $workCenter)->first();
if (! $machine) {
return response()->json([
'status_code' => 'ERROR',
@@ -764,29 +808,29 @@ class TestingPanelController extends Controller
], 404);
}
$machine = Machine::where('work_center', $data['machine_name'])->where('plant_id', $plantId)->first();
$machine = Machine::where('work_center', $workCenter)->where('plant_id', $plantId)->first();
if (! $machine) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Work center not found for the specified plant : '{$data['plant_code']}'!",
'status_description' => "Work center not found for the specified plant : '{$plantCode}'!",
], 404);
}
$machine = Machine::where('work_center', $data['machine_name'])->where('work_group_master_id', $gWorkCenterId)->first();
$machine = Machine::where('work_center', $workCenter)->where('work_group_master_id', $gWorkCenterId)->first();
if (! $machine) {
// return response("Machine not found for the specified line : {$data['line_name']}", 400)->header('Content-Type', 'text/plain');
// return response("Machine not found for the specified line : {$groupWorkCenter}", 400)->header('Content-Type', 'text/plain');
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Work center not found for the specified Group work center : '{$data['line_name']}'!",
'status_description' => "Work center not found for the specified Group work center : '{$groupWorkCenter}'!",
], 404);
}
$machine = Machine::where('work_center', $data['machine_name'])->where('plant_id', $plantId)->where('work_group_master_id', $gWorkCenterId)->first();
$machine = Machine::where('work_center', $workCenter)->where('plant_id', $plantId)->where('work_group_master_id', $gWorkCenterId)->first();
if (! $machine) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Work center not found for the specified Plant : '{$data['plant_code']}' and Group work center : '{$data['line_name']}'!",
'status_description' => "Work center not found for the specified Plant : '{$plantCode}' and Group work center : '{$groupWorkCenter}'!",
], 404);
}
@@ -1478,7 +1522,7 @@ class TestingPanelController extends Controller
'flow_reading' => $entry['flow_reading'] ?? '0',
'current' => $entry['current'] ?? '0',
'watt' => $entry['watt'] ?? '0',
'tested_by' => $entry['created_by'] ?? $userName,
'tested_by' => (($entry['created_by'] == 'Admin') ? 'jothi' : $entry['created_by']) ?? $userName,
'created_datetime' => ! empty($entry['created_at']) ? Carbon::parse($entry['created_at'])->setTimezone('Asia/Kolkata')->format('Y-m-d H:i:s') : now('Asia/Kolkata')->format('Y-m-d H:i:s'),
];
}, $pumpTestingEntries ?? []),
@@ -1704,8 +1748,7 @@ class TestingPanelController extends Controller
$flow_reading = $entry['flow_reading'] ?? '0';
$current = $entry['current'] ?? '0';
$watt = $entry['watt'] ?? '0';
$tested_by = $entry['tested_by'] ?? $userName;
$tested_by = ($tested_by == 'jothi') ? 'Admin' : $tested_by;
$tested_by = (($entry['tested_by'] == 'jothi') ? 'Admin' : $entry['tested_by']) ?? $userName;
// $pendingExists = PumpTestingEntry::where('plant_id', $plantId)->where('pump_serial_number', $pumpSerial)->where('pump_testing_master_id', $pumpMasterId)->where('tested_type', $testedType)->where('sl_no', $sl_no)->first();
$cnt++;
@@ -1780,8 +1823,7 @@ class TestingPanelController extends Controller
$flow_reading = $entry['flow_reading'] ?? '0';
$current = $entry['current'] ?? '0';
$watt = $entry['watt'] ?? '0';
$tested_by = $entry['tested_by'] ?? $userName;
$tested_by = ($tested_by == 'jothi') ? 'Admin' : $tested_by;
$tested_by = (($entry['tested_by'] == 'jothi') ? 'Admin' : $entry['tested_by']) ?? $userName;
$createdRows++;
PumpTestingEntry::create([
@@ -2043,7 +2085,7 @@ class TestingPanelController extends Controller
'flow_reading' => $result['discharge'] ?? '0',
'current' => $result['current'] ?? '0',
'watt' => (string) (($result['watt'] ?? '0') * 1000),
'tested_by' => $result['created_by'] ?? $userName,
'tested_by' => (($result['created_by'] == 'Admin') ? 'jothi' : $result['created_by']) ?? $userName,
'created_datetime' => ! empty($result['created_at']) ? Carbon::parse($result['created_at'])->setTimezone('Asia/Kolkata')->format('Y-m-d H:i:s') : now('Asia/Kolkata')->format('Y-m-d H:i:s'),
];
}, $pumpTestingResults ?? []),
@@ -2277,8 +2319,7 @@ class TestingPanelController extends Controller
$power_p2 = $result['power_p2'] ?? '0';
$overall_efficiency = $result['overall_efficiency'] ?? '0';
$pump_efficiency = $result['pump_efficiency'] ?? '0';
$tested_by = $result['tested_by'] ?? $userName;
$tested_by = ($tested_by == 'jothi') ? 'Admin' : $tested_by;
$tested_by = (($result['tested_by'] == 'jothi') ? 'Admin' : $result['tested_by']) ?? $userName;
// $pendingExists = PumpTestingResult::where('plant_id', $plantId)->where('pump_serial_number', $pumpSerial)->where('pump_testing_master_id', $pumpMasterId)->where('tested_type', $testedType)->where('sl_no', $sl_no)->first();
$cnt++;
@@ -2368,8 +2409,7 @@ class TestingPanelController extends Controller
$power_p2 = $result['power_p2'] ?? '0';
$overall_efficiency = $result['overall_efficiency'] ?? '0';
$pump_efficiency = $result['pump_efficiency'] ?? '0';
$tested_by = $result['tested_by'] ?? $userName;
$tested_by = ($tested_by == 'jothi') ? 'Admin' : $tested_by;
$tested_by = (($result['tested_by'] == 'jothi') ? 'Admin' : $result['tested_by']) ?? $userName;
$createdRows++;
PumpTestingResult::create([