2018-07-06 06:57:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
2018-08-20 12:15:28 +00:00
|
|
|
use App\Traits\NextKey;
|
|
|
|
|
2018-07-06 06:57:49 +00:00
|
|
|
class Account extends Model
|
|
|
|
{
|
2018-08-20 12:15:28 +00:00
|
|
|
use NextKey;
|
|
|
|
public $incrementing = FALSE;
|
|
|
|
|
2018-07-06 06:57:49 +00:00
|
|
|
protected $table = 'ab_account';
|
2018-07-13 04:53:44 +00:00
|
|
|
public $timestamps = FALSE;
|
|
|
|
|
2018-07-17 04:10:40 +00:00
|
|
|
protected $appends = [
|
|
|
|
'active_display',
|
2018-08-08 23:33:51 +00:00
|
|
|
'services_count_html',
|
|
|
|
'switch_url',
|
2018-07-17 04:10:40 +00:00
|
|
|
];
|
|
|
|
protected $visible = [
|
|
|
|
'id',
|
|
|
|
'company',
|
|
|
|
'active_display',
|
2018-08-08 23:33:51 +00:00
|
|
|
'services_count_html',
|
|
|
|
'switch_url',
|
2018-07-17 04:10:40 +00:00
|
|
|
];
|
|
|
|
|
2018-07-13 04:53:44 +00:00
|
|
|
/**
|
|
|
|
* Return the country the user belongs to
|
|
|
|
*/
|
|
|
|
public function country()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Country::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function language()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Language::class);
|
|
|
|
}
|
|
|
|
|
2018-08-08 23:33:51 +00:00
|
|
|
public function services()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Service::class);
|
|
|
|
}
|
|
|
|
|
2018-07-13 04:53:44 +00:00
|
|
|
public function user()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(\App\User::class);
|
|
|
|
}
|
2018-07-17 04:10:40 +00:00
|
|
|
|
2018-08-01 07:09:38 +00:00
|
|
|
public function getActiveDisplayAttribute($value)
|
|
|
|
{
|
2019-06-02 05:35:48 +00:00
|
|
|
return sprintf('<span class="btn-sm btn-block btn-%s text-center">%s</span>',$this->active ? 'success' : 'danger',$this->active ? 'Active' : 'Inactive');
|
2018-08-01 07:09:38 +00:00
|
|
|
}
|
|
|
|
|
2018-07-17 04:10:40 +00:00
|
|
|
public function getCompanyAttribute($value)
|
|
|
|
{
|
|
|
|
return $value ? $value : $this->user->SurFirstName;
|
|
|
|
}
|
|
|
|
|
2018-08-01 07:09:38 +00:00
|
|
|
public function getAccountIdAttribute()
|
2018-07-17 04:10:40 +00:00
|
|
|
{
|
2018-08-01 07:09:38 +00:00
|
|
|
return sprintf('%02s-%04s',$this->site_id,$this->id);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getAccountIdUrlAttribute()
|
|
|
|
{
|
|
|
|
return sprintf('<a href="/r/account/view/%s">%s</a>',$this->id,$this->account_id);
|
|
|
|
}
|
|
|
|
|
2018-08-08 23:33:51 +00:00
|
|
|
public function getServicesCountHtmlAttribute()
|
|
|
|
{
|
|
|
|
return sprintf('%s <small>/%s</small>',$this->services->where('active',TRUE)->count(),$this->services->count());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSwitchUrlAttribute()
|
|
|
|
{
|
2018-08-12 01:09:44 +00:00
|
|
|
return sprintf('<a href="/r/switch/start/%s"><i class="fa fa-external-link"></i></a>',$this->user_id);
|
2018-08-08 23:33:51 +00:00
|
|
|
}
|
|
|
|
|
2018-08-01 07:09:38 +00:00
|
|
|
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('<br>',$this->_address());
|
|
|
|
case 'newline': return join("\m",$this->_address());
|
|
|
|
|
|
|
|
default:
|
|
|
|
return join("\n",$this->_address());
|
|
|
|
}
|
2018-07-17 04:10:40 +00:00
|
|
|
}
|
2018-07-06 06:57:49 +00:00
|
|
|
}
|