Merge pull request 'Added uuid logic in vehicle controller' (#586) from ranjith-dev into master
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Reviewed-on: #586
This commit was merged in pull request #586.
This commit is contained in:
@@ -57,101 +57,126 @@ class VehicleController extends Controller
|
||||
|
||||
$plantId = $plantCod->id;
|
||||
|
||||
$data = $request->all();
|
||||
// $data = $request->all();
|
||||
|
||||
$vehicleNo = $data['vehicle_number'] ?? '';
|
||||
$entryTimeRaw = $data['entry_time'] ?? '';
|
||||
$exitTimeRaw = $data['exit_time'] ?? '';
|
||||
$duration = $data['duration'] ?? '';
|
||||
$type = $data['type'] ?? '';
|
||||
$data = $request->json()->all();
|
||||
|
||||
if(!$vehicleNo)
|
||||
{
|
||||
return response()->json([
|
||||
'status' => 'ERROR',
|
||||
'status_description' => "Vehicle number cant't be empty!",
|
||||
], 404);
|
||||
}
|
||||
else if (strlen($vehicleNo) < 8) {
|
||||
return response()->json([
|
||||
'status' => 'ERROR',
|
||||
'status_description' => "vehicle number '$vehicleNo' must be at least 8 characters long",
|
||||
], 404);
|
||||
}
|
||||
else if(!$entryTimeRaw)
|
||||
{
|
||||
return response()->json([
|
||||
'status' => 'ERROR',
|
||||
'status_description' => "Entry time cant't be empty!",
|
||||
], 404);
|
||||
}
|
||||
// else if(!$exitTimeRaw)
|
||||
// {
|
||||
// return response()->json([
|
||||
// 'status' => 'ERROR',
|
||||
// 'status_description' => "Exit time cant't be empty!",
|
||||
// ], 404);
|
||||
// }
|
||||
// else if(!$duration)
|
||||
// {
|
||||
// return response()->json([
|
||||
// 'status' => 'ERROR',
|
||||
// 'status_description' => "Duration cant't be empty!",
|
||||
// ], 404);
|
||||
// }
|
||||
else if(!$type)
|
||||
{
|
||||
return response()->json([
|
||||
'status' => 'ERROR',
|
||||
'status_description' => "type cant't be empty!",
|
||||
], 404);
|
||||
$results = [];
|
||||
|
||||
foreach ($data as $item) {
|
||||
|
||||
$uuid = $item['uuid'] ?? '';
|
||||
$vehicleNo = trim($item['vehicle_number'] ?? '');
|
||||
$entryTimeRaw = $item['entry_time'] ?? '';
|
||||
$exitTimeRaw = $item['exit_time'] ?? '';
|
||||
$duration = $item['duration'] ?? '';
|
||||
$type = $item['type'] ?? '';
|
||||
|
||||
// vehicle number validation
|
||||
if (!$vehicleNo) {
|
||||
|
||||
$results[] = [
|
||||
'uuid' => $uuid,
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Vehicle number can't be empty!"
|
||||
];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strlen($vehicleNo) < 8) {
|
||||
|
||||
$results[] = [
|
||||
'uuid' => $uuid,
|
||||
'status_code' => 'ERROR',
|
||||
'status_description' => "Vehicle number '$vehicleNo' must be at least 8 characters long"
|
||||
];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// entry time validation
|
||||
if (!$entryTimeRaw) {
|
||||
|
||||
$results[] = [
|
||||
'uuid' => $uuid,
|
||||
'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')) {
|
||||
return response()->json([
|
||||
'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($results)){
|
||||
return response()->json($results, 404);
|
||||
}
|
||||
|
||||
if(!empty($entryTimeRaw)){
|
||||
$entryTime = $entryTimeRaw
|
||||
? Carbon::createFromFormat('d/m/Y h:i:s A', $entryTimeRaw)
|
||||
: null;
|
||||
foreach ($data as $item) {
|
||||
|
||||
$uuid = $item['uuid'] ?? '';
|
||||
$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){
|
||||
return response()->json([
|
||||
'status' => 'SUCCESS',
|
||||
|
||||
Reference in New Issue
Block a user