belongsTo('Account');
	}
	public function invoices()
	{
		return $this->hasMany('Invoice');
	}
	public function payments()
	{
		return $this->hasMany('Payment');
	}
	public function contacts()
	{
		return $this->hasMany('Contact');
	}
	public function country()
	{
		return $this->belongsTo('Country');
	}
	public function currency()
	{
		return $this->belongsTo('Currency');
	}
	public function size()
	{
		return $this->belongsTo('Size');	
	}
	public function industry()
	{
		return $this->belongsTo('Industry');
	}
	public function getTotalCredit()
	{
		return DB::table('credits')
				->where('client_id','=',$this->id)
				->whereNull('deleted_at')
				->sum('balance');
	}
	public function getName()
	{
		return $this->getDisplayName();
	}
	public function getDisplayName()
	{
		if ($this->name) 
		{
			return $this->name;
		}
		$this->load('contacts');
		$contact = $this->contacts()->first();
		
		return $contact->getDisplayName();
	}
	public function getEntityType()
	{
		return ENTITY_CLIENT;
	}
	public function getAddress()
	{
		$str = '';
		if ($this->address1) {
			$str .= $this->address1 . '
';
		}
		if ($this->address2) {
			$str .= $this->address2 . '
';	
		}
		if ($this->city) {
			$str .= $this->city . ', ';	
		}
		if ($this->state) {
			$str .= $this->state . ' ';	
		}
		if ($this->postal_code) {
			$str .= $this->postal_code;
		}
		if ($this->country) {
			$str .= '
' . $this->country->name;			
		}
		if ($str)
		{
			$str = '
' . $str . '
'; } return $str; } public function getPhone() { $str = ''; if ($this->work_phone) { $str .= '' . Utils::formatPhoneNumber($this->work_phone); } return $str; } public function getNotes() { $str = ''; if ($this->private_notes) { $str .= '' . $this->private_notes . ''; } return $str; } public function getIndustry() { $str = ''; if ($this->client_industry) { $str .= $this->client_industry->name . ' '; } if ($this->client_size) { $str .= $this->client_size->name; } return $str; } public function getCustomFields() { $str = ''; $account = $this->account; if ($account->custom_client_label1 && $this->custom_value1) { $str .= "{$account->custom_client_label1}: {$this->custom_value1}