mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Refactor Group level settings
This commit is contained in:
parent
db7043abd9
commit
1f624e28bc
@ -60,8 +60,6 @@ class ClientSettings extends BaseSettings
|
||||
public $auto_bill;
|
||||
public $auto_archive_invoice;
|
||||
|
||||
public $groups;
|
||||
|
||||
/**
|
||||
* Counter Variables
|
||||
*
|
||||
|
@ -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
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
}
|
@ -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.
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
39
app/Models/GroupSetting.php
Normal file
39
app/Models/GroupSetting.php
Normal 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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');
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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',
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user