mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-05 18:52:44 +01:00
Working on settings - safe guards to updating the settings object
This commit is contained in:
parent
04b4f224fa
commit
4aa781fb03
@ -57,4 +57,9 @@ class BaseSettings
|
||||
}
|
||||
}
|
||||
|
||||
public static function castSingleAttribute($key, $data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -154,8 +154,12 @@ class CompanySettings extends BaseSettings
|
||||
public $has_custom_design2 = '';
|
||||
public $has_custom_design3 = '';
|
||||
public $enable_portal_password = false;
|
||||
public $show_accept_invoice_terms = false;
|
||||
public $show_accept_quote_terms = false;
|
||||
|
||||
public static $casts = [
|
||||
'show_accept_quote_terms' => 'false',
|
||||
'show_accept_invoice_terms' => 'false',
|
||||
'timezone_id' => 'string',
|
||||
'date_format' => 'string',
|
||||
'datetime_format' => 'string',
|
||||
@ -250,6 +254,7 @@ class CompanySettings extends BaseSettings
|
||||
*/
|
||||
public static function defaults() : \stdClass
|
||||
{
|
||||
|
||||
$config = json_decode(config('ninja.settings'));
|
||||
|
||||
$data = (object)get_class_vars(CompanySettings::class);
|
||||
@ -266,6 +271,29 @@ class CompanySettings extends BaseSettings
|
||||
$data->translations = (object) [];
|
||||
|
||||
return self::setCasts($data, self::$casts);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* In case we update the settings object in the future we
|
||||
* need to provide a fallback catch on old settings objects which will
|
||||
* set new properties to the object prior to being returned.
|
||||
*
|
||||
* @param object $data The settings object to be checked
|
||||
*/
|
||||
public static function setProperties($settings) :\stdClass
|
||||
{
|
||||
|
||||
$company_settings = (object)get_class_vars(CompanySettings::class);
|
||||
|
||||
foreach($company_settings as $key => $value)
|
||||
{
|
||||
|
||||
if(!property_exists($data, $key))
|
||||
$settings->{$key} = self::castAttribute($key, $company_settings->{$key});
|
||||
|
||||
}
|
||||
return $settings;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ class InvoiceController extends Controller
|
||||
|
||||
$total = $invoices->sum('balance');
|
||||
|
||||
|
||||
|
||||
$invoices->filter(function ($invoice){
|
||||
return $invoice->isPayable();
|
||||
})->map(function ($invoice){
|
||||
@ -138,6 +138,7 @@ class InvoiceController extends Controller
|
||||
$payment_methods = auth()->user()->client->getPaymentMethods($total);
|
||||
|
||||
$data = [
|
||||
'settings' => auth()->user()->client->getMergedSettings(),
|
||||
'invoices' => $invoices,
|
||||
'formatted_total' => $formatted_total,
|
||||
'payment_methods' => $payment_methods,
|
||||
|
@ -173,7 +173,7 @@ class Client extends BaseModel
|
||||
*
|
||||
* @return object stdClass object of settings
|
||||
*/
|
||||
public function getMergedSettings()
|
||||
public function getMergedSettings() :object
|
||||
{
|
||||
|
||||
if($this->group_settings !== null)
|
||||
@ -185,7 +185,7 @@ class Client extends BaseModel
|
||||
|
||||
}
|
||||
|
||||
return ClientSettings::buildClientSettings($this->company->settings, $this->settings);
|
||||
return CompanySettings::setProperties(ClientSettings::buildClientSettings($this->company->settings, $this->settings));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,8 +70,8 @@
|
||||
).then(function(result) {
|
||||
if (result.error) {
|
||||
// Display error.message in your UI.
|
||||
console.log(result.error);
|
||||
console.log(result.error.message);
|
||||
// console.log(result.error);
|
||||
// console.log(result.error.message);
|
||||
|
||||
$("#card-errors").empty();
|
||||
$("#card-errors").append("<b>" + result.error.message + "</b>");
|
||||
|
@ -97,7 +97,7 @@
|
||||
<div id="signature"></div><br/>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button id="modalPayNowButton" type="button" class="btn btn-success" onclick="onModalPayNowClick()" disabled="">
|
||||
<button id="modal_pay_now_button" type="button" class="btn btn-success" onclick="onModalPayNowClick()" disabled="">
|
||||
{{ ctrans('texts.pay_now') }}
|
||||
</button>
|
||||
</div>
|
||||
@ -120,28 +120,65 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var terms_accepted = false;
|
||||
|
||||
$('#pay_now').on('click', function(e) {
|
||||
//check if terms must be accepted
|
||||
$('#terms_modal').modal('show');
|
||||
|
||||
@if(App\DataMapper\CompanySettings::duh())
|
||||
@endif
|
||||
|
||||
@if($settings->show_accept_invoice_terms)
|
||||
$('#terms_modal').modal('show');
|
||||
@endif
|
||||
|
||||
//check if signature required
|
||||
getSignature();
|
||||
|
||||
//push to signature check
|
||||
});
|
||||
|
||||
$('#terms_accepted').on('click', function(e){
|
||||
|
||||
terms_accepted = true;
|
||||
|
||||
$('#terms_modal').modal('hide');
|
||||
|
||||
//check in signature is required
|
||||
$("#signature").jSignature({ 'UndoButton': true, }).bind('change', function(e) {});
|
||||
$("#signature").resize();
|
||||
|
||||
$("#signature").jSignature('reset');
|
||||
$('#signature_modal').modal();
|
||||
//push to payment
|
||||
|
||||
|
||||
});
|
||||
|
||||
$("#modal_pay_now_button").on('click', function(e){
|
||||
|
||||
//disable to prevent firing twice
|
||||
$("#modal_pay_now_button").attr("disabled", true);
|
||||
|
||||
|
||||
});
|
||||
|
||||
function getSignature()
|
||||
{
|
||||
//check in signature is required
|
||||
$("#signature").jSignature({ 'UndoButton': true, }).bind('change', function(e) {
|
||||
|
||||
if( $("#signature").jSignature('getData', 'native').length >= 1) {
|
||||
|
||||
$("#modal_pay_now_button").removeAttr("disabled");
|
||||
|
||||
} else {
|
||||
$("#modal_pay_now_button").attr("disabled", true);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$("#signature").resize();
|
||||
|
||||
$("#signature").jSignature('reset');
|
||||
$('#signature_modal').modal();
|
||||
}
|
||||
|
||||
function onModalPayNowClick() {
|
||||
var data = {
|
||||
signature: $('#signature').jSignature('getData', 'svgbase64')[1]
|
||||
|
Loading…
Reference in New Issue
Block a user