Cambios a inscripcion, placa en vez de niv y correción de fecha en PadronEstatalService
This commit is contained in:
parent
fd727ca45f
commit
c9e5cb86c8
@ -40,7 +40,7 @@ public function vehicleInscription(VehicleStoreRequest $request)
|
||||
try {
|
||||
$folio = $request->input('folio');
|
||||
$tagNumber = $request->input('tag_number');
|
||||
$niv = $request->input('niv');
|
||||
$placa = $request->input('placa');
|
||||
$telefono = $request->input('telefono');
|
||||
|
||||
// Buscar Tag y validar que NO tenga vehículo asignado
|
||||
@ -61,10 +61,21 @@ public function vehicleInscription(VehicleStoreRequest $request)
|
||||
]);
|
||||
}
|
||||
|
||||
// Iniciar transacción
|
||||
DB::beginTransaction();
|
||||
|
||||
// Obtener datos de API Estatal por placa
|
||||
$vehicleData = $this->getVehicleByPlaca($placa);
|
||||
$ownerData = $this->getOwnerByPlaca($placa);
|
||||
|
||||
// Obtener NIV de los datos del vehículo para verificar robo
|
||||
$niv = $vehicleData['niv'];
|
||||
|
||||
// Verificar robo (API Repuve Nacional)
|
||||
$isStolen = $this->checkIfStolen($niv);
|
||||
|
||||
if ($isStolen) {
|
||||
DB::rollBack();
|
||||
return ApiResponse::FORBIDDEN->response([
|
||||
'folio' => $folio,
|
||||
'tag_number' => $tagNumber,
|
||||
@ -73,13 +84,6 @@ public function vehicleInscription(VehicleStoreRequest $request)
|
||||
]);
|
||||
}
|
||||
|
||||
// Iniciar transacción
|
||||
DB::beginTransaction();
|
||||
|
||||
// Obtener 37 datos de API Estatal
|
||||
$vehicleData = $this->getVehicle($niv);
|
||||
$ownerData = $this->getOwner($niv);
|
||||
|
||||
// Crear propietario
|
||||
$owner = Owner::updateOrCreate(
|
||||
['rfc' => $ownerData['rfc']],
|
||||
|
||||
@ -15,12 +15,12 @@ public function rules(): array
|
||||
return [
|
||||
'folio' => ['required', 'string', 'max:50'],
|
||||
'tag_number' => ['required', 'string', 'exists:tags,tag_number'],
|
||||
'niv' => ['sometimes', 'string', 'max:30'],
|
||||
'placa' => ['required', 'string', 'max:30'],
|
||||
'telefono' => ['required', 'string', 'max:11'],
|
||||
'files' => ['nullable', 'array', 'min:1'],
|
||||
'files.*' => ['file', 'mimes:jpeg,png,jpg', 'max:10240'],
|
||||
'names' => ['nullable', 'array'],
|
||||
'names.*' => ['string', 'max:255'],
|
||||
'name_id' => ['required', 'array', 'min:1'],
|
||||
'name_id.*' => ['required', 'integer', 'exists:catalog_name_img,id']
|
||||
];
|
||||
}
|
||||
|
||||
@ -31,8 +31,8 @@ public function messages(): array
|
||||
'folio.string' => 'El folio debe ser una cadena de texto',
|
||||
'tag_number.required' => 'El tag_number es requerido',
|
||||
'tag_number.exists' => 'El tag_number no existe en el sistema',
|
||||
'niv.required' => 'El niv es requerido',
|
||||
'niv.string' => 'El niv debe ser una cadena de texto',
|
||||
'placa.required' => 'La placa es requerida',
|
||||
'placa.string' => 'La placa debe ser una cadena de texto',
|
||||
'telefono.required' => 'El teléfono es requerido',
|
||||
'telefono.max' => 'El teléfono no debe superar los 10 caracteres',
|
||||
'files.array' => 'Los archivos deben ser un array',
|
||||
|
||||
@ -18,6 +18,11 @@ public function getVehiculoByNiv(string $niv): array
|
||||
return $this->consultarPadron('niv', $niv);
|
||||
}
|
||||
|
||||
public function getVehiculoByPlaca(string $placa): array
|
||||
{
|
||||
return $this->consultarPadron('placa', $placa);
|
||||
}
|
||||
|
||||
public function getVehiculoByFolio(string $folio): array
|
||||
{
|
||||
return $this->consultarPadron('folio', $folio);
|
||||
@ -123,6 +128,12 @@ private function parsearRespuesta(string $soapResponse): array
|
||||
*/
|
||||
public function extraerDatosVehiculo(array $datos): array
|
||||
{
|
||||
// Convertir fecha de DD/MM/YYYY a YYYY-MM-DD
|
||||
$fechaexpedicion = null;
|
||||
if (isset($datos['fechaexp']) && $datos['fechaexp']) {
|
||||
$fechaexpedicion = $this->convertirFecha($datos['fechaexp']);
|
||||
}
|
||||
|
||||
return [
|
||||
'placa' => $datos['placa'] ?? null,
|
||||
'niv' => $datos['niv'] ?? null,
|
||||
@ -136,7 +147,7 @@ public function extraerDatosVehiculo(array $datos): array
|
||||
'tipo_servicio' => $datos['tipo_uso'] ?? null,
|
||||
'rfv' => $datos['rfv'] ?? null,
|
||||
'ofcexpedicion' => $datos['ofcexp'] ?? null,
|
||||
'fechaexpedicion' => $datos['fechaexp'] ?? null,
|
||||
'fechaexpedicion' => $fechaexpedicion,
|
||||
'tipo_veh' => $datos['tipo_veh'] ?? null,
|
||||
'numptas' => $datos['numptas'] ?? null,
|
||||
'observac' => $datos['observac'] ?? null,
|
||||
@ -145,6 +156,29 @@ public function extraerDatosVehiculo(array $datos): array
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Convierte fecha de DD/MM/YYYY a YYYY-MM-DD
|
||||
*/
|
||||
private function convertirFecha(?string $fecha): ?string
|
||||
{
|
||||
if (!$fecha) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Si ya está en formato YYYY-MM-DD, retornar tal cual
|
||||
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $fecha)) {
|
||||
return $fecha;
|
||||
}
|
||||
|
||||
// Convertir de DD/MM/YYYY a YYYY-MM-DD
|
||||
if (preg_match('/^(\d{2})\/(\d{2})\/(\d{4})$/', $fecha, $matches)) {
|
||||
return "{$matches[3]}-{$matches[2]}-{$matches[1]}";
|
||||
}
|
||||
|
||||
// Si no coincide con ningún formato esperado, retornar null
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extrae los datos del propietario del resultado
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user