removed exit time as mandatory
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:
@@ -41,12 +41,11 @@ class VehicleController extends Controller
|
|||||||
|
|
||||||
if (!ctype_digit((string) $plantCode)) {
|
if (!ctype_digit((string) $plantCode)) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status' => 'error',
|
'status' => 'ERROR',
|
||||||
'status_description' => "plant code must be $plantCode a numeric value",
|
'status_description' => "plant code must be $plantCode a numeric value",
|
||||||
], 404);
|
], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$plantCod = Plant::where('code', $plantCode)->first();
|
$plantCod = Plant::where('code', $plantCode)->first();
|
||||||
|
|
||||||
if(!$plantCod){
|
if(!$plantCod){
|
||||||
@@ -56,6 +55,20 @@ class VehicleController extends Controller
|
|||||||
], 404);
|
], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// $expectedKeys = ['vehicle_number','entry_time','exit_time','duration','type'];
|
||||||
|
|
||||||
|
// $requestKeys = array_keys($request->all());
|
||||||
|
|
||||||
|
// sort($expectedKeys);
|
||||||
|
// sort($requestKeys);
|
||||||
|
|
||||||
|
// if ($expectedKeys != $requestKeys) {
|
||||||
|
// return response()->json([
|
||||||
|
// 'status' => 'ERROR',
|
||||||
|
// 'status_description' => 'Send proper valid JSON structure'
|
||||||
|
// ], 400);
|
||||||
|
// }
|
||||||
|
|
||||||
$plantId = $plantCod->id;
|
$plantId = $plantCod->id;
|
||||||
|
|
||||||
$data = $request->all();
|
$data = $request->all();
|
||||||
@@ -86,20 +99,20 @@ class VehicleController extends Controller
|
|||||||
'status_description' => "Entry time cant't be empty!",
|
'status_description' => "Entry time cant't be empty!",
|
||||||
], 404);
|
], 404);
|
||||||
}
|
}
|
||||||
else if(!$exitTimeRaw)
|
// else if(!$exitTimeRaw)
|
||||||
{
|
// {
|
||||||
return response()->json([
|
// return response()->json([
|
||||||
'status' => 'ERROR',
|
// 'status' => 'ERROR',
|
||||||
'status_description' => "Exit time cant't be empty!",
|
// 'status_description' => "Exit time cant't be empty!",
|
||||||
], 404);
|
// ], 404);
|
||||||
}
|
// }
|
||||||
else if(!$duration)
|
// else if(!$duration)
|
||||||
{
|
// {
|
||||||
return response()->json([
|
// return response()->json([
|
||||||
'status' => 'ERROR',
|
// 'status' => 'ERROR',
|
||||||
'status_description' => "Duration cant't be empty!",
|
// 'status_description' => "Duration cant't be empty!",
|
||||||
], 404);
|
// ], 404);
|
||||||
}
|
// }
|
||||||
else if(!$type)
|
else if(!$type)
|
||||||
{
|
{
|
||||||
return response()->json([
|
return response()->json([
|
||||||
@@ -108,7 +121,6 @@ class VehicleController extends Controller
|
|||||||
], 404);
|
], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($entryTimeRaw && !Carbon::hasFormat($entryTimeRaw, 'd/m/Y h:i:s A')) {
|
if ($entryTimeRaw && !Carbon::hasFormat($entryTimeRaw, 'd/m/Y h:i:s A')) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status' => 'ERROR',
|
'status' => 'ERROR',
|
||||||
@@ -123,7 +135,7 @@ class VehicleController extends Controller
|
|||||||
}
|
}
|
||||||
else if ($duration && !preg_match('/^\d{2}:\d{2}:\d{2}$/', $duration)) {
|
else if ($duration && !preg_match('/^\d{2}:\d{2}:\d{2}$/', $duration)) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'status' => 'error',
|
'status' => 'ERROR',
|
||||||
'status_description' => "Invalid duration format $duration. Expected HH:MM:SS",
|
'status_description' => "Invalid duration format $duration. Expected HH:MM:SS",
|
||||||
], 404);
|
], 404);
|
||||||
}
|
}
|
||||||
@@ -136,7 +148,7 @@ class VehicleController extends Controller
|
|||||||
? Carbon::createFromFormat('d/m/Y h:i:s A', $exitTimeRaw)
|
? Carbon::createFromFormat('d/m/Y h:i:s A', $exitTimeRaw)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
VehicleEntry::insert([
|
$record = VehicleEntry::insert([
|
||||||
'plant_id' => $plantId,
|
'plant_id' => $plantId,
|
||||||
'vehicle_number' => $vehicleNo,
|
'vehicle_number' => $vehicleNo,
|
||||||
'entry_time' => $entryTime,
|
'entry_time' => $entryTime,
|
||||||
@@ -147,11 +159,19 @@ class VehicleController extends Controller
|
|||||||
'updated_at' => now(),
|
'updated_at' => now(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return response()->json([
|
if($record){
|
||||||
'status' => 'success',
|
return response()->json([
|
||||||
'status_description' => 'Vehicle entry inserted successfully'
|
'status' => 'SUCCESS',
|
||||||
], 200);
|
'status_description' => 'Vehicle entry inserted successfully'
|
||||||
|
], 200);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return response()->json([
|
||||||
|
'status' => 'ERROR',
|
||||||
|
'status_description' => 'Failed to insert record in the table vehicle entry'
|
||||||
|
], 404);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user