ranjith-dev #415

Merged
jothi merged 4 commits from ranjith-dev into master 2026-02-26 15:45:11 +00:00
Showing only changes of commit 5aec248632 - Show all commits

View File

@@ -167,6 +167,7 @@ class CharacteristicsController extends Controller
// ]; // ];
// return response()->json($response); // return response()->json($response);
foreach ($characteristics as $char) { foreach ($characteristics as $char) {
$line = Line::find($char->line_id); $line = Line::find($char->line_id);
@@ -203,7 +204,6 @@ class CharacteristicsController extends Controller
return response()->json([ return response()->json([
'items' => $items, 'items' => $items,
]); ]);
} }
/** /**
@@ -2231,62 +2231,89 @@ class CharacteristicsController extends Controller
], 404); ], 404);
} }
$lineAgaPlant = Line::where('plant_id', $plantId)->where('name', $lineName)->first(); $line = Line::where('plant_id', $plantId)->where('name', $lineName)->first();
if (! $lineAgaPlant) { if (! $line) {
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Line Name not found in lines table for the plant : '$plant->name'!", 'status_description' => "Line Name not found in lines table for the plant : '$plant->name'!",
], 404); ], 404);
} }
$work = Machine::where('work_center', $workCenter)->first(); $lineId = $line->id;
if (! $work) { $machine = Machine::where('work_center', $workCenter)->first();
if (! $machine) {
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => 'Work Center not found in machines table!', 'status_description' => 'Work Center not found in machines table!',
], 404); ], 404);
} }
$workAgaPlant = Machine::where('plant_id', $plantId)->where('work_center', $workCenter)->first(); $machine = Machine::where('plant_id', $plantId)->where('work_center', $workCenter)->first();
if (! $workAgaPlant) { if (! $machine) {
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Work center not found in machines table for the plant : '$plant->name'!", 'status_description' => "Work center not found in machines table for the plant : '$plant->name'!",
], 404); ], 404);
} }
$machine = Machine::where('plant_id', $plantId)->where('line_id', $lineId)->where('work_center', $workCenter)->first();
if (! $machine) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => 'Work center is not mapped for the given line!',
], 404);
}
$machineId = $machine->id;
// $description = $item ? $item->description : ''; // $description = $item ? $item->description : '';
// $uom = $item ? $item->uom : ''; // $uom = $item ? $item->uom : '';
// $category = $item ? $item->category : ''; // $category = $item ? $item->category : '';
$charMaster = ProductCharacteristicsMaster::where('plant_id', $plantId)->where('item_id', $ItemId) $charMasters = ProductCharacteristicsMaster::with('workGroupMaster')->where('plant_id', $plantId)->where('item_id', $ItemId)->where('line_id', $lineId)->where('machine_id', $machineId)->get(); // ->select(['name', 'characteristics_type', 'inspection_type', 'lower', 'middle', 'upper', 'work_group_master_id'])
->where('line_id', $lineAgaPlant->id)->where('machine_id', $workAgaPlant->id)
->first();
if (! $charMaster) { if (! $charMasters) {
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Characteristics not found in product master table for the plant : '$plant->name'!", 'status_description' => "Characteristics not found in product master table for the plant : '$plant->name'!",
], 404); ], 404);
} else {
$output = $charMasters->map(function ($charMast) {
$charMaster = [
'work_group_master' => optional($charMast->workGroupMaster)->name ?? '',
'name' => $charMast?->name ?? '',
'characteristics_type' => $charMast?->characteristics_type ?? '',
'inspection_type' => $charMast?->inspection_type ?? '',
'lower' => (string) $charMast?->lower ?? '',
'middle' => (string) $charMast?->middle ?? '',
'upper' => (string) $charMast?->upper ?? '',
];
return $charMaster;
});
} }
$workGroup = WorkGroupMaster::find($charMaster->work_group_master_id); // $charMasters = ProductCharacteristicsMaster::with('workGroupMaster')->where('plant_id', $plantId)->where('item_id', $ItemId)->where('line_id', $lineId)->where('machine_id', $machineId)->first();
$workGroupName = $workGroup?->name ?? '';
$output = [ // // $workGroup = WorkGroupMaster::find($charMasters->work_group_master_id);
'work_group_master' => $workGroupName ?? '', // // $workGroupName = $workGroup?->name ?? '';
'name' => $charMaster?->name ?? '',
'characteristics_type' => $charMaster?->characteristics_type ?? '', // $output = [
'inspection_type' => $charMaster?->inspection_type ?? '', // 'work_group_master' => $charMasters?->workGroupMaster->name ?? '', // $workGroupName ?? '',
'lower' => (string) $charMaster?->lower ?? '', // 'name' => $charMasters?->name ?? '',
'middle' => (string) $charMaster?->middle ?? '', // 'characteristics_type' => $charMasters?->characteristics_type ?? '',
'upper' => (string) $charMaster?->upper ?? '', // 'inspection_type' => $charMasters?->inspection_type ?? '',
]; // 'lower' => (string) $charMasters?->lower ?? '',
// 'middle' => (string) $charMasters?->middle ?? '',
// 'upper' => (string) $charMasters?->upper ?? '',
// ];
return response()->json($output, 200); return response()->json($output, 200);
} }
@@ -2347,15 +2374,15 @@ class CharacteristicsController extends Controller
], 404); ], 404);
} }
$lineAgaPlant = Line::where('plant_id', $plantId)->where('name', $lineName)->first(); $line = Line::where('plant_id', $plantId)->where('name', $lineName)->first();
if (! $lineAgaPlant) { if (! $line) {
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Line '{$lineName}' not found against plant code '$plantCode'!", 'status_description' => "Line '{$lineName}' not found against plant code '$plantCode'!",
], 404); ], 404);
} }
$lineId = $lineAgaPlant->id; $lineId = $line->id;
if ($itemCode == null || $itemCode == '') { if ($itemCode == null || $itemCode == '') {
return response()->json([ return response()->json([
@@ -2372,15 +2399,15 @@ class CharacteristicsController extends Controller
], 404); ], 404);
} }
$itemAgaPlant = Item::where('plant_id', $plantId)->where('code', $itemCode)->first(); $item = Item::where('plant_id', $plantId)->where('code', $itemCode)->first();
if (! $itemAgaPlant) { if (! $item) {
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Item code '{$itemCode}' not found against plant code '$plantCode'!", 'status_description' => "Item code '{$itemCode}' not found against plant code '$plantCode'!",
], 404); ], 404);
} }
$itemId = $itemAgaPlant->id; $itemId = $item->id;
if ($workCenter == null || $workCenter == '') { if ($workCenter == null || $workCenter == '') {
return response()->json([ return response()->json([
@@ -2397,23 +2424,23 @@ class CharacteristicsController extends Controller
], 404); ], 404);
} }
$machineAgaPlant = Machine::where('plant_id', $plantId)->where('work_center', $workCenter)->first(); $machine = Machine::where('plant_id', $plantId)->where('work_center', $workCenter)->first();
if (! $machineAgaPlant) { if (! $machine) {
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Work center '{$workCenter}' not found against plant code '$plantCode'!", 'status_description' => "Work center '{$workCenter}' not found against plant code '$plantCode'!",
], 404); ], 404);
} }
$machineAgaPlantLine = Machine::where('plant_id', $plantId)->where('line_id', $lineId)->where('work_center', $workCenter)->first(); $machine = Machine::where('plant_id', $plantId)->where('line_id', $lineId)->where('work_center', $workCenter)->first();
if (! $machineAgaPlantLine) { if (! $machine) {
return response()->json([ return response()->json([
'status_code' => 'ERROR', 'status_code' => 'ERROR',
'status_description' => "Work center '{$workCenter}' not found against plant code '$plantCode' and line name '$lineName'!", 'status_description' => "Work center '{$workCenter}' not found against plant code '$plantCode' and line name '$lineName'!",
], 404); ], 404);
} }
$machineId = $machineAgaPlantLine->id; $machineId = $machine->id;
$data = $request->all(); $data = $request->all();