osb/app/Models/Service.php

78 lines
1.8 KiB
PHP
Raw Normal View History

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';
protected $dates = ['date_last_invoice','date_next_invoice'];
protected $with = ['product.descriptions','account.language','service_adsl','service_domain.tld','service_ssl'];
public function account()
{
return $this->belongsTo(\App\User::class);
}
public function service_adsl()
{
return $this->belongsTo(ServiceAdsl::class,'id','service_id');
}
public function service_domain()
{
return $this->belongsTo(ServiceDomain::class,'id','service_id');
}
public function service_ssl()
{
return $this->belongsTo(ServiceSsl::class,'id','service_id');
}
public function product()
{
return $this->belongsTo(Product::class);
}
2018-06-05 11:13:57 +00:00
public function getCategoryAttribute()
{
return $this->product->prod_plugin_file;
}
public function getNextInvoiceAttribute()
{
return $this->date_next_invoice->format('Y-m-d');
}
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;
case 'SSL': return $this->service_ssl;
default: abort(500,'Havent handled case for: '.$this->product->prod_plugin_file);
}
}
public function getServiceExpireAttribute()
{
return 'TBA';
}
public function getServiceNameAttribute()
{
if (! isset($this->getServiceDetail()->name)) dd($this,$this->product,$this->getServiceDetail());
return sprintf('%s: %s',$this->product->name($this->account->language),$this->getServiceDetail()->name);
}
public function getServiceNumberAttribute()
{
return sprintf('%02s.%04s.%04s',$this->site_id,$this->account_id,$this->id);
}
}