diff --git a/app/Models/Client.php b/app/Models/Client.php index 0bf88057b570..3f7878f102a0 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -468,9 +468,14 @@ class Client extends BaseModel implements HasLocalePreference public function setCompanyDefaults($data, $entity_name) { - $data['terms'] = $this->getSetting($entity_name.'_terms'); - $data['footer'] =$this->getSetting($entity_name.'_footer'); - $data['public_notes'] = isset($this->public_notes) ? $this->public_notes : ''; + if(strlen($this->getSetting($entity_name.'_terms')) >=1) + $data['terms'] = $this->getSetting($entity_name.'_terms'); + + if(strlen($this->getSetting($entity_name.'_footer')) >=1) + $data['footer'] =$this->getSetting($entity_name.'_footer'); + + if(strlen($this->public_notes) >=1) + $data['public_notes'] = $this->public_notes; return $data; } diff --git a/app/Utils/Traits/ClientGroupSettingsSaver.php b/app/Utils/Traits/ClientGroupSettingsSaver.php index eaee401c2220..6188ad834a40 100644 --- a/app/Utils/Traits/ClientGroupSettingsSaver.php +++ b/app/Utils/Traits/ClientGroupSettingsSaver.php @@ -12,6 +12,7 @@ namespace App\Utils\Traits; use App\DataMapper\CompanySettings; +use App\Utils\Traits\SettingsSaver; /** * Class ClientGroupSettingsSaver @@ -89,9 +90,19 @@ trait ClientGroupSettingsSaver } foreach ($casts as $key => $value) { + if(in_array($key, SettingsSaver::$string_casts)) { + $value = "string"; + if (!property_exists($settings, $key)) { + continue; + } elseif (!$this->checkAttribute($value, $settings->{$key})) { + return [$key, $value, $settings->{$key}]; + } + + continue; + } /*Separate loop if it is a _id field which is an integer cast as a string*/ - if (substr($key, -3) == '_id' || substr($key, -14) == 'number_counter') { + elseif (substr($key, -3) == '_id' || substr($key, -14) == 'number_counter') { $value = "integer"; if (!property_exists($settings, $key)) { diff --git a/app/Utils/Traits/CompanySettingsSaver.php b/app/Utils/Traits/CompanySettingsSaver.php index 9d7ef3c38f1a..ece4daf93066 100644 --- a/app/Utils/Traits/CompanySettingsSaver.php +++ b/app/Utils/Traits/CompanySettingsSaver.php @@ -12,6 +12,7 @@ namespace App\Utils\Traits; use App\DataMapper\CompanySettings; +use App\Utils\Traits\SettingsSaver; /** * Class CompanySettingsSaver @@ -79,8 +80,19 @@ trait CompanySettingsSaver foreach ($casts as $key => $value) { + if(in_array($key, SettingsSaver::$string_casts)) { + $value = "string"; + + if (!property_exists($settings, $key)) { + continue; + } elseif (!$this->checkAttribute($value, $settings->{$key})) { + return [$key, $value, $settings->{$key}]; + } + + continue; + } /*Separate loop if it is a _id field which is an integer cast as a string*/ - if (substr($key, -3) == '_id' || substr($key, -14) == 'number_counter') { + elseif (substr($key, -3) == '_id' || substr($key, -14) == 'number_counter') { $value = "integer"; if (!property_exists($settings, $key)) { diff --git a/tests/Integration/DesignTest.php b/tests/Integration/DesignTest.php index a016987c0ef6..6a5ec817fd39 100644 --- a/tests/Integration/DesignTest.php +++ b/tests/Integration/DesignTest.php @@ -8,6 +8,7 @@ use App\Jobs\Credit\CreateCreditPdf; use App\Jobs\Invoice\CreateInvoicePdf; use App\Jobs\Quote\CreateQuotePdf; use App\Utils\Traits\GeneratesCounter; +use App\Utils\Traits\MakesHash; use Tests\MockAccountData; use Tests\TestCase; @@ -19,7 +20,8 @@ class DesignTest extends TestCase { use MockAccountData; use GeneratesCounter; - + use MakesHash; + public function setUp() :void { parent::setUp(); @@ -48,7 +50,7 @@ class DesignTest extends TestCase $this->invoice->uses_inclusive_taxes = false; $settings = $this->invoice->client->settings; - $settings->invoice_design_id = "4"; + $settings->invoice_design_id = "VolejRejNm"; $this->client->settings = $settings; $this->client->save(); @@ -70,7 +72,7 @@ class DesignTest extends TestCase //\Log::error($html); $settings = $this->invoice->client->settings; - $settings->quote_design_id = "4"; + $settings->quote_design_id = "VolejRejNm"; $this->quote->client_id = $this->client->id; $this->quote->setRelation('client', $this->client); @@ -188,32 +190,32 @@ class DesignTest extends TestCase CreateCreditPdf::dispatchNow($this->credit, $this->credit->company, $this->credit->client->primary_contact()->first()); } - // public function testAllDesigns() - // { + public function testAllDesigns() + { - // for($x=1; $x<=10; $x++) - // { + for($x=1; $x<=10; $x++) + { - // $settings = $this->invoice->client->settings; - // $settings->quote_design_id = (string)$x; + $settings = $this->invoice->client->settings; + $settings->quote_design_id = (string)$this->encodePrimaryKey($x); - // $this->quote->client_id = $this->client->id; - // $this->quote->setRelation('client', $this->client); - // $this->quote->save(); + $this->quote->client_id = $this->client->id; + $this->quote->setRelation('client', $this->client); + $this->quote->save(); - // $this->client->settings = $settings; - // $this->client->save(); + $this->client->settings = $settings; + $this->client->save(); - // CreateQuotePdf::dispatchNow($this->quote, $this->quote->company, $this->quote->client->primary_contact()->first()); + CreateQuotePdf::dispatchNow($this->quote, $this->quote->company, $this->quote->client->primary_contact()->first()); - // $this->quote->number = $this->getNextQuoteNumber($this->quote->client); - // $this->quote->save(); + $this->quote->number = $this->getNextQuoteNumber($this->quote->client); + $this->quote->save(); - // } + } - // $this->assertTrue(true); + $this->assertTrue(true); - // } + } } diff --git a/tests/Unit/GroupSettingsTest.php b/tests/Unit/GroupSettingsTest.php index af428f293db1..503369c19d9a 100644 --- a/tests/Unit/GroupSettingsTest.php +++ b/tests/Unit/GroupSettingsTest.php @@ -209,7 +209,7 @@ class GroupSettingsTest extends TestCase { $this->settings = $this->company->settings; - + $this->assertTrue($this->validateSettings($this->settings)); $new_settings = $this->saveSettings($this->settings, $this->client);