feat(ticket): add entry reservation handling to ticket refund logic and tests
This commit is contained in:
@@ -7,6 +7,7 @@ use App\Domains\Commerce\Catalog\Models\Variant;
|
||||
use App\Domains\Commerce\Purchase\Models\PurchaseItem;
|
||||
use App\Domains\Core\Auth\Models\User;
|
||||
use App\Domains\Core\Tenant\Models\Tenant;
|
||||
use App\Domains\Ticketing\Desfile\Models\EntryReservation;
|
||||
use App\Domains\Ticketing\Event\Models\Event;
|
||||
use App\Domains\Ticketing\Ticket\Services\ResolvedTicketValidity;
|
||||
use App\Domains\Ticketing\Ticket\Services\ResolvedValidityGroup;
|
||||
@@ -192,7 +193,9 @@ class Ticket extends Model
|
||||
|
||||
public function can_refund(): bool
|
||||
{
|
||||
return $this->is_active() && $this->allow_refund();
|
||||
return $this->is_active()
|
||||
&& $this->allow_refund()
|
||||
&& ! $this->hasEntryReservation();
|
||||
}
|
||||
|
||||
public function canRefund(): bool
|
||||
@@ -235,6 +238,12 @@ class Ticket extends Model
|
||||
return $this->hasOne(TicketRefund::class);
|
||||
}
|
||||
|
||||
/** @return HasOne<EntryReservation, $this> */
|
||||
public function entryReservation(): HasOne
|
||||
{
|
||||
return $this->hasOne(EntryReservation::class);
|
||||
}
|
||||
|
||||
/** @return BelongsTo<CatalogItem, $this> */
|
||||
public function sourceCatalogItem(): BelongsTo
|
||||
{
|
||||
@@ -247,6 +256,15 @@ class Ticket extends Model
|
||||
return $this->belongsTo(Variant::class, 'source_variant_id')->withTrashed();
|
||||
}
|
||||
|
||||
private function hasEntryReservation(): bool
|
||||
{
|
||||
if ($this->relationLoaded('entryReservation')) {
|
||||
return $this->getRelation('entryReservation') instanceof EntryReservation;
|
||||
}
|
||||
|
||||
return $this->exists && $this->entryReservation()->exists();
|
||||
}
|
||||
|
||||
public function isValid(): bool
|
||||
{
|
||||
if ($this->hasTerminalStatus() || $this->used_at !== null) {
|
||||
|
||||
@@ -27,6 +27,7 @@ class AdminAppTicketService
|
||||
'scannerUser',
|
||||
'sourceCatalogItem.category',
|
||||
'sourcePurchaseItem.purchase',
|
||||
'entryReservation',
|
||||
'refund.createdBy',
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user