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

View File

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

View File

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

View File

@ -16,9 +16,11 @@ use App\Http\Requests\Request;
use App\Http\ValidationRules\ValidSettingsRule; use App\Http\ValidationRules\ValidSettingsRule;
use App\Models\ClientContact; use App\Models\ClientContact;
use App\Models\Company; use App\Models\Company;
use App\Utils\Traits\MakesHash;
class StoreCompanyRequest extends Request class StoreCompanyRequest extends Request
{ {
use MakesHash;
/** /**
* Determine if the user is authorized to make this request. * 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; $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); $this->replace($input);
} }

View File

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

View File

@ -68,7 +68,7 @@ class PaymentAppliedValidAmount implements Rule
{ {
foreach(request()->input('invoices') as $invoice) 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() 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); $company->fill($data);
if(array_key_exists('settings', $data))
$company->saveSettings($data['settings'], $company);
$company->save(); $company->save();
//\Log::error(print_r($company->settings,1));
return $company; return $company;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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