2019-02-17 11:34:46 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\DataMapper;
|
|
|
|
|
2019-03-02 22:44:08 +01:00
|
|
|
use App\DataMapper\ClientSettings;
|
|
|
|
use App\DataMapper\CompanySettings;
|
|
|
|
use App\Utils\TranslationHelper;
|
|
|
|
|
2019-02-17 11:34:46 +01:00
|
|
|
/**
|
|
|
|
* ClientSettings
|
|
|
|
*/
|
|
|
|
class ClientSettings extends BaseSettings
|
|
|
|
{
|
2019-03-02 22:44:08 +01:00
|
|
|
/**
|
|
|
|
* settings which also have a parent company setting
|
|
|
|
*/
|
2019-02-17 11:34:46 +01:00
|
|
|
public $timezone_id;
|
2019-03-02 22:44:08 +01:00
|
|
|
public $date_format_id;
|
|
|
|
public $datetime_format_id;
|
|
|
|
public $military_time;
|
|
|
|
public $start_of_week;
|
|
|
|
public $financial_year_start;
|
|
|
|
|
2019-02-17 11:34:46 +01:00
|
|
|
public $language_id;
|
|
|
|
public $currency_id;
|
2019-03-02 22:44:08 +01:00
|
|
|
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;
|
2019-02-17 11:34:46 +01:00
|
|
|
|
2019-03-02 22:44:08 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
|
2019-02-17 11:34:46 +01:00
|
|
|
/**
|
2019-03-02 22:44:08 +01:00
|
|
|
*
|
|
|
|
* Default Client Settings scaffold
|
|
|
|
*
|
2019-02-17 11:34:46 +01:00
|
|
|
* @return \stdClass
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function defaults() : \stdClass
|
|
|
|
{
|
|
|
|
|
|
|
|
return (object)[
|
|
|
|
'timezone_id' => NULL,
|
|
|
|
'language_id' => NULL,
|
|
|
|
'currency_id' => NULL,
|
|
|
|
'payment_terms' => NULL,
|
2019-03-02 22:44:08 +01:00
|
|
|
'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
|
2019-02-17 11:34:46 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-02 22:44:08 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
2019-02-17 11:34:46 +01:00
|
|
|
}
|
|
|
|
|