From 5296d595f12506022e8b026f4c97b0a1f65eee5d Mon Sep 17 00:00:00 2001 From: ncoronel Date: Wed, 23 Sep 2026 16:28:24 -0300 Subject: [PATCH] feat(desfile): add entry reservation model --- .../Commerce/Catalog/Models/Variant.php | 9 ++++- .../Enums/EntryReservationPaymentType.php | 29 +++++++++++++++ .../Desfile/Models/EntryReservation.php | 36 +++++++++++++++++++ ...reate_desfile_entry_reservations_table.php | 29 +++++++++++++++ .../Desfile/EntryReservationSchemaTest.php | 23 ++++++++++++ tests/Unit/Desfile/EntryReservationTest.php | 30 ++++++++++++++++ 6 files changed, 155 insertions(+), 1 deletion(-) create mode 100644 app/Domains/Ticketing/Desfile/Enums/EntryReservationPaymentType.php create mode 100644 app/Domains/Ticketing/Desfile/Models/EntryReservation.php create mode 100644 database/migrations/2026_09_23_010000_create_desfile_entry_reservations_table.php create mode 100644 tests/Feature/Desfile/EntryReservationSchemaTest.php create mode 100644 tests/Unit/Desfile/EntryReservationTest.php diff --git a/app/Domains/Commerce/Catalog/Models/Variant.php b/app/Domains/Commerce/Catalog/Models/Variant.php index 3e63704..dd5a622 100644 --- a/app/Domains/Commerce/Catalog/Models/Variant.php +++ b/app/Domains/Commerce/Catalog/Models/Variant.php @@ -2,9 +2,10 @@ namespace App\Domains\Commerce\Catalog\Models; -use App\Shared\Attachable\Models\Attachment; +use App\Domains\Ticketing\Desfile\Models\EntryReservation; use App\Domains\Ticketing\Event\Models\EventDate; use App\Domains\Ticketing\Ticket\Models\Ticket; +use App\Shared\Attachable\Models\Attachment; use Illuminate\Database\Eloquent\Attributes\Fillable; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -74,6 +75,12 @@ class Variant extends Model return $this->hasMany(Ticket::class, 'source_variant_id'); } + /** @return HasMany */ + public function desfileEntryReservations(): HasMany + { + return $this->hasMany(EntryReservation::class); + } + /** @return BelongsTo */ public function inventory(): BelongsTo { diff --git a/app/Domains/Ticketing/Desfile/Enums/EntryReservationPaymentType.php b/app/Domains/Ticketing/Desfile/Enums/EntryReservationPaymentType.php new file mode 100644 index 0000000..bec60e8 --- /dev/null +++ b/app/Domains/Ticketing/Desfile/Enums/EntryReservationPaymentType.php @@ -0,0 +1,29 @@ + 'Sin cargo', + self::Other => 'Otro método', + }; + } + + /** @return list */ + public static function options(): array + { + return array_map( + fn (self $type): array => [ + 'value' => $type->value, + 'label' => $type->label(), + ], + self::cases(), + ); + } +} diff --git a/app/Domains/Ticketing/Desfile/Models/EntryReservation.php b/app/Domains/Ticketing/Desfile/Models/EntryReservation.php new file mode 100644 index 0000000..6af818b --- /dev/null +++ b/app/Domains/Ticketing/Desfile/Models/EntryReservation.php @@ -0,0 +1,36 @@ + 'integer', + 'fecha_reserva' => 'datetime', + 'importe' => 'decimal:2', + 'tipo_pago' => EntryReservationPaymentType::class, + ]; + } + + /** @return BelongsTo */ + public function variant(): BelongsTo + { + return $this->belongsTo(Variant::class)->withTrashed(); + } +} diff --git a/database/migrations/2026_09_23_010000_create_desfile_entry_reservations_table.php b/database/migrations/2026_09_23_010000_create_desfile_entry_reservations_table.php new file mode 100644 index 0000000..c167919 --- /dev/null +++ b/database/migrations/2026_09_23_010000_create_desfile_entry_reservations_table.php @@ -0,0 +1,29 @@ +id(); + $table->foreignId('variant_id') + ->constrained('variantes') + ->restrictOnDelete(); + $table->timestamp('fecha_reserva'); + $table->decimal('importe', 10, 2)->nullable(); + $table->string('tipo_pago', 24); + $table->timestamps(); + + $table->index(['fecha_reserva', 'tipo_pago']); + }); + } + + public function down(): void + { + Schema::dropIfExists('desfile_entry_reservations'); + } +}; diff --git a/tests/Feature/Desfile/EntryReservationSchemaTest.php b/tests/Feature/Desfile/EntryReservationSchemaTest.php new file mode 100644 index 0000000..7cc68d8 --- /dev/null +++ b/tests/Feature/Desfile/EntryReservationSchemaTest.php @@ -0,0 +1,23 @@ +assertTrue(Schema::hasColumns('desfile_entry_reservations', [ + 'id', + 'variant_id', + 'fecha_reserva', + 'importe', + 'tipo_pago', + ])); + } +} diff --git a/tests/Unit/Desfile/EntryReservationTest.php b/tests/Unit/Desfile/EntryReservationTest.php new file mode 100644 index 0000000..a8c73dc --- /dev/null +++ b/tests/Unit/Desfile/EntryReservationTest.php @@ -0,0 +1,30 @@ +assertSame([ + ['value' => 'sin_cargo', 'label' => 'Sin cargo'], + ['value' => 'otro_metodo', 'label' => 'Otro método'], + ], EntryReservationPaymentType::options()); + } + + public function test_it_defines_the_requested_fillable_fields(): void + { + $reservation = new EntryReservation; + + $this->assertSame([ + 'variant_id', + 'fecha_reserva', + 'importe', + 'tipo_pago', + ], $reservation->getFillable()); + } +}