Fixes for quote transformer (#3434)

* remove jobs table

* Working on notifications

* Working on notifications

* Fix for pdf_variables

* Fixes for notification

* Fixes for viewing invoice with NO company custom_fields

* Fixes for company settings object creation

* Working on group settings

* Fixes for storing the correct currency_id on client creation

* Fix for invoicetransformer

* fix for store client

* Update PaymentAppliedValidAmount.php (#38)

* update company schema descriptions

* Update PaymentAppliedValidAmount.php

Co-authored-by: David Bomba <turbo124@gmail.com>

* Cast invoice designs to the Hashes

* Fixes for setting invoice/credit/design_ids to hashed

* Fixes for quote transformer

Co-authored-by: michael-hampton <michaelhamptondesign@yahoo.com>
This commit is contained in:
David Bomba 2020-03-06 22:10:59 +11:00 committed by GitHub
parent aa77ccf9ca
commit f0176b6e37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 97 additions and 58 deletions

View File

@ -12,6 +12,7 @@
namespace App\DataMapper;
use App\DataMapper\CompanySettings;
use App\Utils\Traits\MakesHash;
/**
* CompanySettings
@ -19,6 +20,7 @@ use App\DataMapper\CompanySettings;
class CompanySettings extends BaseSettings {
use MakesHash;
/*Group settings based on functionality*/
/*Invoice*/

View File

@ -204,8 +204,6 @@ class CompanyController extends BaseController
$company = $this->company_repo->save($request->all(), $company);
$company->saveSettings($request->input('settings'), $company);
$this->uploadLogo($request->file('company_logo'), $company, $company);
auth()->user()->companies()->attach($company->id, [

View File

@ -640,6 +640,11 @@ class QuoteController extends BaseController
$quote = CloneQuoteFactory::create($quote, auth()->user()->id);
return $this->itemResponse($quote);
break;
case 'approve':
break;
case 'convert':
//convert quote to an invoice make sure we link the two entities!!!
break;
case 'history':
# code...
break;

View File

@ -16,9 +16,11 @@ use App\Http\Requests\Request;
use App\Http\ValidationRules\ValidSettingsRule;
use App\Models\ClientContact;
use App\Models\Company;
use App\Utils\Traits\MakesHash;
class StoreCompanyRequest extends Request
{
use MakesHash;
/**
* Determine if the user is authorized to make this request.
*
@ -64,16 +66,12 @@ class StoreCompanyRequest extends Request
}
$company_settings->invoice_design_id = $this->encodePrimaryKey(1);
$company_settings->quote_design_id = $this->encodePrimaryKey(1);
$company_settings->credit_design_id = $this->encodePrimaryKey(1);
$input['settings'] = $company_settings;
// \Log::error($input);
// if(array_key_exists('settings', $input) && property_exists($input['settings'], 'pdf_variables') && empty((array) $input['settings']->pdf_variables))
// {
// $input['settings']['pdf_variables'] = CompanySettings::getEntityVariableDefaults();
// }
// \Log::error($input);
$this->replace($input);
}

View File

@ -49,4 +49,10 @@ class UpdateCompanyRequest extends Request
return $rules;
}
protected function prepareForValidation()
{
}
}

View File

@ -68,7 +68,7 @@ class PaymentAppliedValidAmount implements Rule
{
foreach(request()->input('invoices') as $invoice)
{
$invoice_amounts =+ $invoice['amount'];
$invoice_amounts += $invoice['amount'];
}
}

View File

@ -48,6 +48,6 @@ class ValidSettingsRule implements Rule
*/
public function message()
{
return $this->return_data[0]." is not a valid ".$this->return_data[1];
return $this->return_data[0]." is not a valid ".$this->return_data[1]. " ( ".$this->return_data[2]." )";
}
}

View File

@ -49,8 +49,13 @@ class CompanyRepository extends BaseRepository
$company->fill($data);
if(array_key_exists('settings', $data))
$company->saveSettings($data['settings'], $company);
$company->save();
//\Log::error(print_r($company->settings,1));
return $company;
}

View File

@ -91,13 +91,9 @@ class PaymentTransformer extends EntityTransformer
'type_id'=> (string) $payment->type_id,
'project_id' => (string) $this->encodePrimaryKey($payment->project_id),
'vendor_id' => (string) $this->encodePrimaryKey($payment->vendor_id),
/*
'private_notes' => $payment->private_notes ?: '',
'exchange_rate' => (float) $payment->exchange_rate,
'exchange_currency_id' => (int) $payment->exchange_currency_id,
'refunded' => (float) $payment->refunded,
'payment_status_id' => (string) $payment->payment_status_id,
*/
'currency_id' => (string) $payment->currency_id ?: '',
'exchange_rate' => (string) $payment->exchange_rate ?: '',
'exchange_currency_id' => (string) $payment->exchange_currency_id ?: '',
];
}
}

