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\Style\Fill;
|
||||||
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Routing\Controllers\HasMiddleware;
|
use Illuminate\Routing\Controllers\HasMiddleware;
|
||||||
|
|
||||||
|
|
||||||
@ -381,9 +382,23 @@ public function constanciasSustituidas(Request $request)
|
|||||||
->orderBy('created_at', 'asc')
|
->orderBy('created_at', 'asc')
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
// Consultar REPUVE Nacional para obtener el folio_CI que se sustituyó
|
// Usar folio_anterior guardado; si no existe, consultar RepuveService
|
||||||
$repuveData = $this->repuveService->consultarVehiculo($log->vehicle->niv, $log->vehicle->placa);
|
$folioAnt = $log->folio_anterior;
|
||||||
$folioCi = $repuveData['folio_CI'] ?? '';
|
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 [
|
return [
|
||||||
'niv' => $log->vehicle->niv ?? '',
|
'niv' => $log->vehicle->niv ?? '',
|
||||||
@ -391,7 +406,7 @@ public function constanciasSustituidas(Request $request)
|
|||||||
'marca' => $log->vehicle->marca ?? '',
|
'marca' => $log->vehicle->marca ?? '',
|
||||||
'placa' => $log->vehicle->placa ?? '',
|
'placa' => $log->vehicle->placa ?? '',
|
||||||
'modelo' => $log->vehicle->modelo ?? '',
|
'modelo' => $log->vehicle->modelo ?? '',
|
||||||
'folio_ant' => $folioCi,
|
'folio_ant' => $folioAnt,
|
||||||
'folio_act' => $newTagLog?->tag?->folio ?? '',
|
'folio_act' => $newTagLog?->tag?->folio ?? '',
|
||||||
'chip' => substr($newTagLog?->tag?->rfid ?? $newTagLog?->tag?->tag_number ?? '', 0, 24),
|
'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'),
|
'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();
|
DB::beginTransaction();
|
||||||
|
|
||||||
// Cancelar el TAG anterior
|
// Cancelar el TAG anterior
|
||||||
@ -159,6 +163,7 @@ public function tagSubstitution(Request $request)
|
|||||||
VehicleTagLog::create([
|
VehicleTagLog::create([
|
||||||
'vehicle_id' => $vehicle->id,
|
'vehicle_id' => $vehicle->id,
|
||||||
'tag_id' => $oldTag->id,
|
'tag_id' => $oldTag->id,
|
||||||
|
'folio_anterior' => $folioAnterior,
|
||||||
'new_tag_folio' => $newTagFolio,
|
'new_tag_folio' => $newTagFolio,
|
||||||
'new_tag_number' => $newTagNumber,
|
'new_tag_number' => $newTagNumber,
|
||||||
'action_type' => 'sustitucion',
|
'action_type' => 'sustitucion',
|
||||||
|
|||||||
@ -14,6 +14,7 @@ class VehicleTagLog extends Model
|
|||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'vehicle_id',
|
'vehicle_id',
|
||||||
'tag_id',
|
'tag_id',
|
||||||
|
'folio_anterior',
|
||||||
'action_type',
|
'action_type',
|
||||||
'cancellation_reason_id',
|
'cancellation_reason_id',
|
||||||
'cancellation_observations',
|
'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