feat: agrega campo folio_anterior en VehicleTagLog y actualiza lógica de consulta en constanciasSustituidas
This commit is contained in:
parent
3a3c0a2ebf
commit
c0b263eb87
@ -22,6 +22,7 @@
|
||||
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Routing\Controllers\HasMiddleware;
|
||||
|
||||
|
||||
@ -381,9 +382,23 @@ public function constanciasSustituidas(Request $request)
|
||||
->orderBy('created_at', 'asc')
|
||||
->first();
|
||||
|
||||
// Consultar REPUVE Nacional para obtener el folio_CI que se sustituyó
|
||||
$repuveData = $this->repuveService->consultarVehiculo($log->vehicle->niv, $log->vehicle->placa);
|
||||
$folioCi = $repuveData['folio_CI'] ?? '';
|
||||
// Usar folio_anterior guardado; si no existe, consultar RepuveService
|
||||
$folioAnt = $log->folio_anterior;
|
||||
if ($folioAnt === null) {
|
||||
Log::info('[constanciasSustituidas] Registro histórico sin folio_anterior, consultando RepuveService', [
|
||||
'log_id' => $log->id,
|
||||
'vehicle_id'=> $log->vehicle_id,
|
||||
'niv' => $log->vehicle->niv,
|
||||
'placa' => $log->vehicle->placa,
|
||||
]);
|
||||
$repuveData = $this->repuveService->consultarVehiculo($log->vehicle->niv, $log->vehicle->placa);
|
||||
$folioAnt = $repuveData['folio_CI'] ?? '';
|
||||
Log::info('[constanciasSustituidas] Respuesta RepuveService', [
|
||||
'log_id' => $log->id,
|
||||
'folio_CI' => $folioAnt,
|
||||
'repuve_has_error' => $repuveData['has_error'] ?? false,
|
||||
]);
|
||||
}
|
||||
|
||||
return [
|
||||
'niv' => $log->vehicle->niv ?? '',
|
||||
@ -391,7 +406,7 @@ public function constanciasSustituidas(Request $request)
|
||||
'marca' => $log->vehicle->marca ?? '',
|
||||
'placa' => $log->vehicle->placa ?? '',
|
||||
'modelo' => $log->vehicle->modelo ?? '',
|
||||
'folio_ant' => $folioCi,
|
||||
'folio_ant' => $folioAnt,
|
||||
'folio_act' => $newTagLog?->tag?->folio ?? '',
|
||||
'chip' => substr($newTagLog?->tag?->rfid ?? $newTagLog?->tag?->tag_number ?? '', 0, 24),
|
||||
'fecha' => $log->cancellation_at?->format('d/m/Y') ?? $log->created_at->format('d/m/Y'),
|
||||
|
||||
@ -150,6 +150,10 @@ public function tagSubstitution(Request $request)
|
||||
]);
|
||||
}
|
||||
|
||||
// Obtener folio_CI de REPUVE antes de cancelar (folio anterior)
|
||||
$repuveData = $this->repuveService->consultarVehiculo($vehicle->niv, $vehicle->placa);
|
||||
$folioAnterior = $repuveData['folio_CI'] ?? null;
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
// Cancelar el TAG anterior
|
||||
@ -159,6 +163,7 @@ public function tagSubstitution(Request $request)
|
||||
VehicleTagLog::create([
|
||||
'vehicle_id' => $vehicle->id,
|
||||
'tag_id' => $oldTag->id,
|
||||
'folio_anterior' => $folioAnterior,
|
||||
'new_tag_folio' => $newTagFolio,
|
||||
'new_tag_number' => $newTagNumber,
|
||||
'action_type' => 'sustitucion',
|
||||
|
||||
@ -14,6 +14,7 @@ class VehicleTagLog extends Model
|
||||
protected $fillable = [
|
||||
'vehicle_id',
|
||||
'tag_id',
|
||||
'folio_anterior',
|
||||
'action_type',
|
||||
'cancellation_reason_id',
|
||||
'cancellation_observations',
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('vehicle_tags_logs', function (Blueprint $table) {
|
||||
$table->string('folio_anterior')->nullable()->after('tag_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('vehicle_tags_logs', function (Blueprint $table) {
|
||||
$table->dropColumn('folio_anterior');
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user