1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/DataMapper/ClientSettings.php
David Bomba 0d508d67f1
Client Settings (#2711)
* Fixes for travis

* Additional settings variables at the company and client level

* Implement accessor for client settings

* Currency symbol or code setter

* Implement custom JS number and currency formatter

* Implement VueX state management for client settings

* Move settings logic into its own class

* Working on client settings

* client settings

* Move Client Settings helper into PHP

* Move translation helper into its own class

* Working on Client Settings

* fixes for client settings

* Client setting defaults

* fixes for .env

* Fixes for Travis
2019-03-03 08:44:08 +11:00

114 lines
2.7 KiB
PHP

<?php
namespace App\DataMapper;
use App\DataMapper\ClientSettings;
use App\DataMapper\CompanySettings;
use App\Utils\TranslationHelper;
/**
* ClientSettings
*/
class ClientSettings extends BaseSettings
{
/**
* settings which also have a parent company setting
*/
public $timezone_id;
public $date_format_id;
public $datetime_format_id;
public $military_time;
public $start_of_week;
public $financial_year_start;
public $language_id;
public $currency_id;
public $default_task_rate;
public $send_reminders;
public $show_tasks_in_portal;
public $custom_message_dashboard;
public $custom_message_unpaid_invoice;
public $custom_message_paid_invoice;
public $custom_message_unapproved_quote;
public $show_currency_symbol;
public $show_currency_code;
/**
* settings which which are unique to client settings
*/
public $industry_id;
public $size_id;
/**
* Cast object values and return entire class
* prevents missing properties from not being returned
* and always ensure an up to date class is returned
*
* @return \stdClass
*/
public function __construct($obj)
{
parent::__construct($obj);
}
/**
*
* Default Client Settings scaffold
*
* @return \stdClass
*
*/
public static function defaults() : \stdClass
{
return (object)[
'timezone_id' => NULL,
'language_id' => NULL,
'currency_id' => NULL,
'payment_terms' => NULL,
'datetime_format_id' => NULL,
'military_time' => NULL,
'date_format_id' => NULL,
'start_of_week' => NULL,
'financial_year_start' => NULL,
'default_task_rate' => NULL,
'send_reminders' => NULL,
'show_tasks_in_portal' => NULL,
'show_currency_symbol' => NULL,
'show_currency_code' => NULL
];
}
/**
* Merges settings from Company to Client
*
* @param \stdClass $company_settings
* @param \stdClass $client_settings
* @return \stdClass of merged settings
*/
public static function buildClientSettings(CompanySettings $company_settings, ClientSettings $client_settings) : ClientSettings
{
foreach($client_settings as $key => $value)
{
if(!isset($client_settings->{$key}) && property_exists($company_settings, $key))
$client_settings->{$key} = $company_settings->{$key};
}
/** Replace ID with Object for presentation in multi-select */
$client_settings->currency_id = TranslationHelper::getCurrencies()->where('id', $client_settings->currency_id)->first();
$client_settings->language_id = TranslationHelper::getLanguages()->where('id', $client_settings->language_id)->first();
$client_settings->payment_terms = TranslationHelper::getPaymentTerms()->where('num_days', $client_settings->payment_terms)->first();
//todo $client_settings->timezone_id
return $client_settings;
}
}