diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 3c8454f0a4c7..d9b15907d3b8 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -1190,10 +1190,12 @@ class AccountController extends BaseController $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(); diff --git a/app/Models/Traits/ChargesFees.php b/app/Models/Traits/ChargesFees.php index a68afdf16adc..f348e09d3c72 100644 --- a/app/Models/Traits/ChargesFees.php +++ b/app/Models/Traits/ChargesFees.php @@ -26,7 +26,18 @@ trait ChargesFees } if ($settings->fee_percent) { - $fee += $this->amount * $settings->fee_percent / 100; + // prevent charging taxes twice on the surcharge + $amount = $this->getRequestedAmount(); + $taxField = $account->gateway_fee_location == FEE_LOCATION_CHARGE1 ? 'custom_invoice_taxes1' : 'custom_invoice_taxes1'; + if ($account->$taxField) { + $taxAmount = 0; + foreach ($this->getTaxes() as $key => $tax) { + $taxAmount += $tax['amount'] - $tax['paid']; + } + $amount -= $taxAmount; + } + + $fee += $amount * $settings->fee_percent / 100; } if ($account->gateway_fee_location == FEE_LOCATION_ITEM && $includeTax) { diff --git a/resources/views/accounts/invoice_settings.blade.php b/resources/views/accounts/invoice_settings.blade.php index 4c1f33d7007a..37833c3b5028 100644 --- a/resources/views/accounts/invoice_settings.blade.php +++ b/resources/views/accounts/invoice_settings.blade.php @@ -238,7 +238,7 @@ ->label(trans('texts.field_label')) ->placeholder($account->gateway_fee_location == FEE_LOCATION_CHARGE1 ? trans('texts.surcharge') : ' ') ->addGroupClass('pad-checkbox') - ->append($account->gateway_fee_location == FEE_LOCATION_CHARGE1 ? false : + ->append($account->gateway_fee_location == FEE_LOCATION_CHARGE1 && false ? false : Former::checkbox('custom_invoice_taxes1') ->value(1) ->raw() . trans('texts.charge_taxes')) !!} @@ -247,7 +247,7 @@ ->label(trans('texts.field_label')) ->placeholder($account->gateway_fee_location == FEE_LOCATION_CHARGE2 ? trans('texts.surcharge') : ' ') ->addGroupClass('pad-checkbox') - ->append($account->gateway_fee_location == FEE_LOCATION_CHARGE2 ? false : + ->append($account->gateway_fee_location == FEE_LOCATION_CHARGE2 && false ? false : Former::checkbox('custom_invoice_taxes2') ->value(1) ->raw() . trans('texts.charge_taxes'))