diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index c0db18de99d8..9cca30677be3 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -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'); diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index 83164ac731c1..b266b234ccb3 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -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); diff --git a/app/Http/Requests/Client/StoreClientRequest.php b/app/Http/Requests/Client/StoreClientRequest.php index 790415f0c675..ec70c6374cf1 100644 --- a/app/Http/Requests/Client/StoreClientRequest.php +++ b/app/Http/Requests/Client/StoreClientRequest.php @@ -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; - } diff --git a/app/Http/Requests/Client/UpdateClientRequest.php b/app/Http/Requests/Client/UpdateClientRequest.php index 618f7c7521c3..ba4482f7f144 100644 --- a/app/Http/Requests/Client/UpdateClientRequest.php +++ b/app/Http/Requests/Client/UpdateClientRequest.php @@ -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'; diff --git a/app/Jobs/Company/CreateCompany.php b/app/Jobs/Company/CreateCompany.php index 6378bbf18b34..520160698c93 100644 --- a/app/Jobs/Company/CreateCompany.php +++ b/app/Jobs/Company/CreateCompany.php @@ -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(); diff --git a/app/Models/Company.php b/app/Models/Company.php index 6d004784c95c..fb252db650e9 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -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 = [ diff --git a/app/Utils/Traits/CompanySettingsSaver.php b/app/Utils/Traits/CompanySettingsSaver.php new file mode 100644 index 000000000000..22be33339d28 --- /dev/null +++ b/app/Utils/Traits/CompanySettingsSaver.php @@ -0,0 +1,39 @@ +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(); + } + +} \ No newline at end of file diff --git a/app/Utils/Traits/GeneratesCounter.php b/app/Utils/Traits/GeneratesCounter.php index d1d0fba7e86b..c2548f980815 100644 --- a/app/Utils/Traits/GeneratesCounter.php +++ b/app/Utils/Traits/GeneratesCounter.php @@ -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;