mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
broad level fixes for settings / transformers (#3432)
* Fixes for company settings object creation * Working on group settings * Fixes for storing the correct currency_id on client creation * Fix for invoicetransformer
This commit is contained in:
parent
280271718b
commit
6d33a1a4c8
@ -73,34 +73,40 @@ class StoreClientRequest extends Request
|
||||
$input = $this->all();
|
||||
|
||||
//@todo implement feature permissions for > 100 clients
|
||||
if (!isset($input['settings'])) {
|
||||
$input['settings'] = ClientSettings::defaults();
|
||||
//
|
||||
$settings = ClientSettings::defaults();
|
||||
|
||||
if(array_key_exists('settings', $input) && !empty($input['settings']))
|
||||
{
|
||||
|
||||
foreach($input['settings'] as $key => $value)
|
||||
{
|
||||
$settings->{$key} = $value;
|
||||
}
|
||||
|
||||
if (isset($input['group_settings_id'])) {
|
||||
}
|
||||
|
||||
//is no settings->currency_id is set then lets dive in and find either a group or company currency all the below may be redundant!!
|
||||
if(!property_exists('currency_id', $input['settings']) && isset($input['group_settings_id']))
|
||||
{
|
||||
|
||||
$input['group_settings_id'] = $this->decodePrimaryKey($input['group_settings_id']);
|
||||
}
|
||||
|
||||
if(empty($input['settings']) || empty($input['settings']->currency_id))
|
||||
{
|
||||
if(!is_object($input['settings']))
|
||||
$input['settings'] = ClientSettings::defaults();
|
||||
|
||||
if(empty($input['group_settings_id']))
|
||||
{
|
||||
$input['settings']->currency_id =(string) auth()->user()->company()->settings->currency_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$group_settings = GroupSetting::find($input['group_settings_id']);
|
||||
|
||||
if($group_settings && property_exists($group_settings->settings, 'currency_id') && is_int($group_settings->settings->currency_id))
|
||||
$input['settings']->currency_id = (string)$group_settings->settings->currency_id;
|
||||
if($group_settings && property_exists($group_settings->settings, 'currency_id') && isset($group_settings->settings->currency_id))
|
||||
$settings->currency_id = (string)$group_settings->settings->currency_id;
|
||||
else
|
||||
$input['settings']->currency_id = (string)auth()->user()->company()->settings->currency_id;
|
||||
$settings->currency_id = (string)auth()->user()->company()->settings->currency_id;
|
||||
|
||||
}
|
||||
elseif(!property_exists('currency_id', $input['settings']))
|
||||
{
|
||||
$settings->currency_id = (string)auth()->user()->company()->settings->currency_id;
|
||||
}
|
||||
|
||||
|
||||
$input['settings'] = $settings;
|
||||
|
||||
if(isset($input['contacts']))
|
||||
{
|
||||
foreach($input['contacts'] as $key => $contact)
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace App\Http\Requests\Company;
|
||||
|
||||
use App\DataMapper\CompanySettings;
|
||||
use App\Http\Requests\Request;
|
||||
use App\Http\ValidationRules\ValidSettingsRule;
|
||||
use App\Models\ClientContact;
|
||||
@ -51,12 +52,28 @@ class StoreCompanyRequest extends Request
|
||||
|
||||
$input = $this->all();
|
||||
|
||||
if(array_key_exists('settings', $input) && property_exists($input['settings'], 'pdf_variables') && empty((array) $input['settings']->pdf_variables))
|
||||
$company_settings = CompanySettings::defaults();
|
||||
|
||||
if(array_key_exists('settings', $input) && !empty($input['settings']))
|
||||
{
|
||||
$input['settings']['pdf_variables'] = CompanySettings::getEntityVariableDefaults();
|
||||
|
||||
foreach($input['settings'] as $key => $value)
|
||||
{
|
||||
$company_settings->{$key} = $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$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);
|
||||
}
|
||||
|
@ -42,7 +42,20 @@ class StoreGroupSettingRequest extends Request
|
||||
{
|
||||
$input = $this->all();
|
||||
|
||||
$input['settings'] = ClientSettings::defaults();
|
||||
$group_settings = ClientSettings::defaults();
|
||||
|
||||
if(array_key_exists('settings', $input) && !empty($input['settings']))
|
||||
{
|
||||
|
||||
foreach($input['settings'] as $key => $value)
|
||||
{
|
||||
$group_settings->{$key} = $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$input['settings'] = $group_settings;
|
||||
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
|
@ -127,10 +127,10 @@ class InvoiceTransformer extends EntityTransformer
|
||||
'custom_surcharge2' => (float)$invoice->custom_surcharge2,
|
||||
'custom_surcharge3' => (float)$invoice->custom_surcharge3,
|
||||
'custom_surcharge4' => (float)$invoice->custom_surcharge4,
|
||||
'custom_surcharge_tax1' => (float) $invoice->custom_surcharge_tax1,
|
||||
'custom_surcharge_tax2' => (float) $invoice->custom_surcharge_tax2,
|
||||
'custom_surcharge_tax3' => (float) $invoice->custom_surcharge_tax3,
|
||||
'custom_surcharge_tax4' => (float) $invoice->custom_surcharge_tax4,
|
||||
'custom_surcharge_tax1' => (bool) $invoice->custom_surcharge_tax1,
|
||||
'custom_surcharge_tax2' => (bool) $invoice->custom_surcharge_tax2,
|
||||
'custom_surcharge_tax3' => (bool) $invoice->custom_surcharge_tax3,
|
||||
'custom_surcharge_tax4' => (bool) $invoice->custom_surcharge_tax4,
|
||||
'line_items' => $invoice->line_items ?: (array)[],
|
||||
'backup' => $invoice->backup ?: '',
|
||||
'entity_type' => 'invoice',
|
||||
|
Loading…
x
Reference in New Issue
Block a user