ranjith-dev #442
@@ -13,10 +13,7 @@ class ObdController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index() {}
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
@@ -24,36 +21,40 @@ class ObdController extends Controller
|
|||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$expectedUser = env('API_AUTH_USER');
|
$expectedUser = env('API_AUTH_USER');
|
||||||
$expectedPw = env('API_AUTH_PW');
|
$expectedPw = env('API_AUTH_PW');
|
||||||
|
|
||||||
$header_auth = $request->header('Authorization');
|
$header_auth = $request->header('Authorization');
|
||||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
$expectedToken = $expectedUser.':'.$expectedPw;
|
||||||
|
|
||||||
// if("Bearer " . $expectedToken != $header_auth)
|
// if("Bearer " . $expectedToken != $header_auth)
|
||||||
// {
|
// {
|
||||||
// return response("ERROR: Unauthorized", 403)
|
// return response("ERROR: Unauthorized", 403)
|
||||||
// ->header('Content-Type', 'text/plain');
|
// ->header('Content-Type', 'text/plain');
|
||||||
// }
|
// }
|
||||||
if ("Bearer " . $expectedToken != $header_auth)
|
if ('Bearer '.$expectedToken != $header_auth) {
|
||||||
{
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => 'Invalid authorization token!'
|
'status_description' => 'Invalid authorization token!',
|
||||||
], 403);
|
], 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
$data = $request->all();
|
$data = $request->all();
|
||||||
// Validate required fields
|
// Validate required fields
|
||||||
$missing = [];
|
$missing = [];
|
||||||
if (empty($data['plant_name'])) $missing[] = 'plant_name';
|
if (empty($data['plant_name'])) {
|
||||||
if (empty($data['obd_number'])) $missing[] = 'obd_number';
|
$missing[] = 'plant_name';
|
||||||
if (empty($data['line_numbers'])) $missing[] = 'line_numbers';
|
}
|
||||||
|
if (empty($data['obd_number'])) {
|
||||||
|
$missing[] = 'obd_number';
|
||||||
|
}
|
||||||
|
if (empty($data['line_numbers'])) {
|
||||||
|
$missing[] = 'line_numbers';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! empty($missing)) {
|
||||||
|
$message = 'Missing required field(s): '.implode(', ', $missing);
|
||||||
|
|
||||||
if (!empty($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([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
@@ -63,53 +64,49 @@ class ObdController extends Controller
|
|||||||
|
|
||||||
// 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([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => "OBD number should contain minimum 8 digit alpha-numeric values only!"
|
'status_description' => 'OBD number should contain minimum 8 digit alpha-numeric values only!',
|
||||||
], 400);
|
], 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([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => "Plant '{$data['plant_name']}' not found!"
|
'status_description' => "Plant '{$data['plant_name']}' not found!",
|
||||||
], 404);
|
], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if OBD number exists for that plant
|
// Check if OBD number exists for that plant
|
||||||
$obdRecords = WeightValidation::where('plant_id', $plantId)
|
$obdRecords = WeightValidation::where('plant_id', $plantId)
|
||||||
->where('obd_number', $obdNumber)
|
->where('obd_number', $obdNumber)
|
||||||
->exists();
|
->exists();
|
||||||
|
|
||||||
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([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => "OBD Number '$obdNumber' not found for plant '{$data['plant_name']}'!"
|
'status_description' => "OBD Number '$obdNumber' not found for plant '{$data['plant_name']}'!",
|
||||||
], 404);
|
], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
$missingLines = [];
|
$missingLines = [];
|
||||||
$alreadyUpdatedLines = [];
|
$alreadyUpdatedLines = [];
|
||||||
|
|
||||||
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)
|
// return response("ERROR: Line Number can't be empty", 400)
|
||||||
// ->header('Content-Type', 'text/plain');
|
// ->header('Content-Type', 'text/plain');
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => "Line Number can't be empty!"
|
'status_description' => "Line Number can't be empty!",
|
||||||
], 404);
|
], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,50 +115,46 @@ class ObdController extends Controller
|
|||||||
->where('line_number', $line['line_number'])
|
->where('line_number', $line['line_number'])
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if (!$record)
|
if (! $record) {
|
||||||
{
|
|
||||||
$missingLines[] = $line['line_number'];
|
$missingLines[] = $line['line_number'];
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$mandatoryFields = ['vehicle_number', 'bundle_number', 'heat_number', 'picked_weight', 'scanned_by'];
|
$mandatoryFields = ['vehicle_number', 'bundle_number', 'heat_number', 'picked_weight', 'scanned_by'];
|
||||||
$missingFields = [];
|
$missingFields = [];
|
||||||
|
|
||||||
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($missingFields))
|
if (! empty($missingFields)) {
|
||||||
{
|
if (count($missingFields) == 1) {
|
||||||
if (count($missingFields) == 1)
|
|
||||||
{
|
|
||||||
$fieldsString = $missingFields[0];
|
$fieldsString = $missingFields[0];
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$lastField = array_pop($missingFields);
|
$lastField = array_pop($missingFields);
|
||||||
$fieldsString = implode(', ', $missingFields) . ' and ' . $lastField;
|
$fieldsString = implode(', ', $missingFields).' and '.$lastField;
|
||||||
}
|
}
|
||||||
|
|
||||||
$message = $fieldsString . " can't be empty for line_number {$line['line_number']}!";
|
$message = $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([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => $message
|
'status_description' => $message,
|
||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($missingLines)) {
|
if (! empty($missingLines)) {
|
||||||
$message = "Line(s) " . implode(', ', $missingLines) . " not found for Plant '{$data['plant_name']}' and OBD Number: '{$data['obd_number']}'!";
|
$message = '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([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => $message
|
'status_description' => $message,
|
||||||
], 404);
|
], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,11 +162,11 @@ class ObdController extends Controller
|
|||||||
$internalDuplicates = [];
|
$internalDuplicates = [];
|
||||||
$bundleChecks = [];
|
$bundleChecks = [];
|
||||||
|
|
||||||
//Check for duplicates within the request
|
// Check for duplicates within the request
|
||||||
foreach ($data['line_numbers'] as $line) {
|
foreach ($data['line_numbers'] as $line) {
|
||||||
$lineNumber = $line['line_number'];
|
$lineNumber = $line['line_number'];
|
||||||
$bundleNumber = trim((string)$line['bundle_number']);
|
$bundleNumber = trim((string) $line['bundle_number']);
|
||||||
$pairKey = $lineNumber . '|' . $bundleNumber;
|
$pairKey = $lineNumber.'|'.$bundleNumber;
|
||||||
|
|
||||||
if (isset($seenPairs[$pairKey])) {
|
if (isset($seenPairs[$pairKey])) {
|
||||||
$internalDuplicates[] = "Line Number {$lineNumber} with Bundle Number {$bundleNumber}";
|
$internalDuplicates[] = "Line Number {$lineNumber} with Bundle Number {$bundleNumber}";
|
||||||
@@ -186,7 +179,7 @@ class ObdController extends Controller
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check for duplicates in the database
|
// Check for duplicates in the database
|
||||||
|
|
||||||
$bundleNumbers = array_column($bundleChecks, 'bundle_number');
|
$bundleNumbers = array_column($bundleChecks, 'bundle_number');
|
||||||
$lineNumbers = array_column($bundleChecks, 'line_number');
|
$lineNumbers = array_column($bundleChecks, 'line_number');
|
||||||
@@ -202,10 +195,10 @@ class ObdController extends Controller
|
|||||||
$line = $row->line_number;
|
$line = $row->line_number;
|
||||||
$bundle = $row->bundle_number;
|
$bundle = $row->bundle_number;
|
||||||
|
|
||||||
if (!isset($grouped[$line])) {
|
if (! isset($grouped[$line])) {
|
||||||
$grouped[$line] = [];
|
$grouped[$line] = [];
|
||||||
}
|
}
|
||||||
if ($bundle && !in_array($bundle, $grouped[$line])) {
|
if ($bundle && ! in_array($bundle, $grouped[$line])) {
|
||||||
$grouped[$line][] = $bundle;
|
$grouped[$line][] = $bundle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,85 +209,80 @@ class ObdController extends Controller
|
|||||||
$dbDuplicates[] = "Line {$line}, has bundle numbers : {$bundlesStr}";
|
$dbDuplicates[] = "Line {$line}, has bundle numbers : {$bundlesStr}";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Return all errors if any duplicates found
|
// Return all errors if any duplicates found
|
||||||
$allDuplicates = [];
|
$allDuplicates = [];
|
||||||
if (!empty($internalDuplicates))
|
if (! empty($internalDuplicates)) {
|
||||||
{
|
$allDuplicates[] = 'Duplicate(s) '.implode(', ', $internalDuplicates);
|
||||||
$allDuplicates[] = "Duplicate(s) " . implode(', ', $internalDuplicates);
|
|
||||||
}
|
}
|
||||||
if (!empty($dbDuplicates))
|
if (! empty($dbDuplicates)) {
|
||||||
{
|
$allDuplicates[] = 'Already exists in database: '.implode('; ', $dbDuplicates);
|
||||||
$allDuplicates[] = "Already exists in database: " . implode('; ', $dbDuplicates);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($allDuplicates)) {
|
if (! empty($allDuplicates)) {
|
||||||
// return response(
|
// return response(
|
||||||
// "Error:" . implode("\n", $allDuplicates),
|
// "Error:" . implode("\n", $allDuplicates),
|
||||||
// 400
|
// 400
|
||||||
// )->header('Content-Type', 'text/plain');
|
// )->header('Content-Type', 'text/plain');
|
||||||
|
|
||||||
$retRes = implode(", and ", $allDuplicates);
|
$retRes = implode(', and ', $allDuplicates);
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => $retRes
|
'status_description' => $retRes,
|
||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
//..
|
// ..
|
||||||
$updated = 0;
|
$updated = 0;
|
||||||
$inserted = 0;
|
$inserted = 0;
|
||||||
$updatedLines = [];
|
$updatedLines = [];
|
||||||
$insertedLines = [];
|
$insertedLines = [];
|
||||||
$lineTracker = [];
|
$lineTracker = [];
|
||||||
|
|
||||||
foreach ($data['line_numbers'] as $line)
|
foreach ($data['line_numbers'] as $line) {
|
||||||
{
|
|
||||||
$lineNumber = $line['line_number'];
|
$lineNumber = $line['line_number'];
|
||||||
$existing = WeightValidation::where('plant_id', $plantId)
|
$existing = WeightValidation::where('plant_id', $plantId)
|
||||||
->where('obd_number', $obdNumber)
|
->where('obd_number', $obdNumber)
|
||||||
->where('line_number', $lineNumber)
|
->where('line_number', $lineNumber)
|
||||||
->where(function ($query) {
|
->where(function ($query) {
|
||||||
$query->whereNull('bundle_number')
|
$query->whereNull('bundle_number')
|
||||||
->orWhere('bundle_number', '');
|
->orWhere('bundle_number', '');
|
||||||
})
|
})
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if($existing)
|
if ($existing) {
|
||||||
{
|
|
||||||
$existing->update([
|
$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,
|
'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++;
|
$updated++;
|
||||||
$updatedLines[] = $lineNumber;
|
$updatedLines[] = $lineNumber;
|
||||||
$lineTracker[$lineNumber] = 1;
|
$lineTracker[$lineNumber] = 1;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$original = WeightValidation::where([
|
$original = WeightValidation::where([
|
||||||
'plant_id' => $plantId,
|
'plant_id' => $plantId,
|
||||||
'obd_number' => $obdNumber,
|
'obd_number' => $obdNumber,
|
||||||
'line_number' => $lineNumber,
|
'line_number' => $lineNumber,
|
||||||
])->orderBy('id')->first();
|
])->orderBy('id')->first();
|
||||||
|
|
||||||
WeightValidation::create([
|
WeightValidation::create([
|
||||||
'plant_id' => $plantId,
|
'plant_id' => $plantId,
|
||||||
'obd_number' => $obdNumber,
|
'obd_number' => $obdNumber,
|
||||||
'line_number' => $lineNumber,
|
'line_number' => $lineNumber,
|
||||||
'item_id' => $original->item_id ?? null,
|
'item_id' => $original->item_id ?? null,
|
||||||
'vehicle_number' => $line['vehicle_number'] ?? null,
|
'vehicle_number' => $line['vehicle_number'] ?? null,
|
||||||
'bundle_number' => $line['bundle_number'] ?? null,
|
'bundle_number' => $line['bundle_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,
|
||||||
'batch_number' => $original->batch_number ?? null,
|
'batch_number' => $original->batch_number ?? null,
|
||||||
'heat_number' => $line['heat_number'] ?? null,
|
'heat_number' => $line['heat_number'] ?? null,
|
||||||
'obd_weight' => $original->obd_weight ?? null,
|
'obd_weight' => $original->obd_weight ?? null,
|
||||||
'created_at' => now(),
|
'created_at' => now(),
|
||||||
'updated_at' => now(),
|
'updated_at' => now(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$inserted++;
|
$inserted++;
|
||||||
@@ -306,11 +294,11 @@ class ObdController extends Controller
|
|||||||
$responseMessage = "OBD Number '{$obdNumber}'";
|
$responseMessage = "OBD Number '{$obdNumber}'";
|
||||||
|
|
||||||
if ($updated > 0) {
|
if ($updated > 0) {
|
||||||
$responseMessage .= " updated successfully. Line Numbers: {" . implode(', ', $updatedLines) . "}";
|
$responseMessage .= ' updated successfully. Line Numbers: {'.implode(', ', $updatedLines).'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($inserted > 0) {
|
if ($inserted > 0) {
|
||||||
$responseMessage .= "Inserted successfully. Line Numbers: {" . implode(', ', $insertedLines) . "}";
|
$responseMessage .= 'Inserted successfully. Line Numbers: {'.implode(', ', $insertedLines).'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
// return response($responseMessage, 200)
|
// return response($responseMessage, 200)
|
||||||
@@ -320,31 +308,28 @@ class ObdController extends Controller
|
|||||||
'status_description' => $responseMessage,
|
'status_description' => $responseMessage,
|
||||||
], 200);
|
], 200);
|
||||||
|
|
||||||
}
|
} catch (\Exception $e) {
|
||||||
catch (\Exception $e)
|
|
||||||
{
|
|
||||||
// response("ERROR: Server error", 500)->header('Content-Type', 'text/plain');
|
// response("ERROR: Server error", 500)->header('Content-Type', 'text/plain');
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => 'Store OBD data internal server error : '.$e?->getCode()
|
'status_description' => 'Store OBD data internal server error : '.$e?->getCode(),
|
||||||
], 500);
|
], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Route::get('obd/get-test-datas', [ObdController::class, 'get_test']);
|
// Route::get('obd/get-test-datas', [ObdController::class, 'get_test']);
|
||||||
public function get_test(Request $request)
|
public function get_test(Request $request)
|
||||||
{
|
{
|
||||||
$expectedUser = env('API_AUTH_USER');
|
$expectedUser = env('API_AUTH_USER');
|
||||||
$expectedPw = env('API_AUTH_PW');
|
$expectedPw = env('API_AUTH_PW');
|
||||||
|
|
||||||
$header_auth = $request->header('Authorization');
|
$header_auth = $request->header('Authorization');
|
||||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
$expectedToken = $expectedUser.':'.$expectedPw;
|
||||||
|
|
||||||
if ("Bearer " . $expectedToken != $header_auth)
|
if ('Bearer '.$expectedToken != $header_auth) {
|
||||||
{
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => 'Invalid authorization token!'
|
'status_description' => 'Invalid authorization token!',
|
||||||
], 403);
|
], 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -374,48 +359,41 @@ class ObdController extends Controller
|
|||||||
// ], 400);
|
// ], 400);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
$productionOrder = $request->header('production-order');
|
$productionOrder = $request->header('production-order');
|
||||||
if (empty($productionOrder))
|
if (empty($productionOrder)) {
|
||||||
{
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => "Production order can't be empty!"
|
'status_description' => "Production order can't be empty!",
|
||||||
], 400);
|
], 400);
|
||||||
}
|
} elseif (Str::length($productionOrder) < 7 || ! is_numeric($productionOrder)) {
|
||||||
else if(Str::length($productionOrder) < 7 || !is_numeric($productionOrder))
|
|
||||||
{
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => "Production order should contain minimum 7 digits numeric values only!"
|
'status_description' => 'Production order should contain minimum 7 digits numeric values only!',
|
||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$prodOrderExist = ($productionOrder == '1234567' || $productionOrder == '7654321');
|
$prodOrderExist = ($productionOrder == '1234567' || $productionOrder == '7654321');
|
||||||
|
|
||||||
if (!$prodOrderExist)
|
if (! $prodOrderExist) {
|
||||||
{
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => "Production order not found!"
|
'status_description' => 'Production order not found!',
|
||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
// return response("Successfully GET request Received", 200)->header('Content-Type', 'text/plain');
|
||||||
//return response("Successfully GET request Received", 200)->header('Content-Type', 'text/plain');
|
|
||||||
$itemCode = Item::where('code', '123456')->where('plant_id', 1)->first();
|
$itemCode = Item::where('code', '123456')->where('plant_id', 1)->first();
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'item_code' => $itemCode->code,
|
'item_code' => $itemCode->code,
|
||||||
'item_description' => $itemCode->description
|
'item_description' => $itemCode->description,
|
||||||
], 200);
|
], 200);
|
||||||
}
|
} catch (\Exception $e) {
|
||||||
catch (\Exception $e)
|
// return response("ERROR: GET test data server error", 500)->header('Content-Type', 'text/plain');
|
||||||
{
|
|
||||||
//return response("ERROR: GET test data server error", 500)->header('Content-Type', 'text/plain');
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => 'Get test data internal server error : '.$e?->getCode()
|
'status_description' => 'Get test data internal server error : '.$e?->getCode(),
|
||||||
], 500);
|
], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -423,9 +401,9 @@ class ObdController extends Controller
|
|||||||
public function get_obd(Request $request)
|
public function get_obd(Request $request)
|
||||||
{
|
{
|
||||||
$expectedUser = env('API_AUTH_USER');
|
$expectedUser = env('API_AUTH_USER');
|
||||||
$expectedPw = env('API_AUTH_PW');
|
$expectedPw = env('API_AUTH_PW');
|
||||||
$header_auth = $request->header('Authorization');
|
$header_auth = $request->header('Authorization');
|
||||||
$expectedToken = $expectedUser . ':' . $expectedPw;
|
$expectedToken = $expectedUser.':'.$expectedPw;
|
||||||
|
|
||||||
// if ("Bearer " . $expectedToken != $header_auth)
|
// if ("Bearer " . $expectedToken != $header_auth)
|
||||||
// {
|
// {
|
||||||
@@ -433,88 +411,81 @@ class ObdController extends Controller
|
|||||||
// ->header('Content-Type', 'text/plain');
|
// ->header('Content-Type', 'text/plain');
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if ("Bearer " . $expectedToken != $header_auth)
|
if ('Bearer '.$expectedToken != $header_auth) {
|
||||||
{
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => 'Invalid authorization token!'
|
'status_description' => 'Invalid authorization token!',
|
||||||
], 403);
|
], 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
$plantName = $request->header('plant-name');
|
$plantName = $request->header('plant-name');
|
||||||
$obdNumber = $request->header('obd-number');
|
$obdNumber = $request->header('obd-number');
|
||||||
|
|
||||||
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([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => "Plant Name can't be empty!"
|
'status_description' => "Plant Name can't be empty!",
|
||||||
], 400);
|
], 400);
|
||||||
}
|
} elseif (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([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => "OBD Number can't be empty!"
|
'status_description' => "OBD Number can't be empty!",
|
||||||
], 400);
|
], 400);
|
||||||
}
|
} elseif (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([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => "OBD number should contain minimum 8 digit alpha-numeric values only!"
|
'status_description' => 'OBD number should contain minimum 8 digit alpha-numeric values only!',
|
||||||
], 400);
|
], 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([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => "Plant not found!"
|
'status_description' => 'Plant not found!',
|
||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
// $records = WeightValidation::where('plant_id', $plantId)
|
// $records = WeightValidation::where('plant_id', $plantId)
|
||||||
// ->where('obd_number', $obdNumber)
|
// ->where('obd_number', $obdNumber)
|
||||||
// ->get();
|
// ->get();
|
||||||
// Fetch and filter records where vehicle_number is empty or null
|
// Fetch and filter records where vehicle_number is empty or null
|
||||||
|
|
||||||
$exists = WeightValidation::where('plant_id', $plantId)
|
$exists = WeightValidation::where('plant_id', $plantId)
|
||||||
->where('obd_number', $obdNumber)
|
->where('obd_number', $obdNumber)
|
||||||
->exists();
|
->exists();
|
||||||
|
|
||||||
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([
|
return response()->json([
|
||||||
'status_code' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => "OBD number $obdNumber does not exist for plant '$plantName'!"
|
'status_description' => "OBD number $obdNumber does not exist for plant '$plantName'!",
|
||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$records = WeightValidation::where('plant_id', $plantId)
|
$records = WeightValidation::where('plant_id', $plantId)
|
||||||
->where('obd_number', $obdNumber)
|
->where('obd_number', $obdNumber)
|
||||||
->get()
|
->get()
|
||||||
->filter(function ($record) {
|
->filter(function ($record) {
|
||||||
return $record->vehicle_number == '' || $record->vehicle_number == null;
|
return $record->vehicle_number == '' || $record->vehicle_number == null;
|
||||||
});
|
});
|
||||||
|
|
||||||
if ($records->isEmpty()) {
|
if ($records->isEmpty()) {
|
||||||
// return response("SUCCESS: Already scanning process completed for the OBD Number", 200)->header('Content-Type', values: 'text/plain');
|
// return response("SUCCESS: Already scanning process completed for the OBD Number", 200)->header('Content-Type', values: 'text/plain');
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status_code' => 'SUCCESS',
|
'status_code' => 'SUCCESS',
|
||||||
'status_description' => "Already weight validation completed for the OBD Number!"
|
'status_description' => 'Already weight validation completed for the OBD Number!',
|
||||||
], 200);
|
], 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -530,18 +501,20 @@ class ObdController extends Controller
|
|||||||
'OBD_Number' => $obdNumber,
|
'OBD_Number' => $obdNumber,
|
||||||
'Line_Numbers' => $records->map(function ($item) use ($itemCodes) {
|
'Line_Numbers' => $records->map(function ($item) use ($itemCodes) {
|
||||||
$itemInfo = $itemCodes[$item->item_id] ?? null;
|
$itemInfo = $itemCodes[$item->item_id] ?? null;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'Line' => $item->line_number ?? "",
|
'Line' => $item->line_number ?? '',
|
||||||
'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(),
|
||||||
]
|
],
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
return response()->json($ObdResponseStructure);
|
return response()->json($ObdResponseStructure);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,17 +44,17 @@ class PalletPrintController extends Controller
|
|||||||
// ->values();
|
// ->values();
|
||||||
|
|
||||||
$items = WireMasterPacking::with('item')
|
$items = WireMasterPacking::with('item')
|
||||||
->where('plant_id', $plant)
|
->where('plant_id', $plant)
|
||||||
->where('wire_packing_number', $pallet)
|
->where('wire_packing_number', $pallet)
|
||||||
->get()
|
->get()
|
||||||
->map(function ($row) {
|
->map(function ($row) {
|
||||||
return (object) [
|
return (object) [
|
||||||
'code' => $row->item->code,
|
'code' => $row->item->code,
|
||||||
'description' => $row->item->description,
|
'description' => $row->item->description,
|
||||||
'box_count' => 1, // each row = one box
|
'box_count' => 1, // each row = one box
|
||||||
'weight' => $row->weight,
|
'weight' => $row->weight,
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
$masterBox = WireMasterPacking::where('plant_id', $plant)
|
$masterBox = WireMasterPacking::where('plant_id', $plant)
|
||||||
->where('wire_packing_number', $pallet)
|
->where('wire_packing_number', $pallet)
|
||||||
@@ -105,12 +105,11 @@ class PalletPrintController extends Controller
|
|||||||
->pluck('wire_packing_number')
|
->pluck('wire_packing_number')
|
||||||
->values();
|
->values();
|
||||||
|
|
||||||
|
|
||||||
$index = $completedPallets->search($pallet);
|
$index = $completedPallets->search($pallet);
|
||||||
|
|
||||||
$currentPalletNo = ($index !== false) ? $index + 1 : 0;
|
$currentPalletNo = ($index != false) ? $index + 1 : 0;
|
||||||
|
|
||||||
$boxLabel = $currentPalletNo . '/' . $totalBoxes;
|
$boxLabel = $currentPalletNo.'/'.$totalBoxes;
|
||||||
|
|
||||||
// $completedPallets = WireMasterPacking::where('plant_id', $plant)
|
// $completedPallets = WireMasterPacking::where('plant_id', $plant)
|
||||||
// ->select('wire_packing_number')
|
// ->select('wire_packing_number')
|
||||||
@@ -127,7 +126,7 @@ class PalletPrintController extends Controller
|
|||||||
// $boxLabel = $currentPalletNo . '/' . $totalBoxes;
|
// $boxLabel = $currentPalletNo . '/' . $totalBoxes;
|
||||||
|
|
||||||
$grossWeight = $items->sum('weight');
|
$grossWeight = $items->sum('weight');
|
||||||
$widthPt = 85 * 2.83465; // 85mm → points
|
$widthPt = 85 * 2.83465; // 85mm → points
|
||||||
$heightPt = 100 * 2.83465; // 100mm → points
|
$heightPt = 100 * 2.83465; // 100mm → points
|
||||||
|
|
||||||
$plantName = Plant::where('id', $plant)->value('name');
|
$plantName = Plant::where('id', $plant)->value('name');
|
||||||
@@ -135,18 +134,18 @@ class PalletPrintController extends Controller
|
|||||||
$plantAddress = Plant::where('id', $plant)->value('address');
|
$plantAddress = Plant::where('id', $plant)->value('address');
|
||||||
|
|
||||||
$pdf = Pdf::loadView('pdf.wire-pallet', [
|
$pdf = Pdf::loadView('pdf.wire-pallet', [
|
||||||
'product' => 'Submersible Winding Wire',
|
'product' => 'Submersible Winding Wire',
|
||||||
'plantName' => $plantName,
|
'plantName' => $plantName,
|
||||||
'plantAddress' => $plantAddress,
|
'plantAddress' => $plantAddress,
|
||||||
'monthYear' => now()->format('M-y'),
|
'monthYear' => now()->format('M-y'),
|
||||||
'branch' => '',
|
'branch' => '',
|
||||||
'customerCode' => $customerCode,
|
'customerCode' => $customerCode,
|
||||||
'customerName' => $customerName,
|
'customerName' => $customerName,
|
||||||
'masterBox' => $boxLabel,
|
'masterBox' => $boxLabel,
|
||||||
'items' => $items,
|
'items' => $items,
|
||||||
'grossWeight' => $grossWeight,
|
'grossWeight' => $grossWeight,
|
||||||
'netWeight' => $grossWeight - 3.05,
|
'netWeight' => $grossWeight - 3.05,
|
||||||
'pallet' => $pallet,
|
'pallet' => $pallet,
|
||||||
])->setPaper([0, 0, $widthPt, $heightPt], 'portrait');
|
])->setPaper([0, 0, $widthPt, $heightPt], 'portrait');
|
||||||
|
|
||||||
return $pdf->stream("Pallet-{$pallet}.pdf");
|
return $pdf->stream("Pallet-{$pallet}.pdf");
|
||||||
@@ -178,7 +177,6 @@ class PalletPrintController extends Controller
|
|||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// public function print(Request $request, $pallet, $plant)
|
// public function print(Request $request, $pallet, $plant)
|
||||||
// {
|
// {
|
||||||
// $customerId = $request->query('customer');
|
// $customerId = $request->query('customer');
|
||||||
@@ -205,7 +203,6 @@ class PalletPrintController extends Controller
|
|||||||
// $customerCode = $customer->customer_po ?? '';
|
// $customerCode = $customer->customer_po ?? '';
|
||||||
// $customerName = $customer->customer_name ?? '';
|
// $customerName = $customer->customer_name ?? '';
|
||||||
|
|
||||||
|
|
||||||
// $totalBoxes = WireMasterPacking::where('plant_id', $plant)
|
// $totalBoxes = WireMasterPacking::where('plant_id', $plant)
|
||||||
// ->where('customer_po_master_id', $customerId)
|
// ->where('customer_po_master_id', $customerId)
|
||||||
// ->distinct('wire_packing_number')
|
// ->distinct('wire_packing_number')
|
||||||
@@ -223,7 +220,6 @@ class PalletPrintController extends Controller
|
|||||||
// ->pluck('wire_packing_number')
|
// ->pluck('wire_packing_number')
|
||||||
// ->values();
|
// ->values();
|
||||||
|
|
||||||
|
|
||||||
// $index = $completedPallets->search($pallet);
|
// $index = $completedPallets->search($pallet);
|
||||||
|
|
||||||
// $currentPalletNo = ($index !== false) ? $index + 1 : 0;
|
// $currentPalletNo = ($index !== false) ? $index + 1 : 0;
|
||||||
|
|||||||
@@ -77,14 +77,6 @@ class ProductionStickerReprintController extends Controller
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// if ($item->category == 'Submersible Motor')
|
|
||||||
// {
|
|
||||||
// $copies = 1;
|
|
||||||
// }
|
|
||||||
// elseif ($item->category == 'Submersible Pump')
|
|
||||||
// {
|
|
||||||
// $copies = 1;
|
|
||||||
// }
|
|
||||||
$copies = 1;
|
$copies = 1;
|
||||||
|
|
||||||
if ($serialNumberRaw) {
|
if ($serialNumberRaw) {
|
||||||
|
|||||||
@@ -195,5 +195,7 @@ class PermissionSeeder extends Seeder
|
|||||||
Permission::updateOrCreate(['name' => 'view production target page']);
|
Permission::updateOrCreate(['name' => 'view production target page']);
|
||||||
|
|
||||||
Permission::updateOrCreate(['name' => 'view wire master print page']);
|
Permission::updateOrCreate(['name' => 'view wire master print page']);
|
||||||
|
Permission::updateOrCreate(['name' => 'view cycle count page']);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user