'date',
'due_date' => 'date',
'paid_at' => 'datetime',
'auto_renew' => 'boolean',
];
public function customer()
{
return $this->belongsTo(Customer::class);
}
/** The order that originated this invoice. */
public function order()
{
return $this->belongsTo(Order::class, 'order_id');
}
/** Line items on this invoice. */
public function invoiceItems()
{
return $this->hasMany(InvoiceItem::class, 'invoice_id');
}
/** Uploaded payment-proof or supporting documents. */
public function attachments()
{
return $this->hasMany(InvoiceAttachment::class);
}
/** Services whose active invoice is this one (updated on each renewal). */
public function services()
{
return $this->hasMany(Service::class, 'invoice_id');
}
public function payment()
{
return $this->belongsTo(Payment::class, 'payment_method', 'id');
}
// -------------------------------------------------------------------------
// Helpers
// -------------------------------------------------------------------------
public function getStatus(): string
{
return match ($this->status) {
1 => 'Chưa thanh toán',
2 => 'Đã thanh toán',
3 => 'Đã hủy',
4 => 'Quá hạn',
default => 'Không xác định',
};
}
public function getStatusLabelAttribute(): string
{
return InvoiceStatus::from($this->status)->label();
}
}