diff --git a/app/DataMapper/ClientSettings.php b/app/DataMapper/ClientSettings.php index 6d07f1982305..ffaa05b8fb66 100644 --- a/app/DataMapper/ClientSettings.php +++ b/app/DataMapper/ClientSettings.php @@ -66,7 +66,7 @@ class ClientSettings extends BaseSettings public $shared_invoice_quote_counter; /** - * settings which which are unique to client settings + * Settings which which are unique to client settings */ public $industry_id; public $size_id; diff --git a/app/Models/Client.php b/app/Models/Client.php index 493148f470bd..0e8c0adbd13c 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -3,6 +3,7 @@ namespace App\Models; use App\DataMapper\ClientSettings; +use App\DataMapper\CompanySettings; use App\Models\Company; use App\Models\Country; use App\Models\Filterable; @@ -22,7 +23,6 @@ class Client extends BaseModel protected $presenter = 'App\Models\Presenters\ClientPresenter'; protected $appends = [ - 'client_settings_object' ]; protected $guarded = [ @@ -38,22 +38,18 @@ class Client extends BaseModel 'shipping_country' ]; - protected $with = ['contacts', 'primary_contact', 'country', 'shipping_country', 'company']; + protected $with = [ + 'contacts', + 'primary_contact', + 'country', + 'shipping_country', + 'company' + ]; protected $casts = [ 'settings' => 'object' ]; - public function getClientSettingsObjectAttribute() - { - return new ClientSettings($this->settings); - } - - public function getHashedIdAttribute() - { - return $this->encodePrimaryKey($this->id); - } - public function contacts() { return $this->hasMany(ClientContact::class)->orderBy('is_primary', 'desc'); @@ -81,12 +77,17 @@ class Client extends BaseModel public function timezone() { - return Timezone::find($this->getSettings()->timezone_id); + return Timezone::find($this->getMergedSettings()->timezone_id); } public function getSettings() { - return ClientSettings::buildClientSettings($this->company->settings, $this->settings); + return new ClientSettings($this->settings); + } + + public function getMergedSettings() + { + return ClientSettings::buildClientSettings(new CompanySettings($this->company->settings), new ClientSettings($this->settings)); } public function documents() diff --git a/tests/Feature/ClientTest.php b/tests/Feature/ClientTest.php index a36a57b70bd4..37e7434ff805 100644 --- a/tests/Feature/ClientTest.php +++ b/tests/Feature/ClientTest.php @@ -242,12 +242,12 @@ class ClientTest extends TestCase $this->assertNotNull($client); /* Make sure we have a valid settings object*/ - $this->assertEquals($client->getSettings()->timezone_id, 15); + $this->assertEquals($client->getMergedSettings()->timezone_id, 15); /* Make sure we are harvesting valid data */ $this->assertEquals($client->timezone()->name, 'US/Eastern'); - $contacts = ClientContact::whereIn('id', explode(',', $client->getSettings()->invoice_email_list))->get(); + $contacts = ClientContact::whereIn('id', explode(',', $client->getMergedSettings()->invoice_email_list))->get(); /* Make sure NULL settings return the correct count (0) instead of throwing an exception*/ $this->assertEquals(count($contacts), 0); diff --git a/tests/Feature/InvoiceTest.php b/tests/Feature/InvoiceTest.php index e4578ccde597..b32593834d92 100644 --- a/tests/Feature/InvoiceTest.php +++ b/tests/Feature/InvoiceTest.php @@ -158,7 +158,7 @@ class InvoiceTest extends TestCase factory(\App\Models\Invoice::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]); $invoice = Invoice::where('user_id',$user->id)->first(); - $invoice->settings = ClientSettings::buildClientSettings(new CompanySettings($company->settings), new ClientSettings($client->getSettings())); + $invoice->settings = $client->getMergedSettings(); $invoice->save();