Using morphTo() on services, added Ezypay payment Import

This commit is contained in:
Deon George
2019-06-07 16:54:27 +10:00
parent 41d6a07196
commit 253eb55c19
33 changed files with 11398 additions and 183 deletions

View File

@@ -3,30 +3,32 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Traits\NextKey;
class Service extends Model
{
use NextKey;
public $incrementing = FALSE;
const CREATED_AT = 'date_orig';
const UPDATED_AT = 'date_last';
protected $table = 'ab_service';
protected $with = ['product.descriptions','account.language','service_adsl','service_domain.tld','service_ssl','service_voip'];
protected $with = ['product.descriptions','account.language'];
protected $dates = ['date_last_invoice','date_next_invoice'];
public $dateFormat = 'U';
protected $casts = [
'order_info'=>'array',
];
const CREATED_AT = 'date_orig';
const UPDATED_AT = 'date_last';
protected $appends = [
'account_name',
'admin_service_id_url',
'category',
'name',
'name_full',
'name_short',
'next_invoice',
'product_category',
'product_name',
'service_id',
'service_id_url',
@@ -37,12 +39,11 @@ class Service extends Model
'account_name',
'admin_service_id_url',
'active',
'category',
'data_orig',
'id',
'name',
'name_full',
'name_short',
'next_invoice',
'product_category',
'product_name',
'service_id',
'service_id_url',
@@ -85,7 +86,7 @@ class Service extends Model
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function orderby()
public function orderedby()
{
return $this->belongsTo(Account::class);
}
@@ -100,31 +101,6 @@ class Service extends Model
return $this->belongsTo(Site::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_host()
{
return $this->belongsTo(ServiceHost::class,'id','service_id');
}
public function service_ssl()
{
return $this->belongsTo(ServiceSsl::class,'id','service_id');
}
public function service_voip()
{
return $this->belongsTo(ServiceVoip::class,'id','service_id');
}
/**
* Product of the service
*
@@ -135,6 +111,21 @@ class Service extends Model
return $this->belongsTo(Product::class);
}
public function type()
{
return $this->morphTo(null,'model','id','service_id');
}
/**
* Only query active categories
*/
public function scopeActive($query)
{
return $query->where(function () use ($query) {
$query->where('active',TRUE)->orWhereNotIn('order_status',$this->inactive_status);
});
}
/**
* Find inactive services.
*
@@ -144,57 +135,66 @@ class Service extends Model
public function scopeInActive($query)
{
return $query->where(function () use ($query) {
return $query->where('active',FALSE)->orWhereIn('order_status',$this->inactive_status);
$query->where('active',FALSE)->orWhereIn('order_status',$this->inactive_status);
});
}
/**
* Only query active categories
* Name of the account for this service
*
* @return mixed
*/
public function scopeActive($query)
{
return $query->where(function () use ($query) {
return $query->where('active',TRUE)->orWhereNotIn('order_status',$this->inactive_status);
});
}
public function getAccountNameAttribute()
{
return $this->account->company;
return $this->account->name;
}
/**
* Get the Product's Category for this service
*
*/
public function getProductCategoryAttribute(): string
{
return $this->product->category;
}
/**
* Get the Product's Short Name for the service
*
* @return string
*/
public function getProductNameAttribute(): string
{
return $this->product->name($this->account->language);
}
/**
* Return the short name for the service.
* EG:
* For ADSL, this would be the phone number,
* For Hosting, this would be the domain name, etc
*/
public function getNameShortAttribute()
{
return $this->model ? $this->type->name : NULL;
}
/**
* Return the date for the next invoice
*
* @return null
*/
public function getNextInvoiceAttribute()
{
return $this->date_next_invoice ? $this->date_next_invoice->format('Y-m-d') : NULL;
}
//@todo
public function getAdminServiceIdUrlAttribute()
{
return sprintf('<a href="/a/service/%s">%s</a>',$this->id,$this->service_id);
}
public function getCategoryAttribute()
{
// @todo: All services should be linked to a product. This might require data cleaning for old services not linked to a product.
return is_object($this->product) ? $this->product->category : 'Unknown Product';
}
public function getNameAttribute()
{
if (! isset($this->ServicePlugin()->name))
return 'Unknown';
return $this->ServicePlugin()->name;
}
public function getNameFullAttribute()
{
if (! isset($this->ServicePlugin()->full_name))
return 'Unknown';
return $this->ServicePlugin()->full_name;
}
public function getNextInvoiceAttribute()
{
return $this->date_next_invoice ? $this->date_next_invoice->format('Y-m-d') : NULL;
}
/**
* This function will present the Order Info Details
*/
@@ -216,12 +216,6 @@ class Service extends Model
return $result;
}
public function getProductNameAttribute()
{
// @todo: All services should be linked to a product. This might require data cleaning for old services not linked to a product.
return is_object($this->product) ? $this->product->name($this->account->language) : 'Unknown Product';
}
public function getServiceExpireAttribute()
{
return 'TBA';