Add tests for ticket validity and event date formatting
- Create TicketValiditySchemaTest to verify database schema for ticket validity. - Update CatalogModelsTest to include tests for event date attributes and selection options. - Introduce EventDateTextFormatterTest for formatting event dates in Spanish. - Refactor EventModelsTest to include validity time relationships. - Add SaleDetailResourceTest to ensure correct serialization of purchase items. - Enhance TicketTest with validity time checks and status management. - Implement ValidityTimeResourceTest to validate resource output for different validity types. - Add ValidityTimeTest to verify casting and validity checks for validity time types.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
<?php
|
||||
|
||||
use App\Domains\Catalog\Enums\EventProductType;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
@@ -43,9 +42,6 @@ return new class extends Migration
|
||||
->after('tenant_code')
|
||||
->constrained('events')
|
||||
->nullOnDelete();
|
||||
$table->enum('event_product_type', EventProductType::values())
|
||||
->nullable()
|
||||
->after('event_id');
|
||||
});
|
||||
|
||||
Schema::table('variantes', function (Blueprint $table): void {
|
||||
@@ -71,7 +67,6 @@ return new class extends Migration
|
||||
|
||||
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('event_id');
|
||||
$table->dropColumn('event_product_type');
|
||||
});
|
||||
|
||||
Schema::dropIfExists('event_dates');
|
||||
|
||||
@@ -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::create('validity_times', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('type');
|
||||
$table->time('start_time')->nullable();
|
||||
$table->time('end_time')->nullable();
|
||||
$table->dateTime('fixed_starts_at')->nullable();
|
||||
$table->dateTime('fixed_expires_at')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('validity_times');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
<?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('catalog_items', function (Blueprint $table): void {
|
||||
$table->foreignId('validity_time_id')
|
||||
->nullable()
|
||||
->after('has_tickets')
|
||||
->constrained('validity_times')
|
||||
->cascadeOnUpdate()
|
||||
->nullOnDelete();
|
||||
});
|
||||
|
||||
Schema::table('attribute_options', function (Blueprint $table): void {
|
||||
$table->foreignId('validity_time_id')
|
||||
->nullable()
|
||||
->after('attribute_id')
|
||||
->constrained('validity_times')
|
||||
->cascadeOnUpdate()
|
||||
->nullOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('attribute_options', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('validity_time_id');
|
||||
});
|
||||
|
||||
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('validity_time_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
<?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('tickets', function (Blueprint $table): void {
|
||||
$table->foreignId('validity_time_id')
|
||||
->nullable()
|
||||
->after('source_variant_id')
|
||||
->constrained('validity_times')
|
||||
->cascadeOnUpdate()
|
||||
->restrictOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('tickets', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('validity_time_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,92 @@
|
||||
<?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
|
||||
{
|
||||
$this->preserveFixedWindows(
|
||||
'catalog_items',
|
||||
'minimum_use_date',
|
||||
'maximum_use_date',
|
||||
);
|
||||
$this->preserveFixedWindows('tickets', 'starts_at', 'expires_at');
|
||||
|
||||
Schema::table('tickets', function (Blueprint $table): void {
|
||||
$table->dropColumn(['starts_at', 'expires_at']);
|
||||
});
|
||||
|
||||
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||
$table->dropColumn(['minimum_use_date', 'maximum_use_date']);
|
||||
});
|
||||
|
||||
Schema::table('variantes', function (Blueprint $table): void {
|
||||
$table->dropColumn(['minimum_use_date', 'maximum_use_date']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('variantes', function (Blueprint $table): void {
|
||||
$table->dateTime('minimum_use_date')->nullable();
|
||||
$table->dateTime('maximum_use_date')->nullable();
|
||||
});
|
||||
|
||||
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||
$table->dateTime('minimum_use_date')->nullable();
|
||||
$table->dateTime('maximum_use_date')->nullable();
|
||||
});
|
||||
|
||||
Schema::table('tickets', function (Blueprint $table): void {
|
||||
$table->dateTime('starts_at')->nullable();
|
||||
$table->dateTime('expires_at')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
private function preserveFixedWindows(
|
||||
string $table,
|
||||
string $startsAtColumn,
|
||||
string $expiresAtColumn,
|
||||
): void {
|
||||
DB::table($table)
|
||||
->whereNull('validity_time_id')
|
||||
->where(function ($query) use ($startsAtColumn, $expiresAtColumn): void {
|
||||
$query->whereNotNull($startsAtColumn)
|
||||
->orWhereNotNull($expiresAtColumn);
|
||||
})
|
||||
->select([$startsAtColumn, $expiresAtColumn])
|
||||
->distinct()
|
||||
->get()
|
||||
->each(function ($window) use ($table, $startsAtColumn, $expiresAtColumn): void {
|
||||
$startsAt = $window->{$startsAtColumn};
|
||||
$expiresAt = $window->{$expiresAtColumn};
|
||||
$validityTimeId = DB::table('validity_times')->insertGetId([
|
||||
'type' => 'fixed_window',
|
||||
'start_time' => null,
|
||||
'end_time' => null,
|
||||
'fixed_starts_at' => $startsAt,
|
||||
'fixed_expires_at' => $expiresAt,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
DB::table($table)
|
||||
->whereNull('validity_time_id')
|
||||
->when(
|
||||
$startsAt === null,
|
||||
fn ($query) => $query->whereNull($startsAtColumn),
|
||||
fn ($query) => $query->where($startsAtColumn, $startsAt),
|
||||
)
|
||||
->when(
|
||||
$expiresAt === null,
|
||||
fn ($query) => $query->whereNull($expiresAtColumn),
|
||||
fn ($query) => $query->where($expiresAtColumn, $expiresAt),
|
||||
)
|
||||
->update(['validity_time_id' => $validityTimeId]);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
<?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('catalog_items', function (Blueprint $table): void {
|
||||
$table->unsignedInteger('max_units_per_user')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||
$table->dropColumn('max_units_per_user');
|
||||
});
|
||||
}
|
||||
};
|
||||
125
database/migrations/2026_08_07_000000_move_event_onto_tenant.php
Normal file
125
database/migrations/2026_08_07_000000_move_event_onto_tenant.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?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('tenants', function (Blueprint $table): void {
|
||||
$table->string('event_title')->nullable()->after('nombre');
|
||||
$table->string('event_location')->nullable()->after('event_title');
|
||||
});
|
||||
|
||||
Schema::table('event_dates', function (Blueprint $table): void {
|
||||
$table->string('tenant_code')->nullable()->after('id');
|
||||
});
|
||||
|
||||
DB::table('tenants')
|
||||
->whereNotNull('active_event_id')
|
||||
->orderBy('id')
|
||||
->each(function (object $tenant): void {
|
||||
$event = DB::table('events')->where('id', $tenant->active_event_id)->first();
|
||||
|
||||
if ($event === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DB::table('tenants')->where('id', $tenant->id)->update([
|
||||
'event_title' => $event->name,
|
||||
'event_location' => $event->address,
|
||||
]);
|
||||
});
|
||||
|
||||
DB::table('events')->orderBy('id')->each(function (object $event): void {
|
||||
DB::table('event_dates')
|
||||
->where('event_id', $event->id)
|
||||
->update(['tenant_code' => $event->tenant_code]);
|
||||
});
|
||||
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('active_event_id');
|
||||
});
|
||||
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('event_id');
|
||||
});
|
||||
Schema::table('compras', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('event_id');
|
||||
});
|
||||
Schema::table('event_dates', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('event_id');
|
||||
$table->string('tenant_code')->nullable(false)->change();
|
||||
$table->foreign('tenant_code')
|
||||
->references('codigo')
|
||||
->on('tenants')
|
||||
->cascadeOnUpdate()
|
||||
->cascadeOnDelete();
|
||||
});
|
||||
|
||||
Schema::dropIfExists('events');
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::create('events', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('tenant_code');
|
||||
$table->string('name');
|
||||
$table->string('address');
|
||||
$table->foreign('tenant_code')
|
||||
->references('codigo')
|
||||
->on('tenants')
|
||||
->cascadeOnUpdate()
|
||||
->cascadeOnDelete();
|
||||
});
|
||||
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->foreignId('active_event_id')->nullable();
|
||||
});
|
||||
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||
$table->foreignId('event_id')->nullable();
|
||||
});
|
||||
Schema::table('compras', function (Blueprint $table): void {
|
||||
$table->foreignId('event_id')->nullable();
|
||||
});
|
||||
Schema::table('event_dates', function (Blueprint $table): void {
|
||||
$table->foreignId('event_id')->nullable();
|
||||
});
|
||||
|
||||
DB::table('tenants')->orderBy('id')->each(function (object $tenant): void {
|
||||
if ($tenant->event_title === null && $tenant->event_location === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$eventId = DB::table('events')->insertGetId([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'name' => $tenant->event_title ?? $tenant->nombre,
|
||||
'address' => $tenant->event_location ?? '',
|
||||
]);
|
||||
|
||||
DB::table('tenants')->where('id', $tenant->id)->update(['active_event_id' => $eventId]);
|
||||
DB::table('catalog_items')->where('tenant_code', $tenant->codigo)->update(['event_id' => $eventId]);
|
||||
DB::table('compras')->where('tenant_codigo', $tenant->codigo)->update(['event_id' => $eventId]);
|
||||
DB::table('event_dates')->where('tenant_code', $tenant->codigo)->update(['event_id' => $eventId]);
|
||||
});
|
||||
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->foreign('active_event_id')->references('id')->on('events')->nullOnDelete();
|
||||
$table->dropColumn(['event_title', 'event_location']);
|
||||
});
|
||||
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||
$table->foreign('event_id')->references('id')->on('events')->nullOnDelete();
|
||||
});
|
||||
Schema::table('compras', function (Blueprint $table): void {
|
||||
$table->foreign('event_id')->references('id')->on('events')->nullOnDelete();
|
||||
});
|
||||
Schema::table('event_dates', function (Blueprint $table): void {
|
||||
$table->dropForeign(['tenant_code']);
|
||||
$table->dropColumn('tenant_code');
|
||||
$table->foreign('event_id')->references('id')->on('events')->cascadeOnDelete();
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?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('variantes', function (Blueprint $table): void {
|
||||
$table->index(['catalog_item_id', 'event_date_id']);
|
||||
});
|
||||
|
||||
Schema::table('variantes', function (Blueprint $table): void {
|
||||
$table->dropUnique(['catalog_item_id', 'event_date_id']);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('variantes', function (Blueprint $table): void {
|
||||
$table->unique(['catalog_item_id', 'event_date_id']);
|
||||
});
|
||||
|
||||
Schema::table('variantes', function (Blueprint $table): void {
|
||||
$table->dropIndex(['catalog_item_id', 'event_date_id']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$now = now();
|
||||
|
||||
DB::table('tenants')
|
||||
->whereExists(fn ($query) => $query
|
||||
->selectRaw('1')
|
||||
->from('event_dates')
|
||||
->whereColumn('event_dates.tenant_code', 'tenants.codigo'))
|
||||
->orderBy('id')
|
||||
->each(function (object $tenant) use ($now): void {
|
||||
DB::table('attribute')->updateOrInsert(
|
||||
[
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
'codigo' => 'event_date',
|
||||
],
|
||||
[
|
||||
'nombre' => 'Fecha',
|
||||
'is_required' => true,
|
||||
'metadata_schema' => null,
|
||||
'type' => 'event_date',
|
||||
'updated_at' => $now,
|
||||
'created_at' => $now,
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
DB::table('catalog_items')
|
||||
->whereExists(fn ($query) => $query
|
||||
->selectRaw('1')
|
||||
->from('variantes')
|
||||
->whereColumn('variantes.catalog_item_id', 'catalog_items.id')
|
||||
->whereNotNull('variantes.event_date_id'))
|
||||
->orderBy('id')
|
||||
->each(function (object $catalogItem) use ($now): void {
|
||||
$attributeId = DB::table('attribute')
|
||||
->where('tenant_codigo', $catalogItem->tenant_code)
|
||||
->where('codigo', 'event_date')
|
||||
->value('id');
|
||||
|
||||
if ($attributeId === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DB::table('item_attributes')->updateOrInsert(
|
||||
[
|
||||
'catalog_item_id' => $catalogItem->id,
|
||||
'attribute_id' => $attributeId,
|
||||
],
|
||||
[
|
||||
'updated_at' => $now,
|
||||
'created_at' => $now,
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$attributeIds = DB::table('attribute')
|
||||
->where('codigo', 'event_date')
|
||||
->where('type', 'event_date')
|
||||
->pluck('id');
|
||||
|
||||
DB::table('item_attributes')->whereIn('attribute_id', $attributeIds)->delete();
|
||||
DB::table('attribute')->whereIn('id', $attributeIds)->delete();
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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('item_attributes', function (Blueprint $table): void {
|
||||
$table->boolean('allow_multi_select')->default(false)->after('attribute_id');
|
||||
});
|
||||
|
||||
Schema::create('variant_event_dates', function (Blueprint $table): void {
|
||||
$table->foreignId('variant_id')->constrained('variantes')->cascadeOnDelete();
|
||||
$table->foreignId('event_date_id')->constrained('event_dates')->cascadeOnDelete();
|
||||
$table->primary(['variant_id', 'event_date_id']);
|
||||
$table->index(['event_date_id', 'variant_id']);
|
||||
});
|
||||
|
||||
DB::table('variantes')
|
||||
->whereNotNull('event_date_id')
|
||||
->orderBy('id')
|
||||
->each(function (object $variant): void {
|
||||
DB::table('variant_event_dates')->insertOrIgnore([
|
||||
'variant_id' => $variant->id,
|
||||
'event_date_id' => $variant->event_date_id,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('variant_event_dates');
|
||||
|
||||
Schema::table('item_attributes', function (Blueprint $table): void {
|
||||
$table->dropColumn('allow_multi_select');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
<?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('variant_values', function (Blueprint $table): void {
|
||||
$table->dropUnique('variant_values_variant_id_item_attribute_id_unique');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('variant_values', function (Blueprint $table): void {
|
||||
$table->unique(['variant_id', 'item_attribute_id']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
<?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('variantes', function (Blueprint $table): void {
|
||||
$table->text('descripcion')->nullable()->after('inventory_id');
|
||||
$table->decimal('precio', 10, 2)->nullable()->after('descripcion');
|
||||
});
|
||||
|
||||
DB::table('variantes')->orderBy('id')->each(function (object $variant): void {
|
||||
$price = DB::table('catalog_items')
|
||||
->where('id', $variant->catalog_item_id)
|
||||
->value('precio');
|
||||
|
||||
DB::table('variantes')->where('id', $variant->id)->update([
|
||||
'precio' => $price,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('variantes', function (Blueprint $table): void {
|
||||
$table->dropColumn(['descripcion', 'precio']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use App\Domains\Event\Services\EventDateTextFormatter;
|
||||
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('tenants', function (Blueprint $table): void {
|
||||
$table->text('event_date_text')->nullable()->after('event_location');
|
||||
});
|
||||
|
||||
$formatter = new EventDateTextFormatter;
|
||||
|
||||
DB::table('tenants')->orderBy('id')->each(function (object $tenant) use ($formatter): void {
|
||||
$dates = DB::table('event_dates')
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->orderBy('date')
|
||||
->pluck('date');
|
||||
|
||||
DB::table('tenants')->where('id', $tenant->id)->update([
|
||||
'event_date_text' => $formatter->format($dates),
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->dropColumn('event_date_text');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
<?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('item_attributes', function (Blueprint $table): void {
|
||||
$table->unsignedInteger('sort_order')->default(0)->after('allow_multi_select');
|
||||
});
|
||||
|
||||
$foodItemAttributes = DB::table('item_attributes')
|
||||
->join('catalog_items', 'catalog_items.id', '=', 'item_attributes.catalog_item_id')
|
||||
->join('attribute', 'attribute.id', '=', 'item_attributes.attribute_id')
|
||||
->where('catalog_items.slug', 'comida')
|
||||
->whereIn('attribute.codigo', ['event_date', 'horario', 'servicio'])
|
||||
->select('item_attributes.id', 'attribute.codigo')
|
||||
->get();
|
||||
|
||||
$sortOrders = [
|
||||
'event_date' => 1,
|
||||
'horario' => 2,
|
||||
'servicio' => 3,
|
||||
];
|
||||
|
||||
foreach ($foodItemAttributes as $itemAttribute) {
|
||||
DB::table('item_attributes')
|
||||
->where('id', $itemAttribute->id)
|
||||
->update(['sort_order' => $sortOrders[$itemAttribute->codigo]]);
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('item_attributes', function (Blueprint $table): void {
|
||||
$table->dropColumn('sort_order');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
DB::table('catalog_items')
|
||||
->where('tenant_code', 'fiesta_futbol_infantil')
|
||||
->update(['has_tickets' => true]);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$entryCategoryIds = DB::table('categorias')
|
||||
->select('id')
|
||||
->where('tenant_code', 'fiesta_futbol_infantil')
|
||||
->where('nombre', 'Entradas');
|
||||
|
||||
DB::table('catalog_items')
|
||||
->where('tenant_code', 'fiesta_futbol_infantil')
|
||||
->whereNotIn('category_id', $entryCategoryIds)
|
||||
->update(['has_tickets' => false]);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
<?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
|
||||
{
|
||||
if (! Schema::hasColumn('catalog_items', 'event_product_type')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||
$table->dropColumn('event_product_type');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (Schema::hasColumn('catalog_items', 'event_product_type')) {
|
||||
return;
|
||||
}
|
||||
|
||||
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||
$table->enum('event_product_type', ['entrada', 'producto'])
|
||||
->nullable()
|
||||
->after('tenant_code');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
<?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('tenants', function (Blueprint $table): void {
|
||||
$table->boolean('display_categories')->default(true)->after('search_items_per_page');
|
||||
$table->boolean('display_seach_bar')->default(true)->after('display_categories');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->dropColumn(['display_categories', 'display_seach_bar']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
DB::table('tenants')
|
||||
->where('codigo', 'fiesta_futbol_infantil')
|
||||
->update([
|
||||
'display_categories' => false,
|
||||
'display_seach_bar' => false,
|
||||
]);
|
||||
|
||||
DB::table('tenants')
|
||||
->where('codigo', 'sonder')
|
||||
->update([
|
||||
'display_categories' => true,
|
||||
'display_seach_bar' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function down(): void {}
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
<?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
|
||||
{
|
||||
DB::table('websites_extras')
|
||||
->whereNull('is_enabled')
|
||||
->update(['is_enabled' => true]);
|
||||
|
||||
Schema::table('websites_extras', function (Blueprint $table): void {
|
||||
$table->boolean('is_enabled')->default(true)->nullable(false)->change();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('websites_extras', function (Blueprint $table): void {
|
||||
$table->boolean('is_enabled')->nullable()->default(null)->change();
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use App\Domains\Ticket\Enums\TicketGenerationPolicy;
|
||||
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('catalog_items', function (Blueprint $table): void {
|
||||
$table->enum('ticket_generation_policy', TicketGenerationPolicy::values())
|
||||
->default(TicketGenerationPolicy::PerEventDate->value)
|
||||
->after('has_tickets');
|
||||
});
|
||||
|
||||
DB::table('catalog_items')
|
||||
->where('tenant_code', 'fiesta_futbol_infantil')
|
||||
->update([
|
||||
'ticket_generation_policy' => TicketGenerationPolicy::OnePerUnit->value,
|
||||
]);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('catalog_items', function (Blueprint $table): void {
|
||||
$table->dropColumn('ticket_generation_policy');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,63 @@
|
||||
<?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::create('ticket_validity_times', function (Blueprint $table): void {
|
||||
$table->foreignId('ticket_id')
|
||||
->constrained('tickets')
|
||||
->cascadeOnUpdate()
|
||||
->cascadeOnDelete();
|
||||
$table->foreignId('validity_time_id')
|
||||
->constrained('validity_times')
|
||||
->cascadeOnUpdate()
|
||||
->restrictOnDelete();
|
||||
|
||||
$table->primary(['ticket_id', 'validity_time_id']);
|
||||
});
|
||||
|
||||
DB::table('ticket_validity_times')->insertUsing(
|
||||
['ticket_id', 'validity_time_id'],
|
||||
DB::table('tickets')
|
||||
->select(['id', 'validity_time_id'])
|
||||
->whereNotNull('validity_time_id'),
|
||||
);
|
||||
|
||||
Schema::table('tickets', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('validity_time_id');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('tickets', function (Blueprint $table): void {
|
||||
$table->foreignId('validity_time_id')
|
||||
->nullable()
|
||||
->after('source_variant_id')
|
||||
->constrained('validity_times')
|
||||
->cascadeOnUpdate()
|
||||
->restrictOnDelete();
|
||||
});
|
||||
|
||||
DB::table('ticket_validity_times')
|
||||
->orderBy('ticket_id')
|
||||
->orderBy('validity_time_id')
|
||||
->get()
|
||||
->groupBy('ticket_id')
|
||||
->each(function ($validityTimes, int|string $ticketId): void {
|
||||
DB::table('tickets')
|
||||
->where('id', $ticketId)
|
||||
->update([
|
||||
'validity_time_id' => $validityTimes->first()->validity_time_id,
|
||||
]);
|
||||
});
|
||||
|
||||
Schema::dropIfExists('ticket_validity_times');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,68 @@
|
||||
<?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('event_dates', function (Blueprint $table): void {
|
||||
$table->unsignedBigInteger('validity_time_id')
|
||||
->nullable()
|
||||
->unique()
|
||||
->after('id');
|
||||
});
|
||||
|
||||
DB::table('event_dates')
|
||||
->orderBy('id')
|
||||
->each(function (object $eventDate): void {
|
||||
$startsAt = $eventDate->date.' '.$eventDate->time_start;
|
||||
$expiresAt = $eventDate->date.' '.$eventDate->time_end;
|
||||
|
||||
if (strtotime($expiresAt) <= strtotime($startsAt)) {
|
||||
$expiresAt = date('Y-m-d H:i:s', strtotime($expiresAt.' +1 day'));
|
||||
}
|
||||
|
||||
$validityTimeId = DB::table('validity_times')->insertGetId([
|
||||
'type' => 'fixed_window',
|
||||
'start_time' => null,
|
||||
'end_time' => null,
|
||||
'fixed_starts_at' => $startsAt,
|
||||
'fixed_expires_at' => $expiresAt,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
DB::table('event_dates')
|
||||
->where('id', $eventDate->id)
|
||||
->update(['validity_time_id' => $validityTimeId]);
|
||||
});
|
||||
|
||||
Schema::table('event_dates', function (Blueprint $table): void {
|
||||
$table->unsignedBigInteger('validity_time_id')->nullable(false)->change();
|
||||
$table->foreign('validity_time_id')
|
||||
->references('id')
|
||||
->on('validity_times')
|
||||
->restrictOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$validityTimeIds = DB::table('event_dates')
|
||||
->pluck('validity_time_id')
|
||||
->filter()
|
||||
->all();
|
||||
|
||||
Schema::table('event_dates', function (Blueprint $table): void {
|
||||
$table->dropForeign(['validity_time_id']);
|
||||
$table->dropUnique(['validity_time_id']);
|
||||
$table->dropColumn('validity_time_id');
|
||||
});
|
||||
|
||||
DB::table('validity_times')->whereIn('id', $validityTimeIds)->delete();
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,88 @@
|
||||
<?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::create('ticket_validity_groups', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->foreignId('ticket_id')
|
||||
->constrained('tickets')
|
||||
->cascadeOnUpdate()
|
||||
->cascadeOnDelete();
|
||||
});
|
||||
|
||||
Schema::create('ticket_validity_group_times', function (Blueprint $table): void {
|
||||
$table->foreignId('ticket_validity_group_id')
|
||||
->constrained('ticket_validity_groups')
|
||||
->cascadeOnUpdate()
|
||||
->cascadeOnDelete();
|
||||
$table->foreignId('validity_time_id')
|
||||
->constrained('validity_times')
|
||||
->cascadeOnUpdate()
|
||||
->restrictOnDelete();
|
||||
|
||||
$table->primary(['ticket_validity_group_id', 'validity_time_id']);
|
||||
});
|
||||
|
||||
// Every former pivot row was an OR alternative, so each one becomes
|
||||
// an independent group to preserve existing ticket behavior.
|
||||
DB::table('ticket_validity_times')
|
||||
->orderBy('ticket_id')
|
||||
->orderBy('validity_time_id')
|
||||
->each(function (object $association): void {
|
||||
$groupId = DB::table('ticket_validity_groups')->insertGetId([
|
||||
'ticket_id' => $association->ticket_id,
|
||||
]);
|
||||
|
||||
DB::table('ticket_validity_group_times')->insert([
|
||||
'ticket_validity_group_id' => $groupId,
|
||||
'validity_time_id' => $association->validity_time_id,
|
||||
]);
|
||||
});
|
||||
|
||||
Schema::dropIfExists('ticket_validity_times');
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::create('ticket_validity_times', function (Blueprint $table): void {
|
||||
$table->foreignId('ticket_id')
|
||||
->constrained('tickets')
|
||||
->cascadeOnUpdate()
|
||||
->cascadeOnDelete();
|
||||
$table->foreignId('validity_time_id')
|
||||
->constrained('validity_times')
|
||||
->cascadeOnUpdate()
|
||||
->restrictOnDelete();
|
||||
|
||||
$table->primary(['ticket_id', 'validity_time_id']);
|
||||
});
|
||||
|
||||
DB::table('ticket_validity_group_times')
|
||||
->join(
|
||||
'ticket_validity_groups',
|
||||
'ticket_validity_groups.id',
|
||||
'=',
|
||||
'ticket_validity_group_times.ticket_validity_group_id',
|
||||
)
|
||||
->select([
|
||||
'ticket_validity_groups.ticket_id',
|
||||
'ticket_validity_group_times.validity_time_id',
|
||||
])
|
||||
->distinct()
|
||||
->orderBy('ticket_validity_groups.ticket_id')
|
||||
->each(fn (object $association) => DB::table('ticket_validity_times')->insert([
|
||||
'ticket_id' => $association->ticket_id,
|
||||
'validity_time_id' => $association->validity_time_id,
|
||||
]));
|
||||
|
||||
Schema::dropIfExists('ticket_validity_group_times');
|
||||
Schema::dropIfExists('ticket_validity_groups');
|
||||
}
|
||||
};
|
||||
@@ -5,6 +5,8 @@ namespace Database\Seeders;
|
||||
use App\Domains\Catalog\Models\Attribute;
|
||||
use App\Domains\Shared\Enums\FieldType;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Ticket\Enums\ValidityTimeType;
|
||||
use App\Domains\Ticket\Models\ValidityTime;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class AttributeSeeder extends Seeder
|
||||
@@ -17,12 +19,8 @@ class AttributeSeeder extends Seeder
|
||||
$tenants = Tenant::all();
|
||||
|
||||
foreach ($tenants as $tenant) {
|
||||
// Event dates replace catalog attributes for Fiesta Futbol Infantil.
|
||||
if ($tenant->codigo === 'fiesta_futbol_infantil') {
|
||||
Attribute::query()
|
||||
->where('tenant_codigo', $tenant->codigo)
|
||||
->whereIn('codigo', ['color', 'talle', 'talle_numerico', 'fecha'])
|
||||
->delete();
|
||||
$this->seedFiestaFutbolInfantilAttributes($tenant);
|
||||
|
||||
continue;
|
||||
}
|
||||
@@ -91,23 +89,130 @@ class AttributeSeeder extends Seeder
|
||||
],
|
||||
]);
|
||||
|
||||
// Seed Fecha attribute
|
||||
// Las opciones de fecha se resuelven dinámicamente desde event_dates.
|
||||
$this->seedAttribute($tenant, [
|
||||
'codigo' => 'fecha',
|
||||
'codigo' => 'event_date',
|
||||
'nombre' => 'Fecha',
|
||||
'type' => FieldType::Select->value,
|
||||
'type' => FieldType::EventDate->value,
|
||||
'is_required' => true,
|
||||
'options' => [
|
||||
['value' => '2026-10-09', 'label' => '09/10/2026', 'sort_order' => 1],
|
||||
['value' => '2026-10-10', 'label' => '10/10/2026', 'sort_order' => 2],
|
||||
['value' => '2026-10-11', 'label' => '11/10/2026', 'sort_order' => 3],
|
||||
['value' => '2026-10-12', 'label' => '12/10/2026', 'sort_order' => 4],
|
||||
],
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private function seedFiestaFutbolInfantilAttributes(Tenant $tenant): void
|
||||
{
|
||||
Attribute::query()
|
||||
->where('tenant_codigo', $tenant->codigo)
|
||||
->whereNotIn('codigo', [
|
||||
'event_date',
|
||||
'servicio',
|
||||
'color',
|
||||
'horario',
|
||||
'talle',
|
||||
'tipo_alojamiento',
|
||||
])
|
||||
->delete();
|
||||
|
||||
$this->seedAttribute($tenant, [
|
||||
'codigo' => 'event_date',
|
||||
'nombre' => 'Fecha',
|
||||
'type' => FieldType::EventDate->value,
|
||||
'is_required' => true,
|
||||
]);
|
||||
|
||||
$breakfastValidityTime = $this->timeWindow('07:00:00', '12:00:00');
|
||||
$lunchValidityTime = $this->timeWindow('12:00:00', '15:00:00');
|
||||
$dinnerValidityTime = $this->timeWindow('20:00:00', '24:00:00');
|
||||
|
||||
$this->seedAttribute($tenant, [
|
||||
'codigo' => 'tipo_alojamiento',
|
||||
'nombre' => 'TipoAlojamiento',
|
||||
'type' => FieldType::Select->value,
|
||||
'is_required' => true,
|
||||
'options' => [
|
||||
['value' => 'Carpa', 'label' => 'Carpa', 'sort_order' => 1],
|
||||
['value' => 'Motorhome', 'label' => 'Motorhome', 'sort_order' => 2],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->seedAttribute($tenant, [
|
||||
'codigo' => 'servicio',
|
||||
'nombre' => 'Servicio',
|
||||
'type' => FieldType::Select->value,
|
||||
'is_required' => true,
|
||||
'options' => [
|
||||
['value' => 'Comedor', 'label' => 'Comedor', 'sort_order' => 1],
|
||||
['value' => 'Vianda', 'label' => 'Vianda', 'sort_order' => 2],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->seedAttribute($tenant, [
|
||||
'codigo' => 'color',
|
||||
'nombre' => 'Color',
|
||||
'type' => FieldType::Select->value,
|
||||
'is_required' => true,
|
||||
'metadata_schema' => [
|
||||
'hex' => ['type' => 'string'],
|
||||
],
|
||||
'options' => [
|
||||
['value' => 'Verde', 'label' => 'Verde', 'sort_order' => 1, 'metadata' => ['hex' => '#00973F']],
|
||||
['value' => 'Blanco', 'label' => 'Blanco', 'sort_order' => 2, 'metadata' => ['hex' => '#FFFFFF']],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->seedAttribute($tenant, [
|
||||
'codigo' => 'horario',
|
||||
'nombre' => 'Horario',
|
||||
'type' => FieldType::Select->value,
|
||||
'is_required' => true,
|
||||
'options' => [
|
||||
[
|
||||
'value' => 'Desayuno',
|
||||
'label' => 'Desayuno',
|
||||
'sort_order' => 1,
|
||||
'validity_time_id' => $breakfastValidityTime->id,
|
||||
],
|
||||
[
|
||||
'value' => 'Almuerzo',
|
||||
'label' => 'Almuerzo',
|
||||
'sort_order' => 2,
|
||||
'validity_time_id' => $lunchValidityTime->id,
|
||||
],
|
||||
[
|
||||
'value' => 'Cena',
|
||||
'label' => 'Cena',
|
||||
'sort_order' => 3,
|
||||
'validity_time_id' => $dinnerValidityTime->id,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->seedAttribute($tenant, [
|
||||
'codigo' => 'talle',
|
||||
'nombre' => 'Talle',
|
||||
'type' => FieldType::Select->value,
|
||||
'is_required' => true,
|
||||
'options' => [
|
||||
['value' => '14', 'label' => '14', 'sort_order' => 1],
|
||||
['value' => 'S', 'label' => 'S', 'sort_order' => 2],
|
||||
['value' => 'M', 'label' => 'M', 'sort_order' => 3],
|
||||
['value' => 'L', 'label' => 'L', 'sort_order' => 4],
|
||||
['value' => 'XL', 'label' => 'XL', 'sort_order' => 5],
|
||||
['value' => 'XXL', 'label' => 'XXL', 'sort_order' => 6],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
private function timeWindow(string $startTime, string $endTime): ValidityTime
|
||||
{
|
||||
return ValidityTime::query()->firstOrCreate([
|
||||
'type' => ValidityTimeType::TimeWindow,
|
||||
'start_time' => $startTime,
|
||||
'end_time' => $endTime,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
||||
use App\Domains\Catalog\Enums\EventProductType;
|
||||
use App\Domains\Catalog\Enums\FeaturedGroupSource;
|
||||
use App\Domains\Catalog\Enums\GroupLayout;
|
||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||
@@ -12,8 +10,8 @@ use App\Domains\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Catalog\Models\Category;
|
||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||
use App\Domains\Catalog\Services\CatalogService;
|
||||
use App\Domains\Event\Models\Event;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Ticket\Enums\TicketGenerationPolicy;
|
||||
use Illuminate\Database\Seeder;
|
||||
use RuntimeException;
|
||||
|
||||
@@ -30,151 +28,104 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
||||
}
|
||||
|
||||
$this->deleteExistingCatalog($tenant);
|
||||
FeaturedGroup::query()->where('tenant_code', $tenant->codigo)->delete();
|
||||
Category::query()->where('tenant_code', $tenant->codigo)->update(['categoria_id' => null]);
|
||||
Category::query()->where('tenant_code', $tenant->codigo)->delete();
|
||||
|
||||
$event = Event::query()->updateOrCreate(
|
||||
[
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'name' => 'Fiesta Nacional del Fútbol Infantil',
|
||||
],
|
||||
['address' => 'Sunchales, Santa Fe'],
|
||||
);
|
||||
$event->dates()->delete();
|
||||
$categories = collect([
|
||||
'entradas' => 'Entradas',
|
||||
'alojamientos' => 'Alojamientos',
|
||||
'comidas' => 'Comidas',
|
||||
'merchandising' => 'Merchandising',
|
||||
])->map(fn (string $name): Category => Category::query()->create([
|
||||
'nombre' => $name,
|
||||
'tenant_code' => $tenant->codigo,
|
||||
]));
|
||||
|
||||
$tenant->update([
|
||||
'event_title' => 'Fiesta Nacional del Fútbol Infantil',
|
||||
'event_location' => 'Sunchales, Santa Fe',
|
||||
]);
|
||||
|
||||
$tenant->eventDates()->delete();
|
||||
$eventDates = collect(['2026-10-09', '2026-10-10', '2026-10-11', '2026-10-12'])
|
||||
->mapWithKeys(function (string $date) use ($event): array {
|
||||
$eventDate = $event->dates()->create([
|
||||
'date' => $date,
|
||||
'time_start' => '00:00:00',
|
||||
'time_end' => '23:59:59',
|
||||
]);
|
||||
->map(fn (string $date) => $tenant->eventDates()->create([
|
||||
'date' => $date,
|
||||
'time_start' => '00:00:00',
|
||||
'time_end' => '23:59:59',
|
||||
]));
|
||||
$dateIds = $eventDates->pluck('id')->map(fn ($id): int => (int) $id)->values();
|
||||
|
||||
return [$date => $eventDate];
|
||||
});
|
||||
|
||||
$tenant->active_event_id = $event->id;
|
||||
$tenant->save();
|
||||
|
||||
$ticketCategory = Category::query()->firstOrCreate([
|
||||
'nombre' => 'Entradas',
|
||||
'tenant_code' => $tenant->codigo,
|
||||
]);
|
||||
$foodCategory = Category::query()->firstOrCreate([
|
||||
'nombre' => 'Gastronomía',
|
||||
'tenant_code' => $tenant->codigo,
|
||||
]);
|
||||
$mealCategory = Category::query()->updateOrCreate([
|
||||
'nombre' => 'Comidas',
|
||||
'tenant_code' => $tenant->codigo,
|
||||
], [
|
||||
'categoria_id' => $foodCategory->id,
|
||||
]);
|
||||
$drinkCategory = Category::query()->updateOrCreate([
|
||||
'nombre' => 'Bebidas',
|
||||
'tenant_code' => $tenant->codigo,
|
||||
], [
|
||||
'categoria_id' => $foodCategory->id,
|
||||
]);
|
||||
$parkingCategory = Category::query()->firstOrCreate([
|
||||
'nombre' => 'Estacionamiento',
|
||||
'tenant_code' => $tenant->codigo,
|
||||
$this->createProduct($tenant, [
|
||||
'slug' => 'camiseta',
|
||||
'nombre' => 'Camiseta',
|
||||
'category_id' => $categories['merchandising']->id,
|
||||
'precio' => 18000,
|
||||
'attribute_codes' => ['color', 'talle'],
|
||||
'variants' => collect(['Verde', 'Blanco'])
|
||||
->crossJoin(['14', 'S', 'M', 'L', 'XL', 'XXL'])
|
||||
->map(fn (array $values, int $index): array => [
|
||||
'real_stock' => [24, 3, 18, 0, 12, 2, 25, 0, 14, 1, 19, 8][$index],
|
||||
'values' => ['color' => $values[0], 'talle' => $values[1]],
|
||||
])->all(),
|
||||
]);
|
||||
|
||||
$dates = $eventDates->keys()->all();
|
||||
$minimumUseDate = $dates[0].' 00:00:00';
|
||||
$maximumUseDate = $dates[array_key_last($dates)].' 23:59:59';
|
||||
|
||||
$generalAdmission = $this->catalogService->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'event_id' => $event->id,
|
||||
'event_product_type' => EventProductType::Entry->value,
|
||||
'category_id' => $ticketCategory->id,
|
||||
'slug' => 'entrada-general',
|
||||
'nombre' => 'Entrada General',
|
||||
'descripcion' => 'Acceso total al predio. No incluye acceso a estacionamiento. Niños menores de 5 años ingresan gratis.',
|
||||
'precio' => 10000,
|
||||
'inventory_policy' => InventoryPolicy::Unlimited->value,
|
||||
'has_tickets' => true,
|
||||
'minimum_use_date' => $minimumUseDate,
|
||||
'maximum_use_date' => $maximumUseDate,
|
||||
'variants' => array_map(
|
||||
fn (string $date): array => [
|
||||
'real_stock' => 0,
|
||||
'event_date_id' => $eventDates->get($date)->id,
|
||||
],
|
||||
$dates,
|
||||
),
|
||||
$this->createProduct($tenant, [
|
||||
'slug' => 'alojamiento',
|
||||
'nombre' => 'Alojamiento',
|
||||
'category_id' => $categories['alojamientos']->id,
|
||||
'precio' => 35000,
|
||||
'attribute_codes' => ['tipo_alojamiento'],
|
||||
'variants' => collect(['Carpa', 'Motorhome'])->map(fn (string $type, int $index): array => [
|
||||
'real_stock' => [0, 3][$index],
|
||||
'values' => ['tipo_alojamiento' => $type],
|
||||
])->all(),
|
||||
]);
|
||||
|
||||
$items = [
|
||||
['slug' => 'hamburguesa-papa-frita', 'nombre' => 'Hamburguesa con papa frita', 'precio' => 8000, 'category_id' => $mealCategory->id],
|
||||
['slug' => 'pancho', 'nombre' => 'Pancho', 'precio' => 4000, 'category_id' => $mealCategory->id],
|
||||
['slug' => 'coca-cola-500ml', 'nombre' => 'Coca Cola 500ml', 'precio' => 3000, 'category_id' => $drinkCategory->id],
|
||||
['slug' => 'agua-mineral-1l', 'nombre' => 'Agua Mineral 1L', 'precio' => 2500, 'category_id' => $drinkCategory->id],
|
||||
['slug' => 'estacionamiento-auto', 'nombre' => 'Estacionamiento Auto', 'precio' => 5000, 'category_id' => $parkingCategory->id],
|
||||
['slug' => 'estacionamiento-moto', 'nombre' => 'Estacionamiento Moto', 'precio' => 2000, 'category_id' => $parkingCategory->id],
|
||||
];
|
||||
$this->createProduct($tenant, [
|
||||
'slug' => 'comida',
|
||||
'nombre' => 'Comida',
|
||||
'category_id' => $categories['comidas']->id,
|
||||
'precio' => 4000,
|
||||
'attribute_codes' => ['event_date', 'horario', 'servicio'],
|
||||
'variants' => $eventDates
|
||||
->crossJoin(['Desayuno', 'Almuerzo', 'Cena'], ['Comedor', 'Vianda'])
|
||||
->map(fn (array $values, int $index): array => [
|
||||
'real_stock' => [80, 3, 65, 0, 42, 2, 70, 18, 0, 5, 55, 40, 90, 1, 35, 0, 60, 8, 75, 22, 0, 4, 50, 30][$index],
|
||||
'event_date_ids' => [(int) $values[0]->id],
|
||||
'descripcion' => sprintf(
|
||||
'%s del %s - %s',
|
||||
$values[1],
|
||||
$values[0]->date->format('d/m/Y'),
|
||||
$values[2],
|
||||
),
|
||||
'precio' => $this->foodPrice($values[1]),
|
||||
'values' => ['horario' => $values[1], 'servicio' => $values[2]],
|
||||
])->all(),
|
||||
]);
|
||||
|
||||
$createdItems = [];
|
||||
foreach ($items as $item) {
|
||||
$createdItems[$item['slug']] = $this->catalogService->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'event_id' => $event->id,
|
||||
'event_product_type' => EventProductType::Product->value,
|
||||
'descripcion' => $item['descripcion'] ?? $item['nombre'],
|
||||
'inventory_policy' => InventoryPolicy::Unlimited->value,
|
||||
'real_stock' => 0,
|
||||
'minimum_use_date' => $minimumUseDate,
|
||||
'maximum_use_date' => $maximumUseDate,
|
||||
...$item,
|
||||
]);
|
||||
}
|
||||
|
||||
$this->catalogService->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'event_id' => $event->id,
|
||||
'event_product_type' => EventProductType::Entry->value,
|
||||
'type' => CatalogItemType::Bundle->value,
|
||||
'slug' => 'entrada-general-todos-los-dias',
|
||||
'nombre' => 'Entrada General - Todos los días',
|
||||
'descripcion' => 'Incluye una entrada para cada día de la Fiesta Nacional del Fútbol Infantil.',
|
||||
$this->createProduct($tenant, [
|
||||
'slug' => 'abono',
|
||||
'nombre' => 'Abono',
|
||||
'category_id' => $categories['entradas']->id,
|
||||
'precio' => 40000,
|
||||
'category_id' => $ticketCategory->id,
|
||||
'components' => $generalAdmission->variants
|
||||
->map(fn ($variant): array => [
|
||||
'catalog_item_id' => $generalAdmission->id,
|
||||
'variant_id' => $variant->id,
|
||||
'quantity' => 1,
|
||||
])
|
||||
->all(),
|
||||
'has_tickets' => true,
|
||||
'attribute_codes' => ['event_date'],
|
||||
'multi_select_attribute_codes' => ['event_date'],
|
||||
'variants' => [[
|
||||
'real_stock' => 120,
|
||||
'event_date_ids' => $dateIds->all(),
|
||||
]],
|
||||
]);
|
||||
|
||||
$this->catalogService->create([
|
||||
FeaturedGroup::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'event_id' => $event->id,
|
||||
'event_product_type' => EventProductType::Product->value,
|
||||
'type' => CatalogItemType::Bundle->value,
|
||||
'slug' => 'combo-2-panchos-2-hamburguesas',
|
||||
'nombre' => 'Combo 2 Panchos + 2 Hamburguesas',
|
||||
'descripcion' => 'Incluye 2 panchos y 2 hamburguesas con papa frita.',
|
||||
'precio' => 24000,
|
||||
'category_id' => $mealCategory->id,
|
||||
'components' => [
|
||||
[
|
||||
'catalog_item_id' => $createdItems['pancho']->id,
|
||||
'quantity' => 2,
|
||||
],
|
||||
[
|
||||
'catalog_item_id' => $createdItems['hamburguesa-papa-frita']->id,
|
||||
'quantity' => 2,
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
$this->seedFeaturedGroups($tenant, [
|
||||
'Entradas' => $ticketCategory,
|
||||
'Estacionamiento' => $parkingCategory,
|
||||
'Comidas' => $mealCategory,
|
||||
'Bebidas' => $drinkCategory,
|
||||
'source_type' => FeaturedGroupSource::All,
|
||||
'category_id' => null,
|
||||
'product_layout' => ProductLayout::Row,
|
||||
'group_layout' => GroupLayout::SimpleVertical,
|
||||
'group_name' => 'Productos',
|
||||
'group_order' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -182,51 +133,30 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
||||
{
|
||||
CatalogItem::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->where('type', CatalogItemType::Bundle->value)
|
||||
->each(fn (CatalogItem $item) => $this->catalogService->delete($item));
|
||||
|
||||
CatalogItem::query()
|
||||
->where('tenant_code', $tenant->codigo)
|
||||
->where('type', CatalogItemType::Standard->value)
|
||||
->orderByRaw("CASE WHEN type = 'bundle' THEN 0 ELSE 1 END")
|
||||
->each(fn (CatalogItem $item) => $this->catalogService->delete($item));
|
||||
}
|
||||
|
||||
/** @param array<string, Category> $categories */
|
||||
private function seedFeaturedGroups(Tenant $tenant, array $categories): void
|
||||
/** @param array<string, mixed> $data */
|
||||
private function createProduct(Tenant $tenant, array $data): CatalogItem
|
||||
{
|
||||
FeaturedGroup::query()->where('tenant_code', $tenant->codigo)->delete();
|
||||
return $this->catalogService->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'descripcion' => $data['nombre'],
|
||||
'inventory_policy' => InventoryPolicy::Tracked->value,
|
||||
...$data,
|
||||
'has_tickets' => true,
|
||||
'ticket_generation_policy' => TicketGenerationPolicy::OnePerUnit->value,
|
||||
]);
|
||||
}
|
||||
|
||||
$groups = [
|
||||
'Entradas' => [
|
||||
'product_layout' => ProductLayout::Row,
|
||||
'group_layout' => GroupLayout::SimpleVertical,
|
||||
],
|
||||
'Estacionamiento' => [
|
||||
'product_layout' => ProductLayout::ColumnWithCart,
|
||||
'group_layout' => GroupLayout::Simple,
|
||||
],
|
||||
'Comidas' => [
|
||||
'product_layout' => ProductLayout::ColumnWithCart,
|
||||
'group_layout' => GroupLayout::Simple,
|
||||
],
|
||||
'Bebidas' => [
|
||||
'product_layout' => ProductLayout::ColumnWithCart,
|
||||
'group_layout' => GroupLayout::Simple,
|
||||
],
|
||||
];
|
||||
|
||||
$groupOrder = 0;
|
||||
foreach ($groups as $groupName => $config) {
|
||||
FeaturedGroup::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'source_type' => FeaturedGroupSource::Category,
|
||||
'category_id' => $categories[$groupName]->id,
|
||||
'product_layout' => $config['product_layout'],
|
||||
'group_layout' => $config['group_layout'],
|
||||
'group_name' => $groupName,
|
||||
'group_order' => $groupOrder++,
|
||||
]);
|
||||
|
||||
}
|
||||
private function foodPrice(string $schedule): int
|
||||
{
|
||||
return match ($schedule) {
|
||||
'Desayuno' => 4000,
|
||||
'Almuerzo' => 10000,
|
||||
'Cena' => 8000,
|
||||
default => throw new RuntimeException("Horario de comida desconocido: {$schedule}"),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,30 @@ class MenuSeeder extends Seeder
|
||||
'parent_menu_code' => 'main.adminapp',
|
||||
'route' => '/admin/staff',
|
||||
],
|
||||
[
|
||||
'code' => 'adminapp.fiesta-futbol-infantil.entradas',
|
||||
'label' => 'Entradas',
|
||||
'parent_menu_code' => 'main.adminapp',
|
||||
'route' => '/admin/entradas',
|
||||
],
|
||||
[
|
||||
'code' => 'adminapp.fiesta-futbol-infantil.alojamientos',
|
||||
'label' => 'Alojamientos',
|
||||
'parent_menu_code' => 'main.adminapp',
|
||||
'route' => '/admin/alojamientos',
|
||||
],
|
||||
[
|
||||
'code' => 'adminapp.fiesta-futbol-infantil.merchandising',
|
||||
'label' => 'Merchandising',
|
||||
'parent_menu_code' => 'main.adminapp',
|
||||
'route' => '/admin/merchandising',
|
||||
],
|
||||
[
|
||||
'code' => 'adminapp.fiesta-futbol-infantil.comida',
|
||||
'label' => 'Comida',
|
||||
'parent_menu_code' => 'main.adminapp',
|
||||
'route' => '/admin/comidas',
|
||||
],
|
||||
[
|
||||
'code' => 'account',
|
||||
'label' => 'Mi cuenta',
|
||||
@@ -222,6 +246,18 @@ class MenuSeeder extends Seeder
|
||||
'sonder',
|
||||
'fiesta_futbol_infantil',
|
||||
];
|
||||
$fiestaCategoryMenuCodes = [
|
||||
'adminapp.fiesta-futbol-infantil.entradas',
|
||||
'adminapp.fiesta-futbol-infantil.alojamientos',
|
||||
'adminapp.fiesta-futbol-infantil.merchandising',
|
||||
'adminapp.fiesta-futbol-infantil.comida',
|
||||
];
|
||||
$fiestaExcludedAdminMenuCodes = [
|
||||
'adminapp.inicio',
|
||||
'adminapp.catalog',
|
||||
'adminapp.categories',
|
||||
'adminapp.combos',
|
||||
];
|
||||
$frequentlyAskedQuestions = [
|
||||
[
|
||||
'pregunta' => '¿Hay algún límite de compra?',
|
||||
@@ -279,6 +315,12 @@ class MenuSeeder extends Seeder
|
||||
$menuCodes = array_diff($menuCodes, $helpMenuCodes);
|
||||
}
|
||||
|
||||
if ($tenant->codigo !== 'fiesta_futbol_infantil') {
|
||||
$menuCodes = array_diff($menuCodes, $fiestaCategoryMenuCodes);
|
||||
} else {
|
||||
$menuCodes = array_diff($menuCodes, $fiestaExcludedAdminMenuCodes);
|
||||
}
|
||||
|
||||
// Usar sync para asociar los menues al tenant
|
||||
$tenant->menues()->sync($menuCodes);
|
||||
|
||||
|
||||
@@ -56,6 +56,8 @@ class TenantSeeder extends Seeder
|
||||
'success_color' => '#198754',
|
||||
'header_bg_color' => '#ffffff',
|
||||
'footer_bg_color' => '#313131',
|
||||
'display_categories' => true,
|
||||
'display_seach_bar' => true,
|
||||
'header_logo' => $this->uploadedImage('images/tennants/sonder/sonder_header.png', 'sonder_header.png'),
|
||||
'footer_logo' => $this->uploadedImage('images/tennants/sonder/sonder_footer.png', 'sonder_footer.png'),
|
||||
'social_media' => self::SOCIAL_MEDIA,
|
||||
@@ -107,6 +109,8 @@ class TenantSeeder extends Seeder
|
||||
'success_color' => '#198754',
|
||||
'header_bg_color' => '#ffffff',
|
||||
'footer_bg_color' => '#015327',
|
||||
'display_categories' => false,
|
||||
'display_seach_bar' => false,
|
||||
'header_logo' => $this->uploadedImage(
|
||||
'images/tennants/fiesta_futbol_infantil/futbol_infantil_header.png',
|
||||
'futbol_infantil_header.png',
|
||||
|
||||
Reference in New Issue
Block a user