Files
portal-api/app/Models/Invoice.php
T
baodev0andClaude Opus 5.5 94614d9cb3 feat: khởi tạo/huỷ domain Plesk qua job, gửi mail hoá đơn qua queue, đính kèm triển khai
- ProvisionDnsDomainJob/SuspendDnsDomainJob: tạo domain admin lên Plesk, huỷ = suspend (is_created=3)
- Khách xem zone DNS được gán ở /dich-vu/domain, quản lý bản ghi A/AAAA/CNAME/TXT/MX/SRV
- send-mail hoá đơn đẩy SendInvoiceMailJob, preview + sửa nội dung, ghi mail.order_id
- invoice_attachments.type (payment_proof/deployment)
- CacheService xoá theo SCAN pattern, Redis không persistent mặc định
- Backfill transactions.public_code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 09:56:18 +07:00

83 lines
2.0 KiB
PHP

<?php
namespace App\Models;
use App\Enums\Invoice\InvoiceStatus;
use App\Traits\LogsActivity;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Invoice extends Model
{
use HasFactory, SoftDeletes, LogsActivity;
protected $table = 'invoices';
protected $guarded = [];
protected $casts = [
'date' => 'date',
'due_date' => 'date',
'paid_at' => 'datetime',
'auto_renew' => 'boolean',
];
protected static function booted(): void
{
static::creating(function (Invoice $invoice) {
$invoice->date ??= now()->toDateString();
});
}
public function customer()
{
return $this->belongsTo(Customer::class);
}
/** The order that originated this invoice. */
public function clientPath(): string
{
return '/hoa-don/' . ($this->order?->order_num ?? $this->invoice_number);
}
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');
}
/** The service this invoice upgrades, for invoice_type = 3 (upgrade). */
public function service()
{
return $this->belongsTo(Service::class, 'service_id');
}
public function payment()
{
return $this->belongsTo(Payment::class, 'payment_method', 'id');
}
public function getStatusLabelAttribute(): string
{
return InvoiceStatus::from($this->status)->label();
}
}