repuve-backend-v1/scripts/seed_owner_vehicle_tinker.txt
2026-01-15 12:38:10 -06:00

101 lines
2.9 KiB
Plaintext

// Copia y pega este código directamente en Tinker (sin las etiquetas <?php)
use App\Models\Owner;
use App\Models\Vehicle;
use App\Models\Tag;
use App\Models\CatalogTagStatus;
use App\Models\VehicleTagLog;
// Crear un propietario
$owner = Owner::create([
'name' => 'Juan',
'paternal' => 'Pérez',
'maternal' => 'García',
'rfc' => 'PEGJ850101ABC',
'curp' => 'PEGJ850101HDFRRN01',
'address' => 'Calle Principal 123',
'tipopers' => true,
'pasaporte' => null,
'licencia' => 'LIC123456789',
'ent_fed' => 'Ciudad de México',
'munic' => 'Benito Juárez',
'callep' => 'Calle Principal',
'num_ext' => '123',
'num_int' => 'A',
'colonia' => 'Centro',
'cp' => '03100',
'telefono' => '5551234567',
]);
echo "Propietario creado: {$owner->full_name} (ID: {$owner->id})\n";
// Crear un vehículo asociado al propietario
$vehicle = Vehicle::create([
'placa' => 'ABC-123',
'niv' => '1HGBH41JXMN109186',
'marca' => 'Honda',
'linea' => 'Civic',
'sublinea' => 'Sedan',
'modelo' => '2020',
'color' => 'Blanco',
'numero_motor' => 'ENG123456789',
'clase_veh' => 'Automóvil',
'tipo_servicio' => 'Particular',
'rfv' => 'RFV123456789',
'ofcexpedicion' => 'Oficina Central',
'fechaexpedicion' => '2020-01-15',
'tipo_veh' => 'Sedan',
'numptas' => '4',
'observac' => 'Vehículo en buen estado',
'cve_vehi' => 'CVE001',
'tipo_mov' => 'Alta',
'owner_id' => $owner->id,
]);
echo "Vehículo creado: {$vehicle->marca} {$vehicle->linea} - Placa: {$vehicle->placa} (ID: {$vehicle->id})\n";
echo "Asociado al propietario: {$owner->full_name}\n";
// Obtener el status "available" para crear el tag
$statusAvailable = CatalogTagStatus::where('code', Tag::STATUS_AVAILABLE)->first();
if (!$statusAvailable) {
throw new Exception('No se encontró el status "available" en el catálogo. Ejecuta el seeder CatalogTagStatusSeeder primero.');
}
// Generar un folio único para el tag
$folio = str_pad(rand(1, 99999999), 8, '0', STR_PAD_LEFT);
// Verificar que el folio no exista
while (Tag::where('folio', $folio)->exists()) {
$folio = str_pad(rand(1, 99999999), 8, '0', STR_PAD_LEFT);
}
// Crear un tag disponible
$tag = Tag::create([
'folio' => $folio,
'tag_number' => 'TAG' . str_pad(rand(1, 999999), 10, '0', STR_PAD_LEFT),
'vehicle_id' => null,
'package_id' => null,
'module_id' => null,
'status_id' => $statusAvailable->id,
]);
echo "Tag creado: Folio {$tag->folio} - Tag Number: {$tag->tag_number} (ID: {$tag->id})\n";
// Asignar el tag al vehículo
$tag->markAsAssigned($vehicle->id, $folio);
echo "Tag asignado al vehículo: {$vehicle->placa}\n";
// Crear registro en el log de tags
VehicleTagLog::create([
'vehicle_id' => $vehicle->id,
'tag_id' => $tag->id,
'action_type' => 'inscripcion',
'performed_by' => null,
]);
echo "Registro de log creado\n";
echo "Proceso completado exitosamente!\n";