2018-10-15 16:00:48 +11:00
|
|
|
<?php
|
2019-05-11 13:32:07 +10:00
|
|
|
/**
|
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
|
*
|
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
|
*
|
|
|
|
|
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
|
*
|
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
|
*/
|
2018-10-15 16:00:48 +11:00
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2019-03-03 08:44:08 +11:00
|
|
|
use App\DataMapper\ClientSettings;
|
2019-04-29 10:54:26 +10:00
|
|
|
use App\DataMapper\CompanySettings;
|
2019-04-29 15:50:08 +10:00
|
|
|
use App\Models\Client;
|
2019-01-25 21:47:23 +11:00
|
|
|
use App\Models\Company;
|
2019-01-26 20:34:38 +11:00
|
|
|
use App\Models\Country;
|
2019-03-28 21:07:45 +11:00
|
|
|
use App\Models\Filterable;
|
2019-04-24 10:22:02 +10:00
|
|
|
use App\Models\Timezone;
|
2019-04-30 16:02:39 +10:00
|
|
|
use App\Utils\Traits\MakesDates;
|
2018-11-11 00:24:36 +11:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2019-01-25 21:47:23 +11:00
|
|
|
use Hashids\Hashids;
|
2018-11-12 18:52:20 +11:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2019-04-30 22:30:47 +10:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2019-01-25 21:47:23 +11:00
|
|
|
use Laracasts\Presenter\PresentableTrait;
|
2018-10-15 16:00:48 +11:00
|
|
|
|
2018-11-02 21:54:46 +11:00
|
|
|
class Client extends BaseModel
|
2018-10-15 16:00:48 +11:00
|
|
|
{
|
2018-11-02 21:54:46 +11:00
|
|
|
use PresentableTrait;
|
2018-11-11 00:24:36 +11:00
|
|
|
use MakesHash;
|
2019-04-30 16:02:39 +10:00
|
|
|
use MakesDates;
|
2018-11-12 18:52:20 +11:00
|
|
|
use SoftDeletes;
|
2019-03-28 21:07:45 +11:00
|
|
|
use Filterable;
|
|
|
|
|
|
2018-11-02 21:54:46 +11:00
|
|
|
protected $presenter = 'App\Models\Presenters\ClientPresenter';
|
|
|
|
|
|
2019-03-03 08:44:08 +11:00
|
|
|
protected $appends = [
|
|
|
|
|
];
|
2018-11-11 00:24:36 +11:00
|
|
|
|
2018-11-12 18:52:20 +11:00
|
|
|
protected $guarded = [
|
2018-11-27 17:59:16 +11:00
|
|
|
'id',
|
|
|
|
|
'updated_at',
|
|
|
|
|
'created_at',
|
|
|
|
|
'deleted_at',
|
2018-11-27 18:24:26 +11:00
|
|
|
'contacts',
|
|
|
|
|
'primary_contact',
|
2019-01-25 21:47:23 +11:00
|
|
|
'q',
|
2019-01-26 20:34:38 +11:00
|
|
|
'company',
|
|
|
|
|
'country',
|
|
|
|
|
'shipping_country'
|
2018-11-11 00:24:36 +11:00
|
|
|
];
|
2018-11-27 17:59:16 +11:00
|
|
|
|
2019-04-29 10:54:26 +10:00
|
|
|
protected $with = [
|
|
|
|
|
'contacts',
|
|
|
|
|
'primary_contact',
|
|
|
|
|
'country',
|
|
|
|
|
'shipping_country',
|
|
|
|
|
'company'
|
|
|
|
|
];
|
2019-01-22 20:47:26 +11:00
|
|
|
|
2019-02-17 21:34:46 +11:00
|
|
|
protected $casts = [
|
|
|
|
|
'settings' => 'object'
|
|
|
|
|
];
|
|
|
|
|
|
2018-10-29 14:16:17 +11:00
|
|
|
public function contacts()
|
|
|
|
|
{
|
2019-01-25 21:47:23 +11:00
|
|
|
return $this->hasMany(ClientContact::class)->orderBy('is_primary', 'desc');
|
2018-10-29 14:16:17 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function primary_contact()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(ClientContact::class)->whereIsPrimary(true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-25 21:47:23 +11:00
|
|
|
public function company()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Company::class);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-26 20:34:38 +11:00
|
|
|
public function country()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Country::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function shipping_country()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Country::class, 'shipping_country_id', 'id');
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-24 10:22:02 +10:00
|
|
|
public function timezone()
|
|
|
|
|
{
|
2019-04-29 10:54:26 +10:00
|
|
|
return Timezone::find($this->getMergedSettings()->timezone_id);
|
2019-04-24 10:22:02 +10:00
|
|
|
}
|
|
|
|
|
|
2019-04-29 10:54:26 +10:00
|
|
|
public function getMergedSettings()
|
|
|
|
|
{
|
2019-04-29 15:50:08 +10:00
|
|
|
|
2019-05-24 19:23:38 +10:00
|
|
|
return ClientSettings::buildClientSettings(new CompanySettings($this->company->settings), new ClientSettings($this->settings));
|
2019-04-29 15:50:08 +10:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-28 15:31:32 +10:00
|
|
|
public function documents()
|
|
|
|
|
{
|
|
|
|
|
return $this->morphMany(Document::class, 'documentable');
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-24 10:22:02 +10:00
|
|
|
|
|
|
|
|
|
2019-04-29 15:50:08 +10:00
|
|
|
|
2018-10-15 16:00:48 +11:00
|
|
|
}
|