2016-01-06 15:23:58 +01:00
|
|
|
<?php namespace App\Models;
|
2017-01-30 17:05:31 +01:00
|
|
|
|
2016-01-07 16:21:13 +01:00
|
|
|
// vendor
|
2016-01-06 15:23:58 +01:00
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* Class VendorContact
|
|
|
|
*/
|
2016-01-06 15:23:58 +01:00
|
|
|
class VendorContact extends EntityModel
|
|
|
|
{
|
|
|
|
use SoftDeletes;
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2016-01-06 15:23:58 +01:00
|
|
|
protected $dates = ['deleted_at'];
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-01-06 15:23:58 +01:00
|
|
|
protected $table = 'vendor_contacts';
|
2016-06-08 07:11:05 +02:00
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2016-01-06 15:23:58 +01:00
|
|
|
protected $fillable = [
|
|
|
|
'first_name',
|
|
|
|
'last_name',
|
|
|
|
'email',
|
|
|
|
'phone',
|
|
|
|
'send_invoice',
|
|
|
|
];
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-01-06 15:23:58 +01:00
|
|
|
public static $fieldFirstName = 'first_name';
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-01-06 15:23:58 +01:00
|
|
|
public static $fieldLastName = 'last_name';
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-01-06 15:23:58 +01:00
|
|
|
public static $fieldEmail = 'email';
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
2016-01-06 15:23:58 +01:00
|
|
|
public static $fieldPhone = 'phone';
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
*/
|
2016-01-06 15:23:58 +01:00
|
|
|
public function account()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('App\Models\Account');
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2016-01-06 15:23:58 +01:00
|
|
|
public function user()
|
|
|
|
{
|
2016-06-08 07:11:05 +02:00
|
|
|
return $this->belongsTo('App\Models\User')->withTrashed();
|
2016-01-06 15:23:58 +01:00
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2016-01-06 15:23:58 +01:00
|
|
|
public function vendor()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('App\Models\Vendor')->withTrashed();
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2016-01-06 15:23:58 +01:00
|
|
|
public function getPersonType()
|
|
|
|
{
|
|
|
|
return PERSON_VENDOR_CONTACT;
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return mixed|string
|
|
|
|
*/
|
2016-01-06 15:23:58 +01:00
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return $this->getDisplayName();
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return mixed|string
|
|
|
|
*/
|
2016-01-06 15:23:58 +01:00
|
|
|
public function getDisplayName()
|
|
|
|
{
|
|
|
|
if ($this->getFullName()) {
|
|
|
|
return $this->getFullName();
|
|
|
|
} else {
|
|
|
|
return $this->email;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-01-06 15:23:58 +01:00
|
|
|
public function getFullName()
|
|
|
|
{
|
|
|
|
if ($this->first_name || $this->last_name) {
|
|
|
|
return $this->first_name.' '.$this->last_name;
|
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|