Update source into github
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
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 $guarded = [];
|
||||
|
||||
public $timestamps = true;
|
||||
public function invoice()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Invoice::class, 'invoice_id');
|
||||
}
|
||||
|
||||
public function customer()
|
||||
{
|
||||
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');
|
||||
}
|
||||
|
||||
public function addons()
|
||||
{
|
||||
return $this->hasMany(InvoiceAddons::class, 'invoice_item_id')->with('addonItems');
|
||||
}
|
||||
|
||||
public function hosting()
|
||||
{
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
public function getBilling()
|
||||
{
|
||||
$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"
|
||||
};
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user