mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Abstract settings save to separate trait
This commit is contained in:
parent
ebf439adcf
commit
534b515849
@ -270,7 +270,7 @@ class CompanySettings extends BaseSettings
|
||||
* Array of variables which
|
||||
* cannot be modified client side
|
||||
*/
|
||||
public static $protected = [
|
||||
public static $protected_fields = [
|
||||
'credit_number_counter',
|
||||
'invoice_number_counter',
|
||||
'quote_number_counter',
|
||||
@ -299,7 +299,7 @@ class CompanySettings extends BaseSettings
|
||||
|
||||
$data = (object)get_class_vars(CompanySettings::class);
|
||||
unset($data->casts);
|
||||
unset($data->protected);
|
||||
unset($data->protected_fields);
|
||||
|
||||
$data->timezone_id = (string)config('ninja.i18n.timezone_id');
|
||||
$data->language_id = (string)config('ninja.i18n.language_id');
|
||||
|
@ -409,6 +409,8 @@ class CompanyController extends BaseController
|
||||
{
|
||||
$company = $this->company_repo->save($request->all(), $company);
|
||||
|
||||
$company->saveSettings($request->input('settings'));
|
||||
|
||||
$this->uploadLogo($request->file('company_logo'), $company, $company);
|
||||
|
||||
return $this->itemResponse($company);
|
||||
|
@ -32,7 +32,6 @@ class StoreClientRequest extends Request
|
||||
|
||||
public function rules()
|
||||
{
|
||||
// $this->sanitize();
|
||||
|
||||
/* Ensure we have a client name, and that all emails are unique*/
|
||||
$rules['name'] = 'required|min:1';
|
||||
@ -51,11 +50,8 @@ class StoreClientRequest extends Request
|
||||
|
||||
}
|
||||
|
||||
// Log::error($rules);
|
||||
|
||||
return $rules;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,10 +31,8 @@ class UpdateClientRequest extends Request
|
||||
public function rules()
|
||||
{
|
||||
/* Ensure we have a client name, and that all emails are unique*/
|
||||
// $rules['name'] = 'required';
|
||||
|
||||
$rules['company_logo'] = 'mimes:jpeg,jpg,png,gif|max:10000';
|
||||
|
||||
$rules['industry_id'] = 'integer|nullable';
|
||||
$rules['size_id'] = 'integer|nullable';
|
||||
$rules['currency_id'] = 'integer|nullable';
|
||||
|
@ -53,7 +53,6 @@ class CreateCompany
|
||||
$settings->name = isset($this->request['name']) ? $this->request['name'] : $this->request['first_name'] . ' ' . $this->request['last_name'];
|
||||
|
||||
$company = new Company();
|
||||
//$company->name = isset($this->request['name']) ? $this->request['name'] : $this->request['first_name'] . ' ' . $this->request['last_name'];
|
||||
$company->account_id = $this->account->id;
|
||||
$company->company_key = $this->createHash();
|
||||
$company->ip = request()->ip();
|
||||
|
@ -30,6 +30,7 @@ use App\Models\TaxRate;
|
||||
use App\Models\Timezone;
|
||||
use App\Models\Traits\AccountTrait;
|
||||
use App\Models\User;
|
||||
use App\Utils\Traits\CompanySettingsSaver;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@ -39,7 +40,8 @@ class Company extends BaseModel
|
||||
{
|
||||
use PresentableTrait;
|
||||
use MakesHash;
|
||||
|
||||
use CompanySettingsSaver;
|
||||
|
||||
protected $presenter = 'App\Models\Presenters\CompanyPresenter';
|
||||
|
||||
protected $fillable = [
|
||||
|
39
app/Utils/Traits/CompanySettingsSaver.php
Normal file
39
app/Utils/Traits/CompanySettingsSaver.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\Utils\Traits;
|
||||
|
||||
use App\DataMapper\CompanySettings;
|
||||
|
||||
/**
|
||||
* Class CompanySettingsSaver
|
||||
* @package App\Utils\Traits
|
||||
*/
|
||||
trait CompanySettingsSaver
|
||||
{
|
||||
|
||||
public function saveSettings($settings)
|
||||
{
|
||||
$company_settings = $this->settings;
|
||||
|
||||
//unset protected properties.
|
||||
foreach(CompanySettings::$protected_fields as $field)
|
||||
unset($settings[$field]);
|
||||
|
||||
//iterate through set properties with new values;
|
||||
foreach($settings as $key => $value)
|
||||
$company_settings->{$key} = $value;
|
||||
|
||||
$this->settings = $company_settings;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
}
|
@ -363,13 +363,13 @@ trait GeneratesCounter
|
||||
$replace[] = $client->custom_value1;
|
||||
|
||||
$search[] = '{$custom2}';
|
||||
$replace[] = $client->custom_value1;
|
||||
$replace[] = $client->custom_value2;
|
||||
|
||||
$search[] = '{$custom3}';
|
||||
$replace[] = $client->custom_value1;
|
||||
$replace[] = $client->custom_value3;
|
||||
|
||||
$search[] = '{$custom4}';
|
||||
$replace[] = $client->custom_value1;
|
||||
$replace[] = $client->custom_value4;
|
||||
|
||||
$search[] = '{$id_number}';
|
||||
$replace[] = $client->id_number;
|
||||
|
Loading…
Reference in New Issue
Block a user