Working on gateway fees

This commit is contained in:
Hillel Coren 2017-03-16 22:34:45 +02:00
parent 87507c06f4
commit 0379bb61fa
3 changed files with 19 additions and 18 deletions

View File

@ -68,6 +68,7 @@ class ClientPortalController extends BaseController
} }
$account->loadLocalizationSettings($client); $account->loadLocalizationSettings($client);
$this->invoiceRepo->clearGatewayFee($invoice);
if (! Input::has('phantomjs') && ! session('silent:' . $client->id) && ! Session::has($invitation->invitation_key) if (! Input::has('phantomjs') && ! session('silent:' . $client->id) && ! Session::has($invitation->invitation_key)
&& (! Auth::check() || Auth::user()->account_id != $invoice->account_id)) { && (! Auth::check() || Auth::user()->account_id != $invoice->account_id)) {

View File

@ -268,21 +268,8 @@ class InvoicePresenter extends EntityPresenter
return ''; return '';
} }
$parts = []; $fee = $invoice->calcGatewayFee($gatewayTypeId);
$fee = $account->formatMoney($fee, $invoice->client);
if (floatval($settings->fee_amount) != 0) {
$parts[] = $account->formatMoney($settings->fee_amount, $invoice->client);
}
if (floatval($settings->fee_percent) != 0) {
$parts[] = (floor($settings->fee_percent * 1000) / 1000) . '%';
}
if (! count($parts)) {
return '';
}
$str = join(' + ', $parts);
if (floatval($settings->fee_amount) < 0 || floatval($settings->fee_percent) < 0) { if (floatval($settings->fee_amount) < 0 || floatval($settings->fee_percent) < 0) {
$label = trans('texts.discount'); $label = trans('texts.discount');
@ -290,6 +277,6 @@ class InvoicePresenter extends EntityPresenter
$label = trans('texts.fee'); $label = trans('texts.fee');
} }
return $label . ': ' . $str; return $fee . ' ' . $label;
} }
} }

View File

@ -1004,12 +1004,12 @@ class InvoiceRepository extends BaseRepository
return $invoices; return $invoices;
} }
public function setGatewayFee($invoice, $gatewayTypeId) public function clearGatewayFee($invoice)
{ {
$account = $invoice->account; $account = $invoice->account;
$location = $account->gateway_fee_location; $location = $account->gateway_fee_location;
if (! $location) { if (! $location || $invoice->amount != $invoice->balance) {
return; return;
} }
@ -1027,10 +1027,23 @@ class InvoiceRepository extends BaseRepository
$invoice = $this->save($data, $invoice); $invoice = $this->save($data, $invoice);
} }
} }
}
public function setGatewayFee($invoice, $gatewayTypeId)
{
$account = $invoice->account;
$location = $account->gateway_fee_location;
if (! $location) {
return;
}
$this->clearGatewayFee($invoice);
$fee = $invoice->calcGatewayFee($gatewayTypeId); $fee = $invoice->calcGatewayFee($gatewayTypeId);
$data = $invoice->toArray(); $data = $invoice->toArray();
$data[$location] = $fee; $data[$location] = $fee;
$this->save($data, $invoice); $this->save($data, $invoice);
} }
} }