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)
{
$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;
}

View File

@ -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)) {

View File

@ -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)) {

View File

@ -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);
// }
}
}

View File

@ -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);