67 lines
1.6 KiB
PHP
67 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Ticket\Models;
|
|
|
|
use App\Domains\Auth\Models\User;
|
|
use App\Domains\Purchase\Models\PurchaseItem;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
#[Fillable([
|
|
'ticket_id',
|
|
'purchase_item_id',
|
|
'created_by_user_id',
|
|
'type',
|
|
'amount',
|
|
])]
|
|
class TicketRefund extends Model
|
|
{
|
|
public const TYPE_PARTIAL = 'partial';
|
|
|
|
public const TYPE_TOTAL = 'total';
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'ticket_id' => 'integer',
|
|
'purchase_item_id' => 'integer',
|
|
'created_by_user_id' => 'integer',
|
|
'amount' => 'decimal:2',
|
|
];
|
|
}
|
|
|
|
/** @return list<string> */
|
|
public static function types(): array
|
|
{
|
|
return [self::TYPE_PARTIAL, self::TYPE_TOTAL];
|
|
}
|
|
|
|
public function typeLabel(): string
|
|
{
|
|
return match ($this->type) {
|
|
self::TYPE_PARTIAL => 'Reembolso parcial',
|
|
self::TYPE_TOTAL => 'Reembolso total',
|
|
default => 'Reembolsado',
|
|
};
|
|
}
|
|
|
|
/** @return BelongsTo<Ticket, $this> */
|
|
public function ticket(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Ticket::class);
|
|
}
|
|
|
|
/** @return BelongsTo<PurchaseItem, $this> */
|
|
public function purchaseItem(): BelongsTo
|
|
{
|
|
return $this->belongsTo(PurchaseItem::class);
|
|
}
|
|
|
|
/** @return BelongsTo<User, $this> */
|
|
public function createdBy(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by_user_id')->withTrashed();
|
|
}
|
|
}
|