56 lines
1.7 KiB
PHP
56 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\Invoice\InvoiceStatus;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Invoice extends Model
|
|
{
|
|
use HasFactory, SoftDeletes;
|
|
protected $table = 'invoice';
|
|
public $timestamps = true;
|
|
|
|
protected $guarded = [];
|
|
public function customer()
|
|
{
|
|
return $this->belongsTo(\App\Models\Customer::class);
|
|
}
|
|
|
|
public function payment()
|
|
{
|
|
return $this->belongsTo(\App\Models\Payment::class, 'payment_id', 'id');
|
|
}
|
|
|
|
public function invoiceItem()
|
|
{
|
|
return $this->hasMany(\App\Models\InvoiceItem::class)->with(['addons.addonItems', 'hosting', 'vps', 'os']);
|
|
}
|
|
|
|
public function order()
|
|
{
|
|
return $this->belongsTo(\App\Models\Order::class, 'id', 'invoice_id');
|
|
}
|
|
|
|
public function attachments()
|
|
{
|
|
return $this->hasMany(\App\Models\InvoiceAttachment::class);
|
|
}
|
|
|
|
public function getStatus()
|
|
{
|
|
return match ($this->attributes['status']) {
|
|
1 => '<span class="bg-red-100 text-red-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded-sm dark:bg-red-900 dark:text-red-300">Chưa thanh toán</span>',
|
|
2 => '<span class="bg-lime-100 text-lime-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded-sm dark:bg-lime-900 dark:text-lime-300">Đã thanh toán</span>',
|
|
default => '<span class="bg-red-100 text-red-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded-sm dark:bg-red-900 dark:text-red-300">Đã hủy</span>'
|
|
};
|
|
}
|
|
|
|
public function getStatusLabelAttribute(): string
|
|
{
|
|
return InvoiceStatus::from($this->status)->label();
|
|
}
|
|
}
|