Fixes for setting entity defaults. (#3446)

* Create route for invoice/credit/quote PDF download

* Fixes for tests

* Fixes for settings entity defaults
This commit is contained in:
David Bomba 2020-03-07 09:48:03 +11:00 committed by GitHub
parent 7c00c68bf3
commit 4f9c596d3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 26 deletions

View File

@ -468,9 +468,14 @@ class Client extends BaseModel implements HasLocalePreference
public function setCompanyDefaults($data, $entity_name) public function setCompanyDefaults($data, $entity_name)
{ {
$data['terms'] = $this->getSetting($entity_name.'_terms'); if(strlen($this->getSetting($entity_name.'_terms')) >=1)
$data['footer'] =$this->getSetting($entity_name.'_footer'); $data['terms'] = $this->getSetting($entity_name.'_terms');
$data['public_notes'] = isset($this->public_notes) ? $this->public_notes : '';
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; return $data;
} }

View File

@ -12,6 +12,7 @@
namespace App\Utils\Traits; namespace App\Utils\Traits;
use App\DataMapper\CompanySettings; use App\DataMapper\CompanySettings;
use App\Utils\Traits\SettingsSaver;
/** /**
* Class ClientGroupSettingsSaver * Class ClientGroupSettingsSaver
@ -89,9 +90,19 @@ trait ClientGroupSettingsSaver
} }
foreach ($casts as $key => $value) { 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*/ /*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"; $value = "integer";
if (!property_exists($settings, $key)) { if (!property_exists($settings, $key)) {

View File

@ -12,6 +12,7 @@
namespace App\Utils\Traits; namespace App\Utils\Traits;
use App\DataMapper\CompanySettings; use App\DataMapper\CompanySettings;
use App\Utils\Traits\SettingsSaver;
/** /**
* Class CompanySettingsSaver * Class CompanySettingsSaver
@ -79,8 +80,19 @@ trait CompanySettingsSaver
foreach ($casts as $key => $value) { 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*/ /*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"; $value = "integer";
if (!property_exists($settings, $key)) { if (!property_exists($settings, $key)) {

View File

@ -8,6 +8,7 @@ use App\Jobs\Credit\CreateCreditPdf;
use App\Jobs\Invoice\CreateInvoicePdf; use App\Jobs\Invoice\CreateInvoicePdf;
use App\Jobs\Quote\CreateQuotePdf; use App\Jobs\Quote\CreateQuotePdf;
use App\Utils\Traits\GeneratesCounter; use App\Utils\Traits\GeneratesCounter;
use App\Utils\Traits\MakesHash;
use Tests\MockAccountData; use Tests\MockAccountData;
use Tests\TestCase; use Tests\TestCase;
@ -19,7 +20,8 @@ class DesignTest extends TestCase
{ {
use MockAccountData; use MockAccountData;
use GeneratesCounter; use GeneratesCounter;
use MakesHash;
public function setUp() :void public function setUp() :void
{ {
parent::setUp(); parent::setUp();
@ -48,7 +50,7 @@ class DesignTest extends TestCase
$this->invoice->uses_inclusive_taxes = false; $this->invoice->uses_inclusive_taxes = false;
$settings = $this->invoice->client->settings; $settings = $this->invoice->client->settings;
$settings->invoice_design_id = "4"; $settings->invoice_design_id = "VolejRejNm";
$this->client->settings = $settings; $this->client->settings = $settings;
$this->client->save(); $this->client->save();
@ -70,7 +72,7 @@ class DesignTest extends TestCase
//\Log::error($html); //\Log::error($html);
$settings = $this->invoice->client->settings; $settings = $this->invoice->client->settings;
$settings->quote_design_id = "4"; $settings->quote_design_id = "VolejRejNm";
$this->quote->client_id = $this->client->id; $this->quote->client_id = $this->client->id;
$this->quote->setRelation('client', $this->client); $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()); 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 = $this->invoice->client->settings;
// $settings->quote_design_id = (string)$x; $settings->quote_design_id = (string)$this->encodePrimaryKey($x);
// $this->quote->client_id = $this->client->id; $this->quote->client_id = $this->client->id;
// $this->quote->setRelation('client', $this->client); $this->quote->setRelation('client', $this->client);
// $this->quote->save(); $this->quote->save();
// $this->client->settings = $settings; $this->client->settings = $settings;
// $this->client->save(); $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->number = $this->getNextQuoteNumber($this->quote->client);
// $this->quote->save(); $this->quote->save();
// } }
// $this->assertTrue(true); $this->assertTrue(true);
// } }
} }

View File

@ -209,7 +209,7 @@ class GroupSettingsTest extends TestCase
{ {
$this->settings = $this->company->settings; $this->settings = $this->company->settings;
$this->assertTrue($this->validateSettings($this->settings)); $this->assertTrue($this->validateSettings($this->settings));
$new_settings = $this->saveSettings($this->settings, $this->client); $new_settings = $this->saveSettings($this->settings, $this->client);