feat: Mejorar la validación de errores en la cancelación de constancias y optimizar la búsqueda de tags por lote
This commit is contained in:
parent
cf7cfdb821
commit
2d060f9909
@ -45,13 +45,8 @@ public function cancelarConstancia(CancelConstanciaRequest $request)
|
||||
]);
|
||||
}
|
||||
|
||||
// Validar que el registro no tenga errores previos
|
||||
if ($record->error_id !== null) {
|
||||
return ApiResponse::BAD_REQUEST->response([
|
||||
'message' => 'No se puede cancelar un registro que tiene errores. El vehículo no fue inscrito.',
|
||||
'error_id' => $record->error_id
|
||||
]);
|
||||
}
|
||||
// Avisar que tiene error
|
||||
$hadPreviousError = $record->error_id !== null;
|
||||
|
||||
// Guardar información del tag anterior ANTES de cancelarlo
|
||||
$oldTagNumber = $tag->tag_number;
|
||||
|
||||
@ -54,11 +54,10 @@ public function vehicleInscription(VehicleStoreRequest $request)
|
||||
]);
|
||||
}
|
||||
|
||||
if ($tag->vehicle_id) {
|
||||
if (!$tag->isAvailable()) {
|
||||
return ApiResponse::BAD_REQUEST->response([
|
||||
'message' => 'El tag ya está asignado a un vehículo. Use actualizar en su lugar.',
|
||||
'tag_number' => $tagNumber,
|
||||
'vehicle_id' => $tag->vehicle_id,
|
||||
'current_status' => $tag->status->name,
|
||||
]);
|
||||
}
|
||||
|
||||
@ -201,8 +200,10 @@ public function vehicleInscription(VehicleStoreRequest $request)
|
||||
// Enviar a API Repuve Nacional
|
||||
$apiResponse = $this->sendToRepuveNacional($niv);
|
||||
|
||||
$apiResponse["repuve_response"]["folio_ci"] = $folio; //harcodeado cambiar despues
|
||||
$apiResponse["repuve_response"]["identificador_ci"] = $tagNumber; //harcodeado cambiar despues
|
||||
if (isset($apiResponse['repuve_response']) && is_array($apiResponse['repuve_response'])) {
|
||||
$apiResponse["repuve_response"]["folio_ci"] = $folio;
|
||||
$apiResponse["repuve_response"]["identificador_ci"] = $tagNumber;
|
||||
}
|
||||
|
||||
// Procesar respuesta
|
||||
if (isset($apiResponse['has_error']) && $apiResponse['has_error']) {
|
||||
@ -428,6 +429,7 @@ public function searchRecord(Request $request)
|
||||
'folio',
|
||||
'vehicle_id',
|
||||
'user_id',
|
||||
'error_id',
|
||||
'created_at'
|
||||
])->paginate(config('app.pagination'))
|
||||
]);
|
||||
|
||||
@ -20,6 +20,12 @@ public function index(Request $request)
|
||||
});
|
||||
}
|
||||
|
||||
if ($request->has('lot')) {
|
||||
$tags->whereHas('package', function ($q) use ($request) {
|
||||
$q->where('lot', $request->lot);
|
||||
});
|
||||
}
|
||||
|
||||
return ApiResponse::OK->response([
|
||||
'tag' => $tags->paginate(config('app.pagination')),
|
||||
]);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user