ranjith-dev #1496

Merged
jothi merged 2 commits from ranjith-dev into master 2026-11-23 06:24:20 +00:00
2 changed files with 322 additions and 0 deletions

View File

@@ -6,8 +6,12 @@ use App\Models\CharacteristicValue;
use App\Models\GrMaster; use App\Models\GrMaster;
use App\Models\Item; use App\Models\Item;
use App\Models\Line; use App\Models\Line;
use App\Models\Machine;
use App\Models\Plant; use App\Models\Plant;
use App\Models\ProcessOrder; use App\Models\ProcessOrder;
use App\Models\ProductionCharacteristic;
use App\Models\ProductionQuantity;
use App\Models\Shift;
use App\Models\User; use App\Models\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
@@ -25,6 +29,318 @@ class PdfController extends Controller
// //
} }
public function storeProdCharData(Request $request)
{
$expectedUser = env('API_AUTH_USER');
$expectedPw = env('API_AUTH_PW');
$headerAuth = $request->header('Authorization');
$expectedToken = 'Bearer '.$expectedUser.':'.$expectedPw;
if ($headerAuth != $expectedToken) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => 'Invalid authorization token!',
], 401);
}
$plantCode = $request->header('plant-code');
$itemCode = $request->header('item-code');
$lineName = $request->header('line-name');
$workCenter = $request->header('work-center');
$pOrder = $request->header('production-order');
$sNo = $request->header('serial-number');
$employeeCode = $request->header('employee-code');
if ($plantCode == null || $plantCode == '' || ! $plantCode) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Plant code can't be empty!",
], 400);
} elseif (! is_numeric($plantCode)) {
return response()->json([
'status_code' => 'ERROR',
'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);
}
$plant = Plant::where('code', $plantCode)->first();
if (! $plant) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Plant code '{$plantCode}' not found in plants table!",
], 404);
}
$plantId = $plant->id;
$plantName = $plant->name;
if ($lineName == null || $lineName == '' || ! $lineName) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Line name can't be empty!",
], 404);
}
$line = Line::where('name', $lineName)->first();
if (! $line) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Line '{$lineName}' not found in lines table!",
], 404);
}
$line = Line::where('name', $lineName)->where('plant_id', $plantId)->first();
if (! $line) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Line '{$lineName}' not found for the plant name '{$plantName}' in lines table!",
], 404);
}
$lineId = $line->id;
if ($itemCode == null || $itemCode == '' || ! $itemCode) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Item code can't be empty!",
], 404);
}
$item = Item::where('code', $itemCode)->first();
if (! $item) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Item Code '{$itemCode}' not found in items table!",
], 404);
}
$item = Item::where('code', $itemCode)->where('plant_id', $plantId)->first();
if (! $item) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Item code '{$itemCode}' not found for the plant name '{$plantName}' in items table!",
], 404);
}
$itemId = $item->id;
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);
}
$machine = Machine::where('work_center', $workCenter)->first();
if (! $machine) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Work center '{$workCenter}' not found in machines table!",
], 404);
}
$machine = Machine::where('work_center', $workCenter)->where('plant_id', $plantId)->first();
if (! $machine) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Work center '{$workCenter}' not found for the plant name '{$plantName}' in machines table!",
], 404);
}
$machine = Machine::where('line_id', $lineId)->where('work_center', $workCenter)->where('plant_id', $plantId)->first();
if (! $machine) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Work center '{$workCenter}' is not mapped for the given line name '{$lineName}' in machines table!",
], 404);
}
$machineId = $machine->id;
if ($pOrder == null || $pOrder == '' || ! $pOrder) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Production Order can't be empty!",
], 404);
} elseif (Str::length($pOrder) < 7) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Production Order '{$pOrder}' should contain minimum 7 digits!",
], 404);
}
if ($sNo == null || $sNo == '' || ! $sNo) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Serial Number can't be empty!",
], 404);
} elseif (Str::length($sNo) < 9) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Serial Number '{$sNo}' should contain minimum 9 digits!",
], 404);
} elseif (! ctype_alnum($sNo)) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Serial Number '{$sNo}' should contain only alpha-numeric values!",
], 404);
}
if ($employeeCode == null || $employeeCode == '' || ! $employeeCode) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Employee Code can't be empty!",
], 404);
} elseif (Str::length($employeeCode) < 6) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Employee Code '{$employeeCode}' should contain minimum 6 digits!",
], 404);
} elseif (! ctype_alnum($employeeCode)) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Employee Code '{$employeeCode}' should contain only alpha-numeric values!",
], 404);
}
$eCode = User::where('plant_id', $plantId)->where('name', $employeeCode)->first();
if(!$eCode){
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Employee Code '{$employeeCode}' not found!",
], 404);
}
$userName = $eCode->name;
$data = $request->all();
$errorMessage = '';
foreach ($data as $index => $characteristic) {
$characteristicsName = $characteristic['characteristics_name'] ?? '';
$obsValue = $characteristic['observed_value'] ?? '';
$status = $characteristic['status'] ?? '';
if (empty($characteristicsName)) {
$errorMessage = "Row " . ($index + 1) . ": Characteristics name is missing.";
break;
} elseif ($obsValue === '') {
$errorMessage = "Row " . ($index + 1) . ": Observed value is missing.";
break;
} elseif (empty($status)) {
$errorMessage = "Row " . ($index + 1) . ": Status is missing.";
break;
} elseif (!in_array($status, ['Ok', 'NotOk'], true)) {
$errorMessage = "Row " . ($index + 1) . ": Status must be either Ok or NotOk.";
break;
}
}
if ($errorMessage != '') {
$response = [
'status_code' => 'ERROR',
'status_description' => $errorMessage,
];
return response()->json($response, 404);
}
$recordProdQuan = ProductionQuantity::where('plant_id', $plantId)->where('serial_number', $sNo)->first();
if($recordProdQuan){
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Duplicate Serial Number $sNo already exist against plant $plantName.",
], 404);
}
$currentTime = now()->format('H:i');
if ($currentTime >= '08:00' && $currentTime < '19:30') {
$shift = 'Day';
} else {
$shift = 'Night';
}
$shift = Shift::where('plant_id', $plantId)->where('name', $shift)->first();
if (!$shift) {
return response()->json([
'status_code' => 'ERROR',
'status_description' => "$shift shift not found for plant $plantName.",
], 404);
}
$recordIns = ProductionQuantity::insert([
'plant_id' => $plantId,
'line_id' => $lineId,
'item_id' => $itemId,
'shift_id' => $shift->id,
'machine_id' => $machineId,
'serial_number' => $sNo,
'production_order' => $pOrder,
'operator_id' => $userName,
'created_at' => now(),
]);
if($recordIns){
// Insert into production_characteristics (multiple records)
foreach ($data as $characteristic) {
$recordCharIns = ProductionCharacteristic::insert([
'plant_id' => $plantId,
'line_id' => $lineId,
'item_id' => $itemId,
'machine_id' => $machineId,
'serial_number' => $sNo,
'production_order' => $pOrder,
'characteristic_name' => $characteristic['characteristics_name'],
'observed_value' => $characteristic['observed_value'],
'status' => $characteristic['status'],
'created_at' => now(),
]);
}
if($recordCharIns){
return response()->json([
'status_code' => 'SUCCESS',
'status_description' => 'Production quantity and characteristic records have been created successfully.',
], 200);
}
else{
return response()->json([
'status_code' => 'ERROR',
'status_description' => "Failed to insert production characteristics for Serial Number $sNo.Please Revoke this Serial Number from Production Quantities table",
], 404);
}
}
}
public function updateGR(Request $request) public function updateGR(Request $request)
{ {
$expectedUser = env('API_AUTH_USER'); $expectedUser = env('API_AUTH_USER');

View File

@@ -262,6 +262,8 @@ Route::get('get-characteristics/master-data', [CharacteristicsController::class,
Route::get('characteristics/get/master', [CharacteristicsController::class, 'getCharMaster']); // LIVEEEE Route::get('characteristics/get/master', [CharacteristicsController::class, 'getCharMaster']); // LIVEEEE
Route::post('production/characteristics/data', [PdfController::class, 'storeProdCharData']);
Route::post('characteristics/values', [CharacteristicsController::class, 'storeCharValues']); Route::post('characteristics/values', [CharacteristicsController::class, 'storeCharValues']);
// GR Master PDF and Serial Number // GR Master PDF and Serial Number
@@ -301,3 +303,7 @@ Route::get('leak-test-item', [PlantController::class, 'getItemLine']);
Route::get('/download-coil-qr-pdf/{palletNo}', [PalletController::class, 'downloadCoilQrPdf'])->name('download-coil-qr-pdf'); Route::get('/download-coil-qr-pdf/{palletNo}', [PalletController::class, 'downloadCoilQrPdf'])->name('download-coil-qr-pdf');
Route::get('coil-details', [PdfController::class, 'getCoilDetails']); Route::get('coil-details', [PdfController::class, 'getCoilDetails']);
//..Testing Panel Data
// Route::post('testing/route/data', [CharacteristicsController::class, 'testRoute']);