Added uuid logic in vehicle controller
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / Gemini PR Review (pull_request) Has been cancelled
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Has been cancelled
Laravel Larastan / larastan (pull_request) Has been cancelled
Laravel Pint / pint (pull_request) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / Gemini PR Review (pull_request) Has been cancelled
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Has been cancelled
Laravel Larastan / larastan (pull_request) Has been cancelled
Laravel Pint / pint (pull_request) Has been cancelled
This commit is contained in:
@@ -57,101 +57,126 @@ class VehicleController extends Controller
|
|||||||
|
|
||||||
$plantId = $plantCod->id;
|
$plantId = $plantCod->id;
|
||||||
|
|
||||||
$data = $request->all();
|
// $data = $request->all();
|
||||||
|
|
||||||
$vehicleNo = $data['vehicle_number'] ?? '';
|
$data = $request->json()->all();
|
||||||
$entryTimeRaw = $data['entry_time'] ?? '';
|
|
||||||
$exitTimeRaw = $data['exit_time'] ?? '';
|
|
||||||
$duration = $data['duration'] ?? '';
|
|
||||||
$type = $data['type'] ?? '';
|
|
||||||
|
|
||||||
if(!$vehicleNo)
|
$results = [];
|
||||||
{
|
|
||||||
return response()->json([
|
foreach ($data as $item) {
|
||||||
'status' => 'ERROR',
|
|
||||||
'status_description' => "Vehicle number cant't be empty!",
|
$uuid = $item['uuid'] ?? '';
|
||||||
], 404);
|
$vehicleNo = trim($item['vehicle_number'] ?? '');
|
||||||
}
|
$entryTimeRaw = $item['entry_time'] ?? '';
|
||||||
else if (strlen($vehicleNo) < 8) {
|
$exitTimeRaw = $item['exit_time'] ?? '';
|
||||||
return response()->json([
|
$duration = $item['duration'] ?? '';
|
||||||
'status' => 'ERROR',
|
$type = $item['type'] ?? '';
|
||||||
'status_description' => "vehicle number '$vehicleNo' must be at least 8 characters long",
|
|
||||||
], 404);
|
// vehicle number validation
|
||||||
}
|
if (!$vehicleNo) {
|
||||||
else if(!$entryTimeRaw)
|
|
||||||
{
|
$results[] = [
|
||||||
return response()->json([
|
'uuid' => $uuid,
|
||||||
'status' => 'ERROR',
|
'status_code' => 'ERROR',
|
||||||
'status_description' => "Entry time cant't be empty!",
|
'status_description' => "Vehicle number can't be empty!"
|
||||||
], 404);
|
];
|
||||||
}
|
|
||||||
// else if(!$exitTimeRaw)
|
continue;
|
||||||
// {
|
}
|
||||||
// return response()->json([
|
|
||||||
// 'status' => 'ERROR',
|
if (strlen($vehicleNo) < 8) {
|
||||||
// 'status_description' => "Exit time cant't be empty!",
|
|
||||||
// ], 404);
|
$results[] = [
|
||||||
// }
|
'uuid' => $uuid,
|
||||||
// else if(!$duration)
|
'status_code' => 'ERROR',
|
||||||
// {
|
'status_description' => "Vehicle number '$vehicleNo' must be at least 8 characters long"
|
||||||
// return response()->json([
|
];
|
||||||
// 'status' => 'ERROR',
|
|
||||||
// 'status_description' => "Duration cant't be empty!",
|
continue;
|
||||||
// ], 404);
|
}
|
||||||
// }
|
|
||||||
else if(!$type)
|
// entry time validation
|
||||||
{
|
if (!$entryTimeRaw) {
|
||||||
return response()->json([
|
|
||||||
'status' => 'ERROR',
|
$results[] = [
|
||||||
'status_description' => "type cant't be empty!",
|
'uuid' => $uuid,
|
||||||
], 404);
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Entry time can't be empty!"
|
||||||
|
];
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// type validation
|
||||||
|
if (!$type) {
|
||||||
|
|
||||||
|
$results[] = [
|
||||||
|
'uuid' => $uuid,
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Type can't be empty!"
|
||||||
|
];
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// duration validation
|
||||||
|
if ($duration && !preg_match('/^\d{2}:\d{2}:\d{2}$/', $duration)) {
|
||||||
|
|
||||||
|
$results[] = [
|
||||||
|
'uuid' => $uuid,
|
||||||
|
'status_code' => 'ERROR',
|
||||||
|
'status_description' => "Invalid duration format $duration"
|
||||||
|
];
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($entryTimeRaw && !Carbon::hasFormat($entryTimeRaw, 'd/m/Y h:i:s A')) {
|
if(!empty($results)){
|
||||||
return response()->json([
|
return response()->json($results, 404);
|
||||||
'status' => 'ERROR',
|
|
||||||
'status_description' => "Invalid Entry time format $entryTimeRaw. Expected dd/mm/yyyy hh:mm:ss AM/PM",
|
|
||||||
], 404);
|
|
||||||
}
|
|
||||||
else if ($exitTimeRaw && !Carbon::hasFormat($exitTimeRaw, 'd/m/Y h:i:s A')) {
|
|
||||||
return response()->json([
|
|
||||||
'status' => 'ERROR',
|
|
||||||
'status_description' => "Invalid Exit time format $exitTimeRaw. Expected dd/mm/yyyy hh:mm:ss AM/PM",
|
|
||||||
], 404);
|
|
||||||
}
|
|
||||||
else if ($duration && !preg_match('/^\d{2}:\d{2}:\d{2}$/', $duration)) {
|
|
||||||
return response()->json([
|
|
||||||
'status' => 'ERROR',
|
|
||||||
'status_description' => "Invalid duration format $duration. Expected HH:MM:SS",
|
|
||||||
], 404);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($entryTimeRaw)){
|
foreach ($data as $item) {
|
||||||
$entryTime = $entryTimeRaw
|
|
||||||
? Carbon::createFromFormat('d/m/Y h:i:s A', $entryTimeRaw)
|
$uuid = $item['uuid'] ?? '';
|
||||||
: null;
|
$vehicleNo = trim($item['vehicle_number'] ?? '');
|
||||||
|
$entryTimeRaw = $item['entry_time'] ?? '';
|
||||||
|
$exitTimeRaw = $item['exit_time'] ?? '';
|
||||||
|
$duration = $item['duration'] ?? '';
|
||||||
|
$type = $item['type'] ?? '';
|
||||||
|
|
||||||
|
if(!empty($entryTimeRaw)){
|
||||||
|
$entryTime = $entryTimeRaw
|
||||||
|
? Carbon::createFromFormat('d/m/Y h:i:s A', $entryTimeRaw)
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$exitTime = null;
|
||||||
|
|
||||||
|
if(!empty($exitTimeRaw)){
|
||||||
|
|
||||||
|
$exitTime = $exitTimeRaw
|
||||||
|
? Carbon::createFromFormat('d/m/Y h:i:s A', $exitTimeRaw)
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$record = VehicleEntry::updateOrInsert(
|
||||||
|
[
|
||||||
|
'uuid' => $uuid
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'plant_id' => $plantId,
|
||||||
|
'vehicle_number' => $vehicleNo,
|
||||||
|
'entry_time' => $entryTime,
|
||||||
|
'exit_time' => $exitTime ?? null,
|
||||||
|
'duration' => $duration ?: null,
|
||||||
|
'type' => $type,
|
||||||
|
'updated_at' => now(),
|
||||||
|
'created_at' => now(),
|
||||||
|
]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$exitTime = null;
|
|
||||||
|
|
||||||
if(!empty($exitTimeRaw)){
|
|
||||||
|
|
||||||
$exitTime = $exitTimeRaw
|
|
||||||
? Carbon::createFromFormat('d/m/Y h:i:s A', $exitTimeRaw)
|
|
||||||
: null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$record = VehicleEntry::insert([
|
|
||||||
'plant_id' => $plantId,
|
|
||||||
'vehicle_number' => $vehicleNo,
|
|
||||||
'entry_time' => $entryTime,
|
|
||||||
'exit_time' => $exitTime ?? null,
|
|
||||||
'duration' => $duration ?: null,
|
|
||||||
'type' => $type,
|
|
||||||
'created_at' => now(),
|
|
||||||
'updated_at' => now(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
if($record){
|
if($record){
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status' => 'SUCCESS',
|
'status' => 'SUCCESS',
|
||||||
|
|||||||
Reference in New Issue
Block a user