Refactored store method in TestingPanelController to improve validation for line and machine names, replacing Line model with WorkGroupMaster for accurate data handling.
This commit is contained in:
@@ -8,6 +8,7 @@ use App\Models\Machine;
|
|||||||
use App\Models\MotorTestingMaster;
|
use App\Models\MotorTestingMaster;
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
use App\Models\TestingPanelReading;
|
use App\Models\TestingPanelReading;
|
||||||
|
use App\Models\WorkGroupMaster;
|
||||||
use DB;
|
use DB;
|
||||||
use Filament\Notifications\Notification;
|
use Filament\Notifications\Notification;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@@ -47,7 +48,6 @@ class TestingPanelController extends Controller
|
|||||||
], 403);
|
], 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$data = $request->all();
|
$data = $request->all();
|
||||||
|
|
||||||
if ($data['plant_code'] == null || $data['plant_code'] == '')
|
if ($data['plant_code'] == null || $data['plant_code'] == '')
|
||||||
@@ -78,19 +78,32 @@ class TestingPanelController extends Controller
|
|||||||
|
|
||||||
$plantId = $plant->id;
|
$plantId = $plant->id;
|
||||||
|
|
||||||
$line = Line::where('group_work_center', $data['line_name'])->first();
|
if ($data['line_name'] == null || $data['line_name'] == '')
|
||||||
if (!$line)
|
{
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Group work center can't be empty!"
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
else if (Str::length($data['line_name']) < 0)
|
||||||
|
{
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Invalid group work center found!"
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$gWorkCenter = WorkGroupMaster::where('name', $data['line_name'])->first();
|
||||||
|
if (!$gWorkCenter)
|
||||||
{
|
{
|
||||||
//return response("Line not found.", 400)->header('Content-Type', 'text/plain');
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => 'Group work center not found!'
|
'status_description' => 'Group work center not found!'
|
||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$line = Line::where('group_work_center', $data['line_name'])->where('plant_id', $plantId)->first();
|
$gWorkCenter = WorkGroupMaster::where('name', $data['line_name'])->where('plant_id', $plantId)->first();
|
||||||
|
if (!$gWorkCenter)
|
||||||
if (!$line)
|
|
||||||
{
|
{
|
||||||
//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 : {$data['plant_code']}",400)->header('Content-Type', 'text/plain');
|
||||||
return response()->json([
|
return response()->json([
|
||||||
@@ -99,13 +112,26 @@ class TestingPanelController extends Controller
|
|||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$lineId = $line->id;
|
$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!"
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
else if (Str::length($data['machine_name']) < 0)
|
||||||
|
{
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Invalid work center found!"
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
$machine = Machine::where('work_center', $data['machine_name'])->first();
|
$machine = Machine::where('work_center', $data['machine_name'])->first();
|
||||||
|
|
||||||
if (!$machine)
|
if (!$machine)
|
||||||
{
|
{
|
||||||
// return response('Machine not found', 400)->header('Content-Type', 'text/plain');
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => 'Work center not found!'
|
'status_description' => 'Work center not found!'
|
||||||
@@ -113,18 +139,15 @@ class TestingPanelController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$machine = Machine::where('work_center', $data['machine_name'])->where('plant_id', $plantId)->first();
|
$machine = Machine::where('work_center', $data['machine_name'])->where('plant_id', $plantId)->first();
|
||||||
|
|
||||||
if (!$machine)
|
if (!$machine)
|
||||||
{
|
{
|
||||||
// return response("Machine not found for the specified plant : {$data['plant_code']}", 400)->header('Content-Type', 'text/plain');
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'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 : '{$data['plant_code']}'!"
|
||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$machine = Machine::where('work_center', $data['machine_name'])->where('line_id', $lineId)->first();
|
$machine = Machine::where('work_center', $data['machine_name'])->where('work_group_master_id', $gWorkCenterId)->first();
|
||||||
|
|
||||||
if (!$machine)
|
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 : {$data['line_name']}", 400)->header('Content-Type', 'text/plain');
|
||||||
@@ -135,17 +158,15 @@ class TestingPanelController extends Controller
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$machine = Machine::where('work_center', $data['machine_name'])->where('plant_id', $plantId)->where('line_id', $lineId)->first();
|
$machine = Machine::where('work_center', $data['machine_name'])->where('plant_id', $plantId)->where('work_group_master_id', $gWorkCenterId)->first();
|
||||||
|
|
||||||
if (!$machine) {
|
if (!$machine) {
|
||||||
// return response('Machine not found for the specified plant and line', 400)
|
|
||||||
// ->header('Content-Type', 'text/plain');
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => 'Work center not found for the specified plant and group work center!'
|
'status_description' => "Work center not found for the specified Plant : '{$data['plant_code']}' and Group work center : '{$data['line_name']}'!"
|
||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$lineId = $machine->line_id;
|
||||||
$machineId = $machine->id;
|
$machineId = $machine->id;
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -262,8 +283,7 @@ class TestingPanelController extends Controller
|
|||||||
|
|
||||||
$updateCountString = (string)$newUpdateCount;
|
$updateCountString = (string)$newUpdateCount;
|
||||||
|
|
||||||
$row =
|
$row = [
|
||||||
[
|
|
||||||
'plant_id' => $plantId,
|
'plant_id' => $plantId,
|
||||||
'line_id' => $lineId,
|
'line_id' => $lineId,
|
||||||
'machine_id' => $machineId,
|
'machine_id' => $machineId,
|
||||||
|
|||||||
Reference in New Issue
Block a user