feat: inscripción de vehículo con datos de repuve nacional y estatal
This commit is contained in:
parent
557fe6858c
commit
2093ff7538
@ -88,18 +88,31 @@ public function vehicleInscription(VehicleStoreRequest $request)
|
||||
]);
|
||||
}
|
||||
|
||||
// Obtener datos del servicio ESTATAL
|
||||
$datosCompletosRaw = $this->padronEstatalService->getVehiculoByPlaca($placa);
|
||||
|
||||
// Obtener datos de API Estatal por placa
|
||||
$vehicleData = $this->padronEstatalService->extraerDatosVehiculo($datosCompletosRaw);
|
||||
// Extraer datos del servicio estatal
|
||||
$vehicleDataEstatal = $this->padronEstatalService->extraerDatosVehiculo($datosCompletosRaw);
|
||||
$ownerData = $this->padronEstatalService->extraerDatosPropietario($datosCompletosRaw);
|
||||
|
||||
// Obtener NIV de los datos del vehículo para verificar robo
|
||||
$niv = $vehicleData['niv'];
|
||||
// Obtener NIV para consultar REPUVE Nacional
|
||||
$niv = $vehicleDataEstatal['niv'];
|
||||
|
||||
// Verificar robo (API Repuve Nacional)
|
||||
// Consultar REPUVE Nacional para obtener datos oficiales del vehículo
|
||||
$repuveNacionalData = $this->repuveService->consultarVehiculo($niv, $placa);
|
||||
|
||||
// Verificar si hubo error en la consulta a REPUVE Nacional
|
||||
if ($repuveNacionalData['has_error'] ?? false) {
|
||||
DB::rollBack();
|
||||
return ApiResponse::INTERNAL_ERROR->response([
|
||||
'message' => 'Error al consultar REPUVE Nacional.',
|
||||
'error' => $repuveNacionalData['error_message'] ?? 'Error desconocido',
|
||||
]);
|
||||
}
|
||||
|
||||
// Verificar robo
|
||||
$roboResult = $this->checkIfStolen($niv, $placa);
|
||||
// Solo bloquear si explícitamente está marcado como robado
|
||||
// Solo bloquear si está marcado como robado
|
||||
if ($roboResult['is_robado'] ?? false) {
|
||||
DB::rollBack();
|
||||
return ApiResponse::FORBIDDEN->response([
|
||||
@ -132,27 +145,32 @@ public function vehicleInscription(VehicleStoreRequest $request)
|
||||
]
|
||||
);
|
||||
|
||||
// Crear vehículo
|
||||
// Crear vehículo combinando datos de REPUVE Nacional y estatal
|
||||
$vehicle = Vehicle::create([
|
||||
'placa' => $vehicleData['placa'],
|
||||
'niv' => $vehicleData['niv'],
|
||||
'marca' => $vehicleData['marca'],
|
||||
'linea' => $vehicleData['linea'],
|
||||
'sublinea' => $vehicleData['sublinea'],
|
||||
'modelo' => $vehicleData['modelo'],
|
||||
'color' => $vehicleData['color'],
|
||||
'numero_motor' => $vehicleData['numero_motor'],
|
||||
'clase_veh' => $vehicleData['clase_veh'],
|
||||
'tipo_servicio' => $vehicleData['tipo_servicio'],
|
||||
'rfv' => $vehicleData['rfv'],
|
||||
'ofcexpedicion' => $vehicleData['ofcexpedicion'],
|
||||
'fechaexpedicion' => $vehicleData['fechaexpedicion'],
|
||||
'tipo_veh' => $vehicleData['tipo_veh'],
|
||||
'numptas' => $vehicleData['numptas'],
|
||||
'observac' => $vehicleData['observac'],
|
||||
'cve_vehi' => $vehicleData['cve_vehi'],
|
||||
'nrpv' => $vehicleData['nrpv'],
|
||||
'tipo_mov' => $vehicleData['tipo_mov'],
|
||||
// Datos de Estatal
|
||||
'placa' => $vehicleDataEstatal['placa'],
|
||||
'numero_motor' => $vehicleDataEstatal['numero_motor'],
|
||||
|
||||
// Datos de REPUVE NACIONAL
|
||||
'niv' => $repuveNacionalData['niv'],
|
||||
'marca' => $repuveNacionalData['marca'],
|
||||
'linea' => $repuveNacionalData['linea'],
|
||||
'modelo' => $repuveNacionalData['modelo'],
|
||||
|
||||
// Otros datos - de estatal
|
||||
'sublinea' => $vehicleDataEstatal['sublinea'],
|
||||
'color' => $repuveNacionalData['color'] ?? $vehicleDataEstatal['color'],
|
||||
'clase_veh' => $vehicleDataEstatal['clase_veh'],
|
||||
'tipo_servicio' => $vehicleDataEstatal['tipo_servicio'],
|
||||
'rfv' => $vehicleDataEstatal['rfv'],
|
||||
'ofcexpedicion' => $vehicleDataEstatal['ofcexpedicion'],
|
||||
'fechaexpedicion' => $vehicleDataEstatal['fechaexpedicion'],
|
||||
'tipo_veh' => $vehicleDataEstatal['tipo_veh'],
|
||||
'numptas' => $vehicleDataEstatal['numptas'],
|
||||
'observac' => $vehicleDataEstatal['observac'],
|
||||
'cve_vehi' => $vehicleDataEstatal['cve_vehi'],
|
||||
'nrpv' => $vehicleDataEstatal['nrpv'],
|
||||
'tipo_mov' => $vehicleDataEstatal['tipo_mov'],
|
||||
'owner_id' => $owner->id,
|
||||
]);
|
||||
|
||||
@ -302,37 +320,38 @@ public function searchRecord(Request $request)
|
||||
'end_date.after_or_equal' => 'La fecha de fin debe ser posterior o igual a la fecha de inicio.',
|
||||
]);
|
||||
|
||||
$records = Record::with([
|
||||
// Vehículo y propietario
|
||||
'vehicle',
|
||||
'vehicle.owner',
|
||||
$records = Record::forUserModule(Auth::user())
|
||||
->with([
|
||||
// Vehículo y propietario
|
||||
'vehicle',
|
||||
'vehicle.owner',
|
||||
|
||||
// Tag con Package
|
||||
'vehicle.tag:id,vehicle_id,folio,tag_number,status_id,package_id',
|
||||
'vehicle.tag.status:id,code,name',
|
||||
'vehicle.tag.package:id,lot,box_number',
|
||||
// Tag con Package
|
||||
'vehicle.tag:id,vehicle_id,folio,tag_number,status_id,package_id',
|
||||
'vehicle.tag.status:id,code,name',
|
||||
'vehicle.tag.package:id,lot,box_number',
|
||||
|
||||
// Archivos
|
||||
'files:id,record_id,name_id,path,md5',
|
||||
'files.catalogName:id,name',
|
||||
// Archivos
|
||||
'files:id,record_id,name_id,path,md5',
|
||||
'files.catalogName:id,name',
|
||||
|
||||
// Operador y módulo
|
||||
'user:id,name,username,module_id',
|
||||
'module:id,name',
|
||||
// Operador y módulo
|
||||
'user:id,name,username,module_id',
|
||||
'module:id,name',
|
||||
|
||||
// Error si existe
|
||||
'error:id,code,description',
|
||||
// Error si existe
|
||||
'error:id,code,description',
|
||||
|
||||
// Log de acciones
|
||||
'vehicle.vehicleTagLogs' => function ($q) {
|
||||
$q->with([
|
||||
'tag:id,folio,tag_number,status_id,module_id,package_id',
|
||||
'tag.status:id,code,name',
|
||||
'tag.module:id,name',
|
||||
'tag.package:id,lot,box_number'
|
||||
])->orderBy('created_at', 'DESC');
|
||||
},
|
||||
])->orderBy('id', 'ASC');
|
||||
// Log de acciones
|
||||
'vehicle.vehicleTagLogs' => function ($q) {
|
||||
$q->with([
|
||||
'tag:id,folio,tag_number,status_id,module_id,package_id',
|
||||
'tag.status:id,code,name',
|
||||
'tag.module:id,name',
|
||||
'tag.package:id,lot,box_number'
|
||||
])->orderBy('created_at', 'DESC');
|
||||
},
|
||||
])->orderBy('id', 'ASC');
|
||||
|
||||
if ($request->filled('folio')) {
|
||||
$records->whereHas('vehicle.tag', function ($q) use ($request) {
|
||||
|
||||
@ -60,4 +60,15 @@ public function vehicleTagLog()
|
||||
'id'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filtra registros por módulo del usuario
|
||||
*/
|
||||
public function scopeForUserModule($query, $user)
|
||||
{
|
||||
if ($user->hasRole('admin')) {
|
||||
return $query;
|
||||
}
|
||||
return $query->where('module_id', $user->module_id);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user