mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 03:17:35 -05:00 
			
		
		
		
	Create settings getter on Client Model
This commit is contained in:
		
							parent
							
								
									2a032ab253
								
							
						
					
					
						commit
						50a43720d1
					
				@ -66,7 +66,7 @@ class ClientSettings extends BaseSettings
 | 
				
			|||||||
	public $shared_invoice_quote_counter;
 | 
						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 $industry_id;
 | 
				
			||||||
	public $size_id;
 | 
						public $size_id;
 | 
				
			||||||
 | 
				
			|||||||
@ -3,6 +3,7 @@
 | 
				
			|||||||
namespace App\Models;
 | 
					namespace App\Models;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use App\DataMapper\ClientSettings;
 | 
					use App\DataMapper\ClientSettings;
 | 
				
			||||||
 | 
					use App\DataMapper\CompanySettings;
 | 
				
			||||||
use App\Models\Company;
 | 
					use App\Models\Company;
 | 
				
			||||||
use App\Models\Country;
 | 
					use App\Models\Country;
 | 
				
			||||||
use App\Models\Filterable;
 | 
					use App\Models\Filterable;
 | 
				
			||||||
@ -22,7 +23,6 @@ class Client extends BaseModel
 | 
				
			|||||||
    protected $presenter = 'App\Models\Presenters\ClientPresenter';
 | 
					    protected $presenter = 'App\Models\Presenters\ClientPresenter';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected $appends = [
 | 
					    protected $appends = [
 | 
				
			||||||
        'client_settings_object'
 | 
					 | 
				
			||||||
    ];
 | 
					    ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected $guarded = [
 | 
					    protected $guarded = [
 | 
				
			||||||
@ -38,22 +38,18 @@ class Client extends BaseModel
 | 
				
			|||||||
        'shipping_country'
 | 
					        'shipping_country'
 | 
				
			||||||
    ];
 | 
					    ];
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    protected $with = ['contacts', 'primary_contact', 'country', 'shipping_country', 'company'];
 | 
					    protected $with = [
 | 
				
			||||||
 | 
					        'contacts', 
 | 
				
			||||||
 | 
					        'primary_contact', 
 | 
				
			||||||
 | 
					        'country', 
 | 
				
			||||||
 | 
					        'shipping_country', 
 | 
				
			||||||
 | 
					        'company'
 | 
				
			||||||
 | 
					    ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected $casts = [
 | 
					    protected $casts = [
 | 
				
			||||||
        'settings' => 'object'
 | 
					        'settings' => 'object'
 | 
				
			||||||
    ];
 | 
					    ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function getClientSettingsObjectAttribute()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return new ClientSettings($this->settings);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public function getHashedIdAttribute()
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
        return $this->encodePrimaryKey($this->id);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public function contacts()
 | 
					    public function contacts()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return $this->hasMany(ClientContact::class)->orderBy('is_primary', 'desc');
 | 
					        return $this->hasMany(ClientContact::class)->orderBy('is_primary', 'desc');
 | 
				
			||||||
@ -81,12 +77,17 @@ class Client extends BaseModel
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public function timezone()
 | 
					    public function timezone()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return Timezone::find($this->getSettings()->timezone_id);
 | 
					        return Timezone::find($this->getMergedSettings()->timezone_id);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function getSettings()
 | 
					    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()
 | 
					    public function documents()
 | 
				
			||||||
 | 
				
			|||||||
@ -242,12 +242,12 @@ class ClientTest extends TestCase
 | 
				
			|||||||
            $this->assertNotNull($client);
 | 
					            $this->assertNotNull($client);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            /* Make sure we have a valid settings object*/
 | 
					            /* 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 */
 | 
					            /* Make sure we are harvesting valid data */
 | 
				
			||||||
            $this->assertEquals($client->timezone()->name, 'US/Eastern');
 | 
					            $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*/
 | 
					            /* Make sure NULL settings return the correct count (0) instead of throwing an exception*/
 | 
				
			||||||
            $this->assertEquals(count($contacts), 0);
 | 
					            $this->assertEquals(count($contacts), 0);
 | 
				
			||||||
 | 
				
			|||||||
@ -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]);
 | 
					        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 = 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();
 | 
					        $invoice->save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user