Refactor Group level settings

This commit is contained in:
David Bomba 2019-09-10 12:30:43 +10:00
parent db7043abd9
commit 1f624e28bc
9 changed files with 79 additions and 84 deletions

View File

@ -60,8 +60,6 @@ class ClientSettings extends BaseSettings
public $auto_bill;
public $auto_archive_invoice;
public $groups;
/**
* Counter Variables
*

View File

@ -84,8 +84,6 @@ class CompanySettings extends BaseSettings
public $inclusive_taxes;
public $translations;
public $group_selectors;
public $groups;
/**
* Counter Variables
@ -172,34 +170,7 @@ class CompanySettings extends BaseSettings
'design' => 'views/pdf/design1.blade.php',
'translations' => (object) [],
'group_selectors' => self::groupSelectors(),
'groups' => self::groupObjects(),
];
}
/**
* Implements App\DataMapper\Group objects
* in order to customise grouped option behaviour
* @return object Settings objects
*/
private static function groupObjects()
{
return (object)[
'company_gateways' => NULL,
'invoice_designs' => NULL
];
}
/**
* Storage point for ALL Group options
* @return object Settings objects
*/
private static function groupSelectors()
{
return (object)[
'company_gateways' => NULL,
'invoice_designs' => NULL
];
}
}

View File

@ -1,43 +0,0 @@
<?php
/**
* 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\DataMapper;
/**
* Class Group
* @package App\DataMapper
*/
class Group
{
/**
* Name of the group
* @var string
*/
public $name;
/**
* Group slug
* @var string
*/
public $slug;
/**
* Array of data
*
* Preferably stored as single dimension array
* [1,2,3,4,5,6]
*
* @var array
*/
public $data;
}

View File

@ -18,6 +18,7 @@ use App\Models\Company;
use App\Models\Country;
use App\Models\Currency;
use App\Models\Filterable;
use App\Models\GroupSetting;
use App\Models\Timezone;
use App\Utils\Traits\CompanyGatewaySettings;
use App\Utils\Traits\GeneratesCounter;
@ -155,6 +156,11 @@ class Client extends BaseModel
return $this->morphMany(Document::class, 'documentable');
}
public function group_settings()
{
return $this->belongsTo(GroupSetting::class);
}
/**
* Generates an array of payment urls per client
* for a given amount.

View File

@ -19,6 +19,7 @@ use App\Models\CompanyUser;
use App\Models\Country;
use App\Models\Currency;
use App\Models\Expense;
use App\Models\GroupSetting;
use App\Models\Industry;
use App\Models\Invoice;
use App\Models\Language;
@ -151,6 +152,11 @@ class Company extends BaseModel
return $this->belongsTo(Country::class);
}
public function group_settings()
{
return $this->hasMany(GroupSetting::class);
}
/**
*
*/

View File

@ -0,0 +1,39 @@
<?php
/**
* 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;
use App\DataMapper\CompanySettings;
use App\Models\Company;
use App\Models\User;
use App\Utils\Traits\MakesHash;
use Hashids\Hashids;
use Illuminate\Database\Eloquent\SoftDeletes;
class GroupSetting extends BaseModel
{
protected $casts = [
'settings' => 'object'
];
public function company()
{
return $this->belongsTo(Company::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
}

View File

@ -293,6 +293,7 @@ class CreateUsersTable extends Migration
$table->boolean('is_deleted')->default(false);
$table->integer('payment_terms')->nullable();
$table->unsignedInteger('group_settings_id')->nullable();
$table->string('vat_number')->nullable();
$table->string('id_number')->nullable();
@ -915,6 +916,18 @@ class CreateUsersTable extends Migration
$table->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
});
Schema::create('group_settings', function ($table){
$table->increments('id');
$table->unsignedInteger('company_id');
$table->unsignedInteger('user_id')->nullable();
$table->string('name');
$table->text('settings');
$table->boolean('is_default')->default(false);
$table->timestamps(6);
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade');
});
}
/**

View File

@ -1,11 +1,13 @@
<?php
use App\DataMapper\ClientSettings;
use App\DataMapper\CompanySettings;
use App\DataMapper\DefaultSettings;
use App\Models\Account;
use App\Models\Client;
use App\Models\ClientContact;
use App\Models\CompanyToken;
use App\Models\GroupSetting;
use App\Models\User;
use App\Models\UserAccount;
use Illuminate\Database\Seeder;
@ -117,6 +119,15 @@ class RandomDataSeeder extends Seeder
$client->save();
}
GroupSetting::create([
'company_id' => $company->id,
'user_id' => $user->id,
'is_default' =>true,
'settings' => ClientSettings::buildClientSettings(new CompanySettings(CompanySettings::defaults()), new ClientSettings(ClientSettings::defaults())),
'name' => 'Default Client Settings',
]);
}
}

View File

@ -26,27 +26,21 @@ class GroupTest extends TestCase
public function testGroupsPropertiesExistsResponses()
{
$this->assertTrue(property_exists($this->settings->groups, 'company_gateways'));
$this->assertTrue(property_exists($this->settings, 'groups'));
$this->assertTrue(property_exists($this->settings, 'design'));
}
public function testPropertyValueAccessors()
{
$this->settings->groups->company_gateways = 'slug';
$this->settings->translations = (object) ['hello' => 'world'];
$this->assertEquals('slug', $this->settings->groups->company_gateways);
$this->assertEquals('world', $this->settings->translations->hello);
}
public function testPropertyIsSet()
{
$this->assertFalse(isset($this->settings->groups->company_gateways));
$this->settings->groups->company_gateways = 'slug';
$this->assertTrue(isset($this->settings->groups->company_gateways));
$this->assertFalse(isset($this->settings->translations->nope));
}
}