Files
portal-api/app/Models/Invoice.php
T
2025-07-24 16:18:27 +07:00

64 lines
1.8 KiB
PHP

<?php
namespace App\Models;
use App\Enums\Invoice\InvoiceStatus;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Invoice extends Model
{
use HasFactory;
protected $table = 'invoice';
public $timestamps = true;
// protected $fillable = [
// 'date',
// 'due_date',
// 'date_paid',
// 'sub_total',
// 'tax',
// 'total',
// 'payment_id',
// 'customer_id',
// 'invoice_type',
// 'note',
// 'status'
// ];
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 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();
}
}