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
+27 -79
View File
@@ -9,101 +9,49 @@ class InvoiceItem extends Model
{
use HasFactory;
protected $table = 'invoice_item';
// protected $fillable = [
// 'invoice_id',
// 'customer_id',
// 'billing',
// 'type_id',
// 'product_id',
// 'invoice_type',
// 'parent_id',
// 'relid',
// 'description',
// 'amount',
// 'tax',
// 'due_date'
// ];
protected $table = 'invoice_items';
protected $guarded = [];
public $timestamps = true;
// -------------------------------------------------------------------------
// Relationships
// -------------------------------------------------------------------------
public function invoice()
{
return $this->belongsTo(\App\Models\Invoice::class, 'invoice_id');
return $this->belongsTo(Invoice::class, 'invoice_id');
}
public function customer()
public function product()
{
return $this->belongsTo(\App\Models\Customer::class);
}
public function type()
{
return $this->belongsTo(\App\Models\Type::class, 'invoice_type');
}
public function os()
{
return $this->belongsTo(Os::class, 'os_id');
return $this->belongsTo(Product::class, 'product_id');
}
public function addons()
{
return $this->hasMany(InvoiceAddons::class, 'invoice_item_id')->with('addonItems');
}
// -------------------------------------------------------------------------
// Helpers
// -------------------------------------------------------------------------
public function hosting()
public function getBillingLabelAttribute(): string
{
return $this->belongsTo(Hosting::class, 'product_id');
}
public function vps()
{
return $this->belongsTo(VPS::class, 'product_id');
}
// Remove the dynamic product relationship as it causes issues with eager loading
public function getProductAttribute()
{
return match ($this->product_type) {
3 => $this->hosting,
4 => $this->vps,
default => null,
return match ((int) $this->months) {
0 => 'One Time',
1 => 'Monthly',
3 => 'Quarterly',
6 => 'Semi-Annually',
12 => 'Annually',
24 => '2 Years',
36 => '3 Years',
default => $this->months . ' Months',
};
}
public function getBilling()
public function getTypeLabelAttribute(): string
{
$months = $this->attributes['months'] ?? 0;
return match ($months) {
0 => "One Time",
1 => "Monthly",
3 => "Quarterly",
6 => "Semi-Annually",
12 => "Annually",
24 => "2 Years",
36 => "3 Years",
default => $months . " Months"
return match ($this->type) {
'service' => 'Dịch vụ',
'addon' => 'Addon',
'upgrade' => 'Nâng cấp',
default => ucfirst($this->type),
};
}
public function GetRelidProduct()
{
$model = null;
switch ($this->type_id) {
case 3:
$model = ModuleHosting::with('server')->find($this->relid);
break;
case 4:
$model = ModuleVmware::with('ipAddress')->find($this->relid);
break;
default:
break;
}
return $model;
}
}