Added Heat number in post api obd and removed heat number in get api obd
This commit is contained in:
@@ -30,10 +30,17 @@ class ObdController extends Controller
|
|||||||
$header_auth = $request->header('Authorization');
|
$header_auth = $request->header('Authorization');
|
||||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||||
|
|
||||||
|
// if("Bearer " . $expectedToken !== $header_auth)
|
||||||
|
// {
|
||||||
|
// return response("ERROR: Unauthorized", 403)
|
||||||
|
// ->header('Content-Type', 'text/plain');
|
||||||
|
// }
|
||||||
if ("Bearer " . $expectedToken !== $header_auth)
|
if ("Bearer " . $expectedToken !== $header_auth)
|
||||||
{
|
{
|
||||||
return response("ERROR: Unauthorized", 403)
|
return response()->json([
|
||||||
->header('Content-Type', 'text/plain');
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => 'Invalid authorization token'
|
||||||
|
], 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -47,23 +54,35 @@ class ObdController extends Controller
|
|||||||
|
|
||||||
if (!empty($missing))
|
if (!empty($missing))
|
||||||
{
|
{
|
||||||
$message = "ERROR: Missing required field(s): " . implode(', ', $missing);
|
$message = "Missing required field(s): " . implode(', ', $missing);
|
||||||
return response($message, 400)->header('Content-Type', 'text/plain');
|
// return response($message, 400)->header('Content-Type', 'text/plain');
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => $message,
|
||||||
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
// OBD Number validation
|
// OBD Number validation
|
||||||
$obdNumber = $data['obd_number'];
|
$obdNumber = $data['obd_number'];
|
||||||
if (Str::length($obdNumber) < 8 || !ctype_alnum($obdNumber))
|
if (Str::length($obdNumber) < 8 || !ctype_alnum($obdNumber))
|
||||||
{
|
{
|
||||||
return response("ERROR: OBD Number should contain minimum 8 digits", 400)
|
// return response("ERROR: OBD Number should contain minimum 8 digits", 400)
|
||||||
->header('Content-Type', 'text/plain');
|
// ->header('Content-Type', 'text/plain');
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "OBD Number should contain minimum 8 digits: '$obdNumber'"
|
||||||
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lookup plant_id by plant_name
|
// Lookup plant_id by plant_name
|
||||||
$plantId = Plant::where('name', $data['plant_name'])->value('id');
|
$plantId = Plant::where('name', $data['plant_name'])->value('id');
|
||||||
if (!$plantId) {
|
if (!$plantId) {
|
||||||
return response("ERROR: Plant '" . $data['plant_name'] . "' not found", 404)
|
// return response("ERROR: Plant '" . $data['plant_name'] . "' not found", 404)
|
||||||
->header('Content-Type', 'text/plain');
|
// ->header('Content-Type', 'text/plain');
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Plant '" . $data['plant_name'] . "' not found"
|
||||||
|
], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if OBD number exists for that plant
|
//Check if OBD number exists for that plant
|
||||||
@@ -73,7 +92,11 @@ class ObdController extends Controller
|
|||||||
|
|
||||||
if (!$obdRecords)
|
if (!$obdRecords)
|
||||||
{
|
{
|
||||||
return response( "ERROR: OBD Number '$obdNumber' not found for plant '{$data['plant_name']}'",404)->header('Content-Type', 'text/plain');
|
// return response( "ERROR: OBD Number '$obdNumber' not found for plant '{$data['plant_name']}'",404)->header('Content-Type', 'text/plain');
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "OBD Number '$obdNumber' not found for plant '{$data['plant_name']}'"
|
||||||
|
], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -82,9 +105,14 @@ class ObdController extends Controller
|
|||||||
|
|
||||||
foreach ($data['line_numbers'] as $line)
|
foreach ($data['line_numbers'] as $line)
|
||||||
{
|
{
|
||||||
if ($line['line_number'] == '' || $line['line_number'] == null) {
|
if ($line['line_number'] == '' || $line['line_number'] == null)
|
||||||
return response("ERROR: Line Number can't be empty", 400)
|
{
|
||||||
->header('Content-Type', 'text/plain');
|
// return response("ERROR: Line Number can't be empty", 400)
|
||||||
|
// ->header('Content-Type', 'text/plain');
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Line Number can't be empty"
|
||||||
|
], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
$record = WeightValidation::where('plant_id', $plantId)
|
$record = WeightValidation::where('plant_id', $plantId)
|
||||||
@@ -103,7 +131,8 @@ class ObdController extends Controller
|
|||||||
|
|
||||||
foreach ($mandatoryFields as $field)
|
foreach ($mandatoryFields as $field)
|
||||||
{
|
{
|
||||||
if ($line[$field] == '' || $line[$field] == null) {
|
if ($line[$field] == '' || $line[$field] == null)
|
||||||
|
{
|
||||||
$missingFields[] = ucwords(str_replace('_', ' ', $field));
|
$missingFields[] = ucwords(str_replace('_', ' ', $field));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,87 +150,188 @@ class ObdController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$message = "ERROR: " . $fieldsString . " can't be empty for line_number " . $line['line_number'];
|
$message = "ERROR: " . $fieldsString . " can't be empty for line_number " . $line['line_number'];
|
||||||
return response($message, 400)->header('Content-Type', 'text/plain');
|
// return response($message, 400)->header('Content-Type', 'text/plain');
|
||||||
}
|
return response()->json([
|
||||||
// Check if ANY of the fields are NOT empty in DB
|
'status_code' => 'ERROR',
|
||||||
$fields = ['vehicle_number', 'bundle_number', 'picked_weight', 'scanned_by'];
|
'status_description' => $message
|
||||||
$alreadyUpdatedLines = [];
|
], 400);
|
||||||
|
|
||||||
foreach ($data['line_numbers'] as $line) {
|
|
||||||
// Fetch the record for this line
|
|
||||||
$record = WeightValidation::where('plant_id', $plantId)
|
|
||||||
->where('obd_number', $data['obd_number'])
|
|
||||||
->where('line_number', $line['line_number'])
|
|
||||||
->first();
|
|
||||||
|
|
||||||
//If No Record Found
|
|
||||||
if (!$record)
|
|
||||||
{
|
|
||||||
continue; // Skip to next line
|
|
||||||
}
|
|
||||||
|
|
||||||
$hasAnyValue = false;
|
|
||||||
foreach ($fields as $field)
|
|
||||||
{
|
|
||||||
if (!empty($record->$field))
|
|
||||||
{
|
|
||||||
$hasAnyValue = true;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($hasAnyValue)
|
|
||||||
{
|
|
||||||
$alreadyUpdatedLines[] = $line['line_number'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($alreadyUpdatedLines))
|
|
||||||
{
|
|
||||||
return response( "Already line number(s): " . implode(', ', $alreadyUpdatedLines) . " is updated for obd_number '" . $data['obd_number'] . "'", 400)->header('Content-Type', 'text/plain');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If any lines are missing, report
|
|
||||||
if (!empty($missingLines)) {
|
if (!empty($missingLines)) {
|
||||||
$message = "ERROR: Line(s) " . implode(', ', $missingLines) . " not found for Plant '" . $data['plant_name'] . "' and OBD Number: '" . $data['obd_number'] . "'";
|
$message = "ERROR: Line(s) " . implode(', ', $missingLines) . " not found for Plant '" . $data['plant_name'] . "' and OBD Number: '" . $data['obd_number'] . "'";
|
||||||
return response($message, 404)->header('Content-Type', 'text/plain');
|
// return response($message, 404)->header('Content-Type', 'text/plain');
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => $message
|
||||||
|
], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$seenPairs = [];
|
||||||
|
$internalDuplicates = [];
|
||||||
|
$bundleChecks = [];
|
||||||
|
|
||||||
|
//Check for duplicates within the request
|
||||||
|
foreach ($data['line_numbers'] as $line) {
|
||||||
|
$lineNumber = $line['line_number'];
|
||||||
|
$bundleNumber = trim((string)$line['bundle_number']);
|
||||||
|
$pairKey = $lineNumber . '|' . $bundleNumber;
|
||||||
|
|
||||||
|
if (isset($seenPairs[$pairKey])) {
|
||||||
|
$internalDuplicates[] = "Line Number {$lineNumber} with Bundle Number {$bundleNumber}";
|
||||||
|
} else {
|
||||||
|
$seenPairs[$pairKey] = true;
|
||||||
|
$bundleChecks[] = [
|
||||||
|
'line_number' => $lineNumber,
|
||||||
|
'bundle_number' => $bundleNumber,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check for duplicates in the database
|
||||||
|
|
||||||
|
$bundleNumbers = array_column($bundleChecks, 'bundle_number');
|
||||||
|
$lineNumbers = array_column($bundleChecks, 'line_number');
|
||||||
|
|
||||||
|
$existingBundles = WeightValidation::where('plant_id', $plantId)
|
||||||
|
->where('obd_number', $obdNumber)
|
||||||
|
->whereIn('line_number', $lineNumbers)
|
||||||
|
->whereIn('bundle_number', $bundleNumbers)
|
||||||
|
->get(['line_number', 'bundle_number']);
|
||||||
|
|
||||||
|
$grouped = [];
|
||||||
|
foreach ($existingBundles as $row) {
|
||||||
|
$line = $row->line_number;
|
||||||
|
$bundle = $row->bundle_number;
|
||||||
|
|
||||||
|
if (!isset($grouped[$line])) {
|
||||||
|
$grouped[$line] = [];
|
||||||
|
}
|
||||||
|
if ($bundle && !in_array($bundle, $grouped[$line])) {
|
||||||
|
$grouped[$line][] = $bundle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$dbDuplicates = [];
|
||||||
|
foreach ($grouped as $line => $bundles) {
|
||||||
|
$bundlesStr = implode(', ', $bundles);
|
||||||
|
$dbDuplicates[] = "Line {$line}, has bundle numbers : {$bundlesStr}";
|
||||||
|
}
|
||||||
|
|
||||||
|
//Return all errors if any duplicates found
|
||||||
|
$allDuplicates = [];
|
||||||
|
if (!empty($internalDuplicates))
|
||||||
|
{
|
||||||
|
$allDuplicates[] = "Duplicate(s) within request: " . implode(', ', $internalDuplicates);
|
||||||
|
}
|
||||||
|
if (!empty($dbDuplicates))
|
||||||
|
{
|
||||||
|
$allDuplicates[] = "Already exists in database: " . implode('; ', $dbDuplicates);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($allDuplicates)) {
|
||||||
|
// return response(
|
||||||
|
// "Error:" . implode("\n", $allDuplicates),
|
||||||
|
// 400
|
||||||
|
// )->header('Content-Type', 'text/plain');
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => $allDuplicates,
|
||||||
|
], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
//..
|
||||||
$updated = 0;
|
$updated = 0;
|
||||||
|
$inserted = 0;
|
||||||
$updatedLines = [];
|
$updatedLines = [];
|
||||||
|
$insertedLines = [];
|
||||||
|
$lineTracker = [];
|
||||||
|
|
||||||
foreach ($data['line_numbers'] as $line)
|
foreach ($data['line_numbers'] as $line)
|
||||||
{
|
{
|
||||||
$count = WeightValidation::where([
|
$lineNumber = $line['line_number'];
|
||||||
'plant_id' => $plantId,
|
$existing = WeightValidation::where('plant_id', $plantId)
|
||||||
'obd_number' => $data['obd_number'],
|
->where('obd_number', $obdNumber)
|
||||||
'line_number'=> $line['line_number'],
|
->where('line_number', $lineNumber)
|
||||||
])
|
->where(function ($query) {
|
||||||
->update([
|
$query->whereNull('bundle_number')
|
||||||
|
->orWhere('bundle_number', '');
|
||||||
|
})
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if($existing)
|
||||||
|
{
|
||||||
|
$existing->update([
|
||||||
'vehicle_number' => $line['vehicle_number'] ?? null,
|
'vehicle_number' => $line['vehicle_number'] ?? null,
|
||||||
'bundle_number' => $line['bundle_number'] ?? null,
|
'bundle_number' => $line['bundle_number'] ?? null,
|
||||||
|
'heat_number' => $line['heat_number'] ?? null,
|
||||||
'picked_weight' => $line['picked_weight'] ?? null,
|
'picked_weight' => $line['picked_weight'] ?? null,
|
||||||
'scanned_by' => $line['scanned_by'] ?? null,
|
'scanned_by' => $line['scanned_by'] ?? null,
|
||||||
'updated_at' => now(),
|
'updated_at' => now(),
|
||||||
]);
|
]);
|
||||||
|
$updated++;
|
||||||
|
$updatedLines[] = $lineNumber;
|
||||||
|
$lineTracker[$lineNumber] = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$original = WeightValidation::where([
|
||||||
|
'plant_id' => $plantId,
|
||||||
|
'obd_number' => $obdNumber,
|
||||||
|
'line_number' => $lineNumber,
|
||||||
|
])->orderBy('id')->first();
|
||||||
|
|
||||||
//$updated += $count;
|
WeightValidation::create([
|
||||||
if ($count > 0) {
|
'plant_id' => $plantId,
|
||||||
$updated += $count;
|
'obd_number' => $obdNumber,
|
||||||
$updatedLines[] = $line['line_number'];
|
'line_number' => $lineNumber,
|
||||||
|
'item_id' => $original->item_id ?? null,
|
||||||
|
'vehicle_number' => $line['vehicle_number'] ?? null,
|
||||||
|
'bundle_number' => $bundleNumber,
|
||||||
|
'picked_weight' => $line['picked_weight'] ?? null,
|
||||||
|
'scanned_by' => $line['scanned_by'] ?? null,
|
||||||
|
'batch_number' => $original->batch_number ?? null,
|
||||||
|
'heat_number' => $line['heat_number'] ?? null,
|
||||||
|
'obd_weight' => $original->obd_weight ?? null,
|
||||||
|
'created_at' => now(),
|
||||||
|
'updated_at' => now(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$inserted++;
|
||||||
|
$insertedLines[] = $lineNumber;
|
||||||
|
$lineTracker[$lineNumber] = isset($lineTracker[$lineNumber]) ? $lineTracker[$lineNumber] + 1 : 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$message = "SUCCESS: OBD Number '" . $data['obd_number'] . "' updated successfully and line number(s): " . implode(', ', $updatedLines);
|
$responseMessage = "Success: OBD Number '{$obdNumber}'";
|
||||||
return response($message, 200)->header('Content-Type', 'text/plain');
|
|
||||||
|
if ($updated > 0) {
|
||||||
|
$responseMessage .= " updated successfully. Line Numbers: {" . implode(', ', $updatedLines) . "}";
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($inserted > 0) {
|
||||||
|
$responseMessage .= "Inserted successfully. Line Numbers: {" . implode(', ', $insertedLines) . "}";
|
||||||
|
}
|
||||||
|
|
||||||
|
// return response($responseMessage, 200)
|
||||||
|
// ->header('Content-Type', 'text/plain');
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'SUCCESS',
|
||||||
|
'status_description' => $responseMessage,
|
||||||
|
], 200);
|
||||||
|
|
||||||
// $message = "SUCCESS: OBD Number '" . $data['obd_number'] . "' updated successfully";
|
|
||||||
// return response($message, 200)->header('Content-Type', 'text/plain');
|
|
||||||
}
|
}
|
||||||
catch (\Exception $e)
|
catch (\Exception $e)
|
||||||
{
|
{
|
||||||
return response("ERROR: Server error", 500)->header('Content-Type', 'text/plain');
|
return response("ERROR: Server error", 500)->header('Content-Type', 'text/plain');
|
||||||
}
|
}
|
||||||
|
// catch (\Exception $e) {
|
||||||
|
// // Log error if needed, e.g. Log::error($e->getMessage());
|
||||||
|
// return response()->json([
|
||||||
|
// 'status' => 'error',
|
||||||
|
// 'message' => 'Server error: ' . $e->getMessage(),
|
||||||
|
// ], 500);
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,77 +518,6 @@ class ObdController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the specified resource.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// public function get(Request $request)
|
|
||||||
// {
|
|
||||||
// $expectedUser = env('API_AUTH_USER');
|
|
||||||
// $expectedPw = env('API_AUTH_PW');
|
|
||||||
|
|
||||||
// $header_auth = $request->header('Authorization');
|
|
||||||
|
|
||||||
// $expectedToken = $expectedUser . ':' . $expectedPw;
|
|
||||||
|
|
||||||
// if ("Bearer " . $expectedToken !== $header_auth) {
|
|
||||||
// return response("ERROR: Unauthorized", 403)
|
|
||||||
// ->header('Content-Type', 'text/plain');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $plantName = $request->header('Plant_Name');
|
|
||||||
// $obdNumber = $request->header('obd_number');
|
|
||||||
|
|
||||||
// if (empty($plantName) || empty($obdNumber)) {
|
|
||||||
// return response("ERROR: Missing required headers (Plant_Name, OBD_Number)", 400)
|
|
||||||
// ->header('Content-Type', 'text/plain');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // Fetch the plant record by name
|
|
||||||
// $plant = Plant::where('name', $plantName)->value('id');
|
|
||||||
|
|
||||||
// if (!$plant)
|
|
||||||
// {
|
|
||||||
// return response("ERROR: Plant not found", 400)
|
|
||||||
// ->header('Content-Type', 'text/plain');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $plantId = $plant->id;
|
|
||||||
|
|
||||||
// $records = WeightValidation::where('plant_id', $plantId)
|
|
||||||
// ->where('obd_number', $obdNumber)
|
|
||||||
// ->get();
|
|
||||||
|
|
||||||
// if ($records->isEmpty()) {
|
|
||||||
// return response("ERROR: No records found", 404)->header('Content-Type', 'text/plain');
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $itemIds = $records->pluck('item_id')->unique();
|
|
||||||
// $itemCodes = Item::whereIn('id', $itemIds)
|
|
||||||
// ->select('id', 'code', 'description')
|
|
||||||
// ->get()
|
|
||||||
// ->keyBy('id');
|
|
||||||
|
|
||||||
// $ObdResponseStructure = [
|
|
||||||
// 'OBD_Number' => [
|
|
||||||
// [
|
|
||||||
// 'OBD_Number' => $obdNumber,
|
|
||||||
// 'Line_Numbers' => $records->map(function ($item) use ($itemCodes) {
|
|
||||||
// $itemInfo = $itemCodes[$item->item_id] ?? null;
|
|
||||||
// return [
|
|
||||||
// 'Line' => $item->line_number,
|
|
||||||
// 'Material_Code' => $itemInfo->code ?? "",
|
|
||||||
// 'Material_Description' => $itemInfo->description ?? "",
|
|
||||||
// // 'Quantity' => $item->picked_weight ?? "",
|
|
||||||
// 'Batch_Number' => $item->batch_number ?? "",
|
|
||||||
// 'Heat_Number' => $item->heat_number ?? "",
|
|
||||||
// ];
|
|
||||||
// })->toArray()
|
|
||||||
// ]
|
|
||||||
// ]
|
|
||||||
// ];
|
|
||||||
// return response()->json($ObdResponseStructure);
|
|
||||||
// }
|
|
||||||
|
|
||||||
public function get_obd(Request $request)
|
public function get_obd(Request $request)
|
||||||
{
|
{
|
||||||
@@ -467,10 +526,18 @@ class ObdController extends Controller
|
|||||||
$header_auth = $request->header('Authorization');
|
$header_auth = $request->header('Authorization');
|
||||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
$expectedToken = $expectedUser . ':' . $expectedPw;
|
||||||
|
|
||||||
|
// if ("Bearer " . $expectedToken !== $header_auth)
|
||||||
|
// {
|
||||||
|
// return response("ERROR: Unauthorized", 403)
|
||||||
|
// ->header('Content-Type', 'text/plain');
|
||||||
|
// }
|
||||||
|
|
||||||
if ("Bearer " . $expectedToken !== $header_auth)
|
if ("Bearer " . $expectedToken !== $header_auth)
|
||||||
{
|
{
|
||||||
return response("ERROR: Unauthorized", 403)
|
return response()->json([
|
||||||
->header('Content-Type', 'text/plain');
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => 'Invalid authorization token'
|
||||||
|
], 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
$plantName = $request->header('plant-name');
|
$plantName = $request->header('plant-name');
|
||||||
@@ -478,26 +545,42 @@ class ObdController extends Controller
|
|||||||
|
|
||||||
if (empty($plantName))
|
if (empty($plantName))
|
||||||
{
|
{
|
||||||
return response("ERROR: Plant Name can't be empty", 400)
|
// return response("ERROR: Plant Name can't be empty", 400)
|
||||||
->header('Content-Type', 'text/plain');
|
// ->header('Content-Type', 'text/plain');
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Plant Name can't be empty"
|
||||||
|
], 400);
|
||||||
}
|
}
|
||||||
else if(empty($obdNumber))
|
else if(empty($obdNumber))
|
||||||
{
|
{
|
||||||
return response("ERROR: OBD Number can't be empty", 400)
|
// return response("ERROR: OBD Number can't be empty", 400)
|
||||||
->header('Content-Type', 'text/plain');
|
// ->header('Content-Type', 'text/plain');
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "OBD Number can't be empty"
|
||||||
|
], 400);
|
||||||
}
|
}
|
||||||
else if(Str::length($obdNumber) < 8 || !ctype_alnum($obdNumber))
|
else if(Str::length($obdNumber) < 8 || !ctype_alnum($obdNumber))
|
||||||
{
|
{
|
||||||
return response("ERROR: OBD Number should contain minimum 8 digits: '$obdNumber'", 400)
|
// return response("ERROR: OBD Number should contain minimum 8 digits: '$obdNumber'", 400)
|
||||||
->header('Content-Type', 'text/plain');
|
// ->header('Content-Type', 'text/plain');
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "OBD Number should contain minimum 8 digits: '$obdNumber'"
|
||||||
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the plant id by name
|
// Fetch the plant id by name
|
||||||
$plantId = Plant::where('name', $plantName)->value('id');
|
$plantId = Plant::where('name', $plantName)->value('id');
|
||||||
|
|
||||||
if (!$plantId) {
|
if (!$plantId) {
|
||||||
return response("ERROR: Plant not found", 400)
|
// return response("ERROR: Plant not found", 400)
|
||||||
->header('Content-Type', 'text/plain');
|
// ->header('Content-Type', 'text/plain');
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Plant not found"
|
||||||
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
// $records = WeightValidation::where('plant_id', $plantId)
|
// $records = WeightValidation::where('plant_id', $plantId)
|
||||||
@@ -511,8 +594,12 @@ class ObdController extends Controller
|
|||||||
|
|
||||||
if (!$exists)
|
if (!$exists)
|
||||||
{
|
{
|
||||||
return response("ERROR: OBD number $obdNumber does not exist for plant '$plantName'", 404)
|
// return response("ERROR: OBD number $obdNumber does not exist for plant '$plantName'", 404)
|
||||||
->header('Content-Type', 'text/plain');
|
// ->header('Content-Type', 'text/plain');
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "OBD number $obdNumber does not exist for plant '$plantName'"
|
||||||
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$records = WeightValidation::where('plant_id', $plantId)
|
$records = WeightValidation::where('plant_id', $plantId)
|
||||||
@@ -523,7 +610,11 @@ class ObdController extends Controller
|
|||||||
});
|
});
|
||||||
|
|
||||||
if ($records->isEmpty()) {
|
if ($records->isEmpty()) {
|
||||||
return response("SUCCESS: Already scanning process completed for the OBD Number", 200)->header('Content-Type', 'text/plain');
|
// return response("SUCCESS: Already scanning process completed for the OBD Number", 200)->header('Content-Type', values: 'text/plain');
|
||||||
|
return response()->json([
|
||||||
|
'status_code' => 'SUCCESS',
|
||||||
|
'status_description' => "Already weight validation completed for the OBD Number"
|
||||||
|
], 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
$itemIds = $records->pluck('item_id')->unique();
|
$itemIds = $records->pluck('item_id')->unique();
|
||||||
@@ -543,7 +634,7 @@ class ObdController extends Controller
|
|||||||
'Material_Code' => $itemInfo->code ?? "",
|
'Material_Code' => $itemInfo->code ?? "",
|
||||||
'Material_Description' => $itemInfo->description ?? "",
|
'Material_Description' => $itemInfo->description ?? "",
|
||||||
'Batch_Number' => $item->batch_number ?? "",
|
'Batch_Number' => $item->batch_number ?? "",
|
||||||
'Heat_Number' => $item->heat_number ?? "",
|
// 'Heat_Number' => $item->heat_number ?? "",
|
||||||
'Actual_Weight' => $item->obd_weight ?? "",
|
'Actual_Weight' => $item->obd_weight ?? "",
|
||||||
];
|
];
|
||||||
})->values()->toArray()
|
})->values()->toArray()
|
||||||
|
|||||||
Reference in New Issue
Block a user