View File

@ -79,9 +79,9 @@ class QuoteTransformer extends EntityTransformer
'amount' => (float) $quote->amount,
'balance' => (float) $quote->balance,
'client_id' => (string) $this->encodePrimaryKey($quote->client_id),
'status_id' => (string) ($quote->status_id ?: 1),
'design_id' => (string) ($quote->design_id ?: 1),
'invoice_id' => (string) ($quote->invoice_id ?: 1),
'status_id' => (string)$quote->status_id,
'design_id' => (string)$quote->design_id,
'invoice_id' => (string)$quote->invoice_id,
'updated_at' => (int)$quote->updated_at,
'archived_at' => (int)$quote->deleted_at,
'created_at' => (int)$quote->created_at,

View File

@ -97,7 +97,7 @@ trait ClientGroupSettingsSaver
if (!property_exists($settings, $key)) {
continue;
} elseif (!$this->checkAttribute($value, $settings->{$key})) {
return [$key, $value];
return [$key, $value, $settings->{$key}];
}
continue;
@ -111,7 +111,7 @@ trait ClientGroupSettingsSaver
/*Catch all filter */
if (!$this->checkAttribute($value, $settings->{$key})) {
return [$key, $value];
return [$key, $value, $settings->{$key}];
}
}

View File

@ -30,23 +30,18 @@ trait CompanySettingsSaver
*/
public function saveSettings($settings, $entity)
{
if (!$settings) {
/* No Settings, No Save!*/
if (!$settings)
return;
}
//unset protected properties.
foreach (CompanySettings::$protected_fields as $field) {
//Unset Protected Properties.
foreach (CompanySettings::$protected_fields as $field)
unset($settings[$field]);
}
$settings = $this->checkSettingType($settings);
$company_settings = CompanySettings::defaults();
//Iterate and set CURRENT settings
// foreach($this->settings as $key => $value)
// $company_settings->{$key} = $value;
//Iterate and set NEW settings
foreach ($settings as $key => $value) {
if (is_null($settings->{$key})) {
@ -57,7 +52,9 @@ trait CompanySettingsSaver
}
$entity->settings = $company_settings;
$entity->save();
}
/**
@ -72,6 +69,7 @@ trait CompanySettingsSaver
public function validateSettings($settings)
{
$settings = (object)$settings;
$casts = CompanySettings::$casts;
if(property_exists($settings, 'pdf_variables'))
@ -88,22 +86,22 @@ trait CompanySettingsSaver
if (!property_exists($settings, $key)) {
continue;
} elseif (!$this->checkAttribute($value, $settings->{$key})) {
return [$key, $value];
return [$key, $value, $settings->{$key}];
}
continue;
}
/* Handles unset settings or blank strings */
if (!property_exists($settings, $key) || is_null($settings->{$key}) || !isset($settings->{$key}) || $settings->{$key} == '') {
if (!property_exists($settings, $key) || is_null($settings->{$key}) || !isset($settings->{$key}) || $settings->{$key} == '')
continue;
}
/*Catch all filter */
if (!$this->checkAttribute($value, $settings->{$key})) {
return [$key, $value];
}
if (!$this->checkAttribute($value, $settings->{$key}))
return [$key, $value, $settings->{$key}];
}
return true;
@ -123,10 +121,29 @@ trait CompanySettingsSaver
private function checkSettingType($settings) : \stdClass
{
$settings = (object)$settings;
$casts = CompanySettings::$casts;
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})) {
if (substr($key, -3) == '_id') {
settype($settings->{$key}, 'string');
} else {
settype($settings->{$key}, $value);
}
} else {
unset($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') {
$value = "integer";
@ -147,9 +164,9 @@ trait CompanySettingsSaver
}
/* Handles unset settings or blank strings */
if (!property_exists($settings, $key) || is_null($settings->{$key}) || !isset($settings->{$key}) || $settings->{$key} == '') {
if (!property_exists($settings, $key) || is_null($settings->{$key}) || !isset($settings->{$key}) || $settings->{$key} == '')
continue;
}
/*Catch all filter */
if ($this->checkAttribute($value, $settings->{$key})) {
@ -162,7 +179,9 @@ trait CompanySettingsSaver
unset($settings->{$key});
}
}
return $settings;
}
/**
@ -173,6 +192,7 @@ trait CompanySettingsSaver
*/
private function checkAttribute($key, $value) :bool
{
switch ($key) {
case 'int':
case 'integer':
@ -196,5 +216,6 @@ trait CompanySettingsSaver
default:
return false;
}
}
}

