diff --git a/app/Constants.php b/app/Constants.php index 2719e7deca40..bd08211e3429 100644 --- a/app/Constants.php +++ b/app/Constants.php @@ -394,8 +394,8 @@ if (! defined('APP_NAME')) { define('GATEWAY_TYPE_CUSTOM', 6); define('GATEWAY_TYPE_TOKEN', 'token'); - define('FEE_LOCATION_CHARGE1', 'invoice_charge1'); - define('FEE_LOCATION_CHARGE2', 'invoice_charge2'); + define('FEE_LOCATION_CHARGE1', 'custom_value1'); + define('FEE_LOCATION_CHARGE2', 'custom_value2'); define('FEE_LOCATION_ITEM', 'invoice_item'); define('REMINDER1', 'reminder1'); diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index cd7d60a2f77f..3c8454f0a4c7 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -1189,6 +1189,12 @@ class AccountController extends BaseController $account->token_billing_type_id = Input::get('token_billing_type_id'); $account->auto_bill_on_due_date = boolval(Input::get('auto_bill_on_due_date')); $account->gateway_fee_location = Input::get('gateway_fee_location') ?: null; + + if ($account->gateway_fee_location) { + $taxField = $account->gateway_fee_location == FEE_LOCATION_CHARGE1 ? 'custom_invoice_taxes1' : 'custom_invoice_taxes1'; + $account->$taxField = false; + } + $account->save(); event(new UserSettingsChanged()); diff --git a/app/Ninja/Presenters/InvoicePresenter.php b/app/Ninja/Presenters/InvoicePresenter.php index d249b1f8e3b7..93371db80114 100644 --- a/app/Ninja/Presenters/InvoicePresenter.php +++ b/app/Ninja/Presenters/InvoicePresenter.php @@ -287,8 +287,6 @@ class InvoicePresenter extends EntityPresenter if (floatval($settings->fee_amount) < 0 || floatval($settings->fee_percent) < 0) { $label = trans('texts.discount'); } else { - //$field = $account->gateway_fee_location == FEE_LOCATION_CHARGE1 ? 'custom_invoice_label1' : 'custom_invoice_label2'; - //$label = $account->$field; $label = trans('texts.fee'); } diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php index 65cb56424059..1ef8ff93986f 100644 --- a/app/Ninja/Repositories/InvoiceRepository.php +++ b/app/Ninja/Repositories/InvoiceRepository.php @@ -1025,22 +1025,16 @@ class InvoiceRepository extends BaseRepository if ($location == FEE_LOCATION_ITEM) { // todo } else { - if ($location == FEE_LOCATION_CHARGE1) { - $field = 'custom_value1'; - } elseif ($location == FEE_LOCATION_CHARGE2) { - $field = 'custom_value2'; - } - if ($invoice->$field > 0) { $data = $invoice->toArray(); - $data[$field] = 0; + $data[$location] = 0; $invoice = $this->save($data, $invoice); } } $fee = $invoice->calcGatewayFee($gatewayTypeId); $data = $invoice->toArray(); - $data[$field] = $fee; + $data[$location] = $fee; $this->save($data, $invoice); } } diff --git a/resources/views/accounts/invoice_settings.blade.php b/resources/views/accounts/invoice_settings.blade.php index 9785c0082a61..4c1f33d7007a 100644 --- a/resources/views/accounts/invoice_settings.blade.php +++ b/resources/views/accounts/invoice_settings.blade.php @@ -238,18 +238,20 @@ ->label(trans('texts.field_label')) ->placeholder($account->gateway_fee_location == FEE_LOCATION_CHARGE1 ? trans('texts.surcharge') : ' ') ->addGroupClass('pad-checkbox') - ->append(Former::checkbox('custom_invoice_taxes1') - ->value(1) - ->raw() . trans('texts.charge_taxes')) !!} + ->append($account->gateway_fee_location == FEE_LOCATION_CHARGE1 ? false : + Former::checkbox('custom_invoice_taxes1') + ->value(1) + ->raw() . trans('texts.charge_taxes')) !!} {!! Former::text('custom_invoice_label2') ->label(trans('texts.field_label')) ->placeholder($account->gateway_fee_location == FEE_LOCATION_CHARGE2 ? trans('texts.surcharge') : ' ') ->addGroupClass('pad-checkbox') - ->append(Former::checkbox('custom_invoice_taxes2') - ->value(1) - ->raw() . trans('texts.charge_taxes')) - ->help(trans('texts.custom_invoice_charges_helps')) !!} + ->append($account->gateway_fee_location == FEE_LOCATION_CHARGE2 ? false : + Former::checkbox('custom_invoice_taxes2') + ->value(1) + ->raw() . trans('texts.charge_taxes')) + ->help(trans('texts.custom_invoice_charges_helps')) !!}