feat(events): associate purchases and integrations with events

This commit is contained in:
2026-09-28 19:13:36 +00:00
parent 7f754037bb
commit 7996d53e12
13 changed files with 312 additions and 7 deletions

View File

@@ -0,0 +1,26 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('events', function (Blueprint $table): void {
$table->foreignId('client_id')
->nullable()
->after('id')
->constrained('clients')
->restrictOnDelete();
});
}
public function down(): void
{
Schema::table('events', function (Blueprint $table): void {
$table->dropConstrainedForeignId('client_id');
});
}
};

View File

@@ -0,0 +1,44 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('compras', function (Blueprint $table): void {
$table->foreignId('event_id')
->nullable()
->after('tenant_codigo')
->constrained('events')
->nullOnDelete();
});
DB::table('compras')
->orderBy('id')
->each(function (object $purchase): void {
$eventIds = DB::table('compra_items')
->join('catalog_items', 'catalog_items.id', '=', 'compra_items.source_catalog_item_id')
->where('compra_items.compra_id', $purchase->id)
->whereNotNull('catalog_items.event_id')
->distinct()
->pluck('catalog_items.event_id');
if ($eventIds->count() === 1) {
DB::table('compras')
->where('id', $purchase->id)
->update(['event_id' => $eventIds->first()]);
}
});
}
public function down(): void
{
Schema::table('compras', function (Blueprint $table): void {
$table->dropConstrainedForeignId('event_id');
});
}
};

View File

@@ -0,0 +1,42 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
return new class extends Migration
{
private const EVENT_TITLE = '26.º Fiesta de la Tradición y 4.º Encuentro de Agrupaciones Gauchas';
public function up(): void
{
$clientId = DB::table('clients')
->where('code', 'pyme_rural')
->value('id');
if ($clientId === null) {
return;
}
DB::table('events')
->where('tenant_code', 'onticket')
->where('title', self::EVENT_TITLE)
->update(['client_id' => $clientId]);
}
public function down(): void
{
$clientId = DB::table('clients')
->where('code', 'pyme_rural')
->value('id');
if ($clientId === null) {
return;
}
DB::table('events')
->where('tenant_code', 'onticket')
->where('title', self::EVENT_TITLE)
->where('client_id', $clientId)
->update(['client_id' => null]);
}
};

View File

@@ -6,6 +6,7 @@ use App\Domains\Commerce\Catalog\Enums\InventoryPolicy;
use App\Domains\Commerce\Catalog\Models\Attribute;
use App\Domains\Commerce\Catalog\Models\CatalogItem;
use App\Domains\Commerce\Catalog\Services\CatalogService;
use App\Domains\Core\Client\Models\Client;
use App\Domains\Core\Tenant\Models\Tenant;
use App\Domains\Ticketing\Event\Models\Event;
use App\Shared\Attachable\Services\AttachmentService;
@@ -35,6 +36,12 @@ class FiestaTradicionArrufoSeeder extends Seeder
throw new RuntimeException("Tenant 'onticket' no encontrado.");
}
$client = Client::query()->where('code', 'pyme_rural')->first();
if ($client === null) {
throw new RuntimeException("Client 'pyme_rural' no encontrado.");
}
Attribute::query()->firstOrCreate(
['tenant_codigo' => $tenant->codigo, 'codigo' => 'event_date'],
['nombre' => 'Fecha', 'type' => FieldType::EventDate, 'is_required' => true],
@@ -45,6 +52,7 @@ class FiestaTradicionArrufoSeeder extends Seeder
['published_at' => now()],
);
$event->update([
'client_id' => $client->id,
'subtitle' => 'Una noche para celebrar nuestras raíces y mantener viva la tradición gaucha.',
'description' => 'La 26.º Fiesta de la Tradición y 4.º Encuentro de Agrupaciones Gauchas reunirá a agrupaciones, artesanos, pilcheros y público en general para compartir una jornada dedicada a nuestras costumbres y cultura.'
."\n\n".'Un encuentro para disfrutar de la tradición, la identidad gaucha y el espíritu de camaradería, en el Predio de Doma del Club Unión Deportiva Arrufó.'