From 85635c8a27a5eca0a532b86c4104faa9c4b808a9 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 16 Mar 2017 23:12:56 +0200 Subject: [PATCH] Working on gateway fees --- app/Models/Traits/ChargesFees.php | 17 +++++++++++++++-- app/Ninja/Presenters/InvoicePresenter.php | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/Models/Traits/ChargesFees.php b/app/Models/Traits/ChargesFees.php index 7f1e220b4bb4..83f6cac4671a 100644 --- a/app/Models/Traits/ChargesFees.php +++ b/app/Models/Traits/ChargesFees.php @@ -11,10 +11,11 @@ use App\Models\AccountGatewaySettings; */ trait ChargesFees { - public function calcGatewayFee($gatewayTypeId = false, $includeTax = true) + public function calcGatewayFee($gatewayTypeId = false, $includeTax = false) { $account = $this->account; $settings = $account->getGatewaySettings($gatewayTypeId); + $taxField = $account->gateway_fee_location == FEE_LOCATION_CHARGE1 ? 'custom_taxes1' : 'custom_taxes1'; $fee = 0; if (! $settings) { @@ -28,7 +29,6 @@ trait ChargesFees if ($settings->fee_percent) { // prevent charging taxes twice on the surcharge $amount = $this->amount; - $taxField = $account->gateway_fee_location == FEE_LOCATION_CHARGE1 ? 'custom_taxes1' : 'custom_taxes1'; if ($this->$taxField) { $taxAmount = 0; foreach ($this->getTaxes() as $key => $tax) { @@ -40,6 +40,18 @@ trait ChargesFees $fee += $amount * $settings->fee_percent / 100; } + // calculate final amount with tax + if ($includeTax && $this->$taxField) { + $preTaxFee = $fee; + if (floatval($this->tax_rate1)) { + $fee += round($preTaxFee * $this->tax_rate1 / 100, 2); + } + if (floatval($this->tax_rate2)) { + $fee += round($preTaxFee * $this->tax_rate2 / 100, 2); + } + } + + /* if ($account->gateway_fee_location == FEE_LOCATION_ITEM && $includeTax) { $preTaxFee = $fee; @@ -51,6 +63,7 @@ trait ChargesFees $fee += $preTaxFee * $settings->fee_tax_rate2 / 100; } } + */ return round($fee, 2); } diff --git a/app/Ninja/Presenters/InvoicePresenter.php b/app/Ninja/Presenters/InvoicePresenter.php index e34016f11f79..d49708e97b7d 100644 --- a/app/Ninja/Presenters/InvoicePresenter.php +++ b/app/Ninja/Presenters/InvoicePresenter.php @@ -268,7 +268,7 @@ class InvoicePresenter extends EntityPresenter return ''; } - $fee = $invoice->calcGatewayFee($gatewayTypeId); + $fee = $invoice->calcGatewayFee($gatewayTypeId, true); $fee = $account->formatMoney($fee, $invoice->client); if (floatval($settings->fee_amount) < 0 || floatval($settings->fee_percent) < 0) {