Updates to login home

This commit is contained in:
Deon George
2018-08-09 09:33:51 +10:00
parent b9cf666581
commit ca402df525
12 changed files with 166 additions and 39 deletions

View File

@@ -15,7 +15,7 @@ class User extends Authenticatable
use HasApiTokens,Notifiable,UserSwitch;
protected $dates = ['created_at','updated_at','last_access'];
protected $with = ['accounts'];
protected $with = ['accounts.services'];
/**
* The attributes that are mass assignable.
@@ -36,13 +36,20 @@ class User extends Authenticatable
];
protected $appends = [
'active_display',
'services_count_html',
'surfirstname',
'switch_url',
'user_id_url',
];
protected $visible = [
'active_display',
'id',
'surfirstname',
'level',
'services_count_html',
'switch_url',
'surfirstname',
'user_id_url',
];
@@ -88,6 +95,11 @@ class User extends Authenticatable
return $this->hasMany(static::class,'parent_id','id');
}
public function getActiveDisplayAttribute($value)
{
return sprintf('<span class="btn-sm btn-block btn-%s text-center">%s</span>',$this->active ? 'primary' : 'danger',$this->active ? 'Active' : 'Inactive');
}
/**
* Logged in users full name
*
@@ -130,7 +142,6 @@ class User extends Authenticatable
{
if (is_null($this->language_id))
return config('SITE_SETUP')->language;
dd(__METHOD__,$value,config('SITE_SETUP')->language);
}
public function getPaymentHistoryAttribute()
@@ -155,6 +166,16 @@ class User extends Authenticatable
return $this->full_name;
}
public function getServicesCountHtmlAttribute()
{
return sprintf('%s <small>/%s</small>',$this->services->where('active',TRUE)->count(),$this->services->count());
}
public function getSwitchUrlAttribute()
{
return sprintf('<a href="/a/switch/start/%s"><i class="fa fa-external-link"></i></a>',$this->id);
}
public function getUserIdAttribute()
{
return sprintf('%02s-%04s',$this->site_id,$this->id);
@@ -235,15 +256,15 @@ class User extends Authenticatable
public function role()
{
// If I have agents and no parent, I am the wholesaler
if (is_null($this->parent_id) AND $this->all_agents()->count())
if (is_null($this->parent_id) AND ($this->all_agents()->count() OR $this->all_clients()->count()))
return 'wholesaler';
// If I have agents and a parent, I am a reseller
elseif ($this->parent_id AND $this->all_agents()->count())
elseif ($this->parent_id AND ($this->all_agents()->count() OR $this->all_clients()->count()))
return 'reseller';
// If I have no agents and a parent, I am a customer
elseif (! $this->all_agents()->count())
elseif (! $this->all_agents()->count() AND ! $this->all_clients()->count())
return 'customer';
}
}