2018-05-20 12:53:14 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class Service extends Model
|
|
|
|
{
|
|
|
|
protected $table = 'ab_service';
|
2018-06-19 12:31:49 +00:00
|
|
|
protected $with = ['product.descriptions','account.language','service_adsl','service_domain.tld','service_ssl','service_voip'];
|
2018-05-20 12:53:14 +00:00
|
|
|
protected $dates = ['date_last_invoice','date_next_invoice'];
|
2018-06-19 12:31:49 +00:00
|
|
|
|
|
|
|
protected $appends = [
|
|
|
|
'category',
|
|
|
|
'next_invoice',
|
|
|
|
'product_name',
|
|
|
|
'service_id',
|
|
|
|
'service_id_url',
|
|
|
|
'service_name',
|
|
|
|
'status',
|
|
|
|
];
|
|
|
|
protected $visible = [
|
|
|
|
'active',
|
|
|
|
'category',
|
|
|
|
'data_orig',
|
|
|
|
'id',
|
|
|
|
'next_invoice',
|
|
|
|
'product_name',
|
|
|
|
'service_id',
|
|
|
|
'service_id_url',
|
|
|
|
'service_name',
|
|
|
|
'status',
|
|
|
|
];
|
2018-05-20 12:53:14 +00:00
|
|
|
|
|
|
|
public function account()
|
|
|
|
{
|
2018-07-13 04:53:44 +00:00
|
|
|
return $this->belongsTo(Account::class);
|
2018-05-20 12:53:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function service_adsl()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(ServiceAdsl::class,'id','service_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function service_domain()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(ServiceDomain::class,'id','service_id');
|
|
|
|
}
|
|
|
|
|
2018-06-19 12:31:49 +00:00
|
|
|
public function service_host()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(ServiceHost::class,'id','service_id');
|
|
|
|
}
|
|
|
|
|
2018-05-20 12:53:14 +00:00
|
|
|
public function service_ssl()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(ServiceSsl::class,'id','service_id');
|
|
|
|
}
|
|
|
|
|
2018-06-19 12:31:49 +00:00
|
|
|
public function service_voip()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(ServiceVoip::class,'id','service_id');
|
|
|
|
}
|
|
|
|
|
2018-05-20 12:53:14 +00:00
|
|
|
public function product()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Product::class);
|
|
|
|
}
|
|
|
|
|
2018-06-19 12:31:49 +00:00
|
|
|
/**
|
|
|
|
* Only query active categories
|
|
|
|
*/
|
|
|
|
public function scopeActive()
|
|
|
|
{
|
|
|
|
return $this->where('active',TRUE);
|
|
|
|
}
|
|
|
|
|
2018-06-05 11:13:57 +00:00
|
|
|
public function getCategoryAttribute()
|
|
|
|
{
|
|
|
|
return $this->product->prod_plugin_file;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getNextInvoiceAttribute()
|
|
|
|
{
|
2018-06-19 12:31:49 +00:00
|
|
|
return $this->date_next_invoice ? $this->date_next_invoice->format('Y-m-d') : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getProductNameAttribute()
|
|
|
|
{
|
|
|
|
return $this->product->name($this->account->language);
|
2018-06-05 11:13:57 +00:00
|
|
|
}
|
|
|
|
|
2018-05-20 12:53:14 +00:00
|
|
|
/**
|
|
|
|
* This function will return the associated service model for the product type
|
|
|
|
*/
|
|
|
|
public function getServiceDetail()
|
|
|
|
{
|
|
|
|
switch ($this->product->prod_plugin_file)
|
|
|
|
{
|
|
|
|
case 'ADSL': return $this->service_adsl;
|
|
|
|
case 'DOMAIN': return $this->service_domain;
|
2018-06-19 12:31:49 +00:00
|
|
|
case 'HOST': return $this->service_host;
|
2018-05-20 12:53:14 +00:00
|
|
|
case 'SSL': return $this->service_ssl;
|
2018-06-19 12:31:49 +00:00
|
|
|
case 'VOIP': return $this->service_voip;
|
|
|
|
default: return NULL;
|
2018-05-20 12:53:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-06-19 12:31:49 +00:00
|
|
|
public function getStatusAttribute()
|
|
|
|
{
|
|
|
|
return $this->active ? 'Active' : 'Inactive';
|
|
|
|
}
|
|
|
|
|
2018-05-20 12:53:14 +00:00
|
|
|
public function getServiceExpireAttribute()
|
|
|
|
{
|
|
|
|
return 'TBA';
|
|
|
|
}
|
|
|
|
|
2018-06-19 12:31:49 +00:00
|
|
|
public function getServiceIdAttribute()
|
|
|
|
{
|
|
|
|
return sprintf('%02s-%05s',$this->site_id,$this->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getServiceIdUrlAttribute()
|
|
|
|
{
|
|
|
|
return sprintf('<a href="/u/service/view/%s">%s</a>',$this->id,$this->service_id);
|
|
|
|
}
|
|
|
|
|
2018-05-20 12:53:14 +00:00
|
|
|
public function getServiceNameAttribute()
|
|
|
|
{
|
2018-06-19 12:31:49 +00:00
|
|
|
if (! isset($this->getServiceDetail()->name))
|
|
|
|
return 'Unknown';
|
|
|
|
|
|
|
|
return $this->getServiceDetail()->name;
|
2018-05-20 12:53:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getServiceNumberAttribute()
|
|
|
|
{
|
|
|
|
return sprintf('%02s.%04s.%04s',$this->site_id,$this->account_id,$this->id);
|
|
|
|
}
|
|
|
|
}
|