1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Models/Client.php

138 lines
3.0 KiB
PHP
Raw Normal View History

<?php
2019-05-11 05:32:07 +02: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
*/
namespace App\Models;
use App\DataMapper\ClientSettings;
2019-04-29 02:54:26 +02:00
use App\DataMapper\CompanySettings;
use App\Models\Client;
use App\Models\Company;
2019-01-26 10:34:38 +01:00
use App\Models\Country;
2019-03-28 11:07:45 +01:00
use App\Models\Filterable;
2019-04-24 02:22:02 +02:00
use App\Models\Timezone;
2019-06-03 07:31:20 +02:00
use App\Utils\Traits\GeneratesCounter;
2019-04-30 08:02:39 +02:00
use App\Utils\Traits\MakesDates;
use App\Utils\Traits\MakesHash;
use Hashids\Hashids;
use Illuminate\Database\Eloquent\SoftDeletes;
2019-04-30 14:30:47 +02:00
use Illuminate\Support\Facades\Log;
use Laracasts\Presenter\PresentableTrait;
class Client extends BaseModel
{
use PresentableTrait;
use MakesHash;
2019-04-30 08:02:39 +02:00
use MakesDates;
use SoftDeletes;
2019-03-28 11:07:45 +01:00
use Filterable;
2019-06-03 07:31:20 +02:00
use GeneratesCounter;
2019-03-28 11:07:45 +01:00
protected $presenter = 'App\Models\Presenters\ClientPresenter';
2019-07-30 00:28:38 +02:00
protected $hidden = [
'id',
2019-07-30 00:28:38 +02:00
'private_notes',
'user_id',
'company_id',
'backup',
'settings',
'last_login',
'private_notes'
];
protected $fillable = [
'name',
'website',
'private_notes',
'industry_id',
'size_id',
'currency_id',
'address1',
'address2',
'city',
'state',
'postal_code',
'country_id',
'custom_value1',
'custom_value2',
'custom_value3',
'custom_value4,',
'shipping_address1',
'shipping_address2',
'shipping_city',
'shipping_state',
'shipping_postal_code',
'shipping_country_id',
'settings',
'payment_terms',
'vat_number',
'id_number',
];
2019-06-03 07:31:20 +02:00
/*
2019-04-29 02:54:26 +02:00
protected $with = [
'contacts',
'primary_contact',
'country',
'shipping_country',
'company'
];
2019-06-03 07:31:20 +02:00
*/
protected $casts = [
'settings' => 'object'
];
public function contacts()
{
return $this->hasMany(ClientContact::class)->orderBy('is_primary', 'desc');
}
public function primary_contact()
{
return $this->hasMany(ClientContact::class)->whereIsPrimary(true);
}
public function company()
{
return $this->belongsTo(Company::class);
}
2019-01-26 10:34:38 +01: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 02:22:02 +02:00
public function timezone()
{
2019-04-29 02:54:26 +02:00
return Timezone::find($this->getMergedSettings()->timezone_id);
2019-04-24 02:22:02 +02:00
}
2019-04-29 02:54:26 +02:00
public function getMergedSettings()
{
return ClientSettings::buildClientSettings(new CompanySettings($this->company->settings), new ClientSettings($this->settings));
}
2019-04-28 07:31:32 +02:00
public function documents()
{
return $this->morphMany(Document::class, 'documentable');
}
2019-04-24 02:22:02 +02:00
}