View File

@ -19,7 +19,11 @@ use App\DataMapper\CompanySettings;
*/
trait SettingsSaver
{
public static $string_casts = [
'invoice_design_id',
'quote_design_id',
'credit_design_id',
];
/**
* Saves a setting object
*
@ -73,14 +77,23 @@ trait SettingsSaver
foreach ($casts as $key => $value) {
/*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') {
$value = "integer";
if(in_array($key, self::$string_casts)){
$value = "string";
if (!property_exists($settings, $key)) {
continue;
} elseif (!$this->checkAttribute($value, $settings->{$key})) {
return [$key, $value];
return [$key, $value, $settings->{$key}];
}
continue;
}
/*Separate loop if it is a _id field which is an integer cast as a string*/
elseif (substr($key, -3) == '_id' || substr($key, -14) == 'number_counter') {
$value = "integer";
if (!property_exists($settings, $key)) {
continue;
} elseif (!$this->checkAttribute($value, $settings->{$key})) {
return [$key, $value, $settings->{$key}];
}
continue;
@ -94,7 +107,7 @@ trait SettingsSaver
/*Catch all filter */
if (!$this->checkAttribute($value, $settings->{$key})) {
return [$key, $value];
return [$key, $value, $settings->{$key}];
}
}
@ -124,7 +137,6 @@ trait SettingsSaver
foreach ($casts as $key => $value) {
/*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') {
$value = "integer";
@ -159,6 +171,7 @@ trait SettingsSaver
unset($settings->{$key});
}
}
return $settings;
}

View File

@ -124,7 +124,7 @@ class CompanyTest extends TestCase
$settings = CompanySettings::defaults();
$settings->custom_value1 = 'test';
$settings->invoice_design_id = '2';
$settings->quote_design_id = 1;
$settings->quote_design_id = '1';
$company->settings = $settings;
// $this->withoutExceptionHandling();

View File

@ -394,11 +394,6 @@ trait MockAccountData
$line_items[] = $item;
$item = InvoiceItemFactory::create();
$item->quantity = 1;
$item->cost =10;
$line_items[] = $item;
// $line_items[] = $item;
// $line_items[] = $item;
// $line_items[] = $item;

View File

@ -32,7 +32,7 @@
"country_id": "840",
"invoice_terms": "",
"enabled_item_tax_rates": false,
"invoice_design_id": 1,
"invoice_design_id": "1",
"phone": "",
"email": "",
"language_id": "1",