feat: Reimplement order and invoice management with new service and repository layers, introduce compression middleware, and update database schema.

This commit is contained in:
pbao9
2026-03-12 09:30:29 +07:00
parent 7f6264c87f
commit 1e09ccf17b
87 changed files with 2348 additions and 2612 deletions
+35 -18
View File
@@ -10,41 +10,58 @@ use Illuminate\Database\Eloquent\SoftDeletes;
class Invoice extends Model
{
use HasFactory, SoftDeletes;
protected $table = 'invoice';
public $timestamps = true;
protected $table = 'invoices';
protected $guarded = [];
protected $casts = [
'due_date' => 'date',
'paid_at' => 'datetime',
'auto_renew' => 'boolean',
];
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']);
return $this->belongsTo(Customer::class);
}
/** The order that originated this invoice. */
public function order()
{
return $this->belongsTo(\App\Models\Order::class, 'id', 'invoice_id');
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(\App\Models\InvoiceAttachment::class);
return $this->hasMany(InvoiceAttachment::class);
}
public function getStatus()
/** Services whose active invoice is this one (updated on each renewal). */
public function services()
{
return match ($this->attributes['status']) {
return $this->hasMany(Service::class, 'invoice_id');
}
// -------------------------------------------------------------------------
// Helpers
// -------------------------------------------------------------------------
public function getStatus(): string
{
return match ($this->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>'
3 => '<span class="bg-gray-100 text-gray-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded-sm dark:bg-gray-900 dark:text-gray-300">Đã hủy</span>',
4 => '<span class="bg-orange-100 text-orange-800 text-xs font-medium me-2 px-2.5 py-0.5 rounded-sm dark:bg-orange-900 dark:text-orange-300">Quá hạ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">Không xác định</span>',
};
}