belongsTo(Country::class);
}
public function external()
{
return $this->belongsToMany(External\Integrations::class,'external_account',NULL,'external_integration_id');
}
public function invoices()
{
return $this->hasMany(Invoice::class);
}
public function language()
{
return $this->belongsTo(Language::class);
}
public function payments()
{
return $this->hasMany(Payment::class);
}
public function services()
{
return $this->hasMany(Service::class);
}
public function user()
{
return $this->belongsTo(\App\User::class);
}
public function getActiveDisplayAttribute($value)
{
return sprintf('%s',$this->active ? 'success' : 'danger',$this->active ? 'Active' : 'Inactive');
}
public function getAccountIdAttribute()
{
return sprintf('%02s-%04s',$this->site_id,$this->id);
}
public function getAccountIdUrlAttribute()
{
return sprintf('%s',$this->id,$this->account_id);
}
public function getNameAttribute()
{
return $this->company ?: $this->user->SurFirstName;
}
public function getServicesCountHtmlAttribute()
{
return sprintf('%s /%s',$this->services->where('active',TRUE)->count(),$this->services->count());
}
public function getSwitchUrlAttribute()
{
return sprintf('',$this->user_id);
}
public function getTypeAttribute()
{
return $this->company ? 'Business' : 'Private';
}
private function _address()
{
$return = [];
if ($this->address1)
array_push($return,$this->address1);
if ($this->address2)
array_push($return,$this->address2);
if ($this->city)
array_push($return,sprintf('%s %s %s',$this->city.(($this->state OR $this->zip) ? ',' : ''),$this->state,$this->zip));
if (! $return)
$return = ['No Address'];
return $return;
}
public function address($type='plain')
{
switch ($type)
{
case 'html' : return join('
',$this->_address());
case 'newline': return join("\m",$this->_address());
default:
return join("\n",$this->_address());
}
}
/**
* Get the due invoices on an account
*
* @return mixed
*/
public function dueInvoices()
{
return $this->invoices->filter(function($item) {
return $item->active AND $item->due > 0;
});
}
/**
* Get the external account ID for a specific integration
*
* @param External\Integrations $o
* @return mixed
*/
public function ExternalAccounting(External\Integrations $o)
{
return $this
->external()
->where('id','=',$o->id)
->where('site_id','=',$this->site_id)
->first();
}
}