feat(ticket): add refund transaction model
This commit is contained in:
@@ -18,6 +18,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
@@ -219,6 +220,12 @@ class Ticket extends Model
|
||||
return $this->belongsTo(PurchaseItem::class, 'source_purchase_item_id');
|
||||
}
|
||||
|
||||
/** @return HasOne<TicketRefund, $this> */
|
||||
public function refund(): HasOne
|
||||
{
|
||||
return $this->hasOne(TicketRefund::class);
|
||||
}
|
||||
|
||||
/** @return BelongsTo<CatalogItem, $this> */
|
||||
public function sourceCatalogItem(): BelongsTo
|
||||
{
|
||||
@@ -284,6 +291,14 @@ class Ticket extends Model
|
||||
|
||||
public function getStatusLabelAttribute(): string
|
||||
{
|
||||
if ($this->status === self::STATUS_REFUNDED && $this->relationLoaded('refund')) {
|
||||
$refund = $this->getRelation('refund');
|
||||
|
||||
if ($refund instanceof TicketRefund) {
|
||||
return $refund->typeLabel();
|
||||
}
|
||||
}
|
||||
|
||||
return self::statusLabel($this->status);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user