Working on gateway fees

This commit is contained in:
Hillel Coren 2017-03-17 12:13:27 +02:00
parent 7b2f46b087
commit b2cfc8b99a
4 changed files with 37 additions and 18 deletions

View File

@ -49,6 +49,11 @@ class AccountGatewaySettings extends EntityModel
return floatval($this->fee_amount) || floatval($this->fee_percent);
}
public function hasTaxes()
{
return floatval($this->fee_tax_rate1) || floatval($this->fee_tax_rate1);
}
public function feesToString()
{
$parts = [];
@ -61,10 +66,6 @@ class AccountGatewaySettings extends EntityModel
$parts[] = (floor($this->fee_percent * 1000) / 1000) . '%';
}
if ($this->fee_location == FEE_LOCATION_ITEM && (floatval($this->fee_tax_rate1) || floatval($this->fee_tax_rate1))) {
$parts[] = trans('texts.tax');
}
return join(' + ', $parts);
}
}

View File

@ -97,7 +97,7 @@ class AccountGatewayDatatable extends EntityDatatable
[
'fees',
function ($model) {
if (! $model->gateway_fee_location) {
if (! $feeLocation = $model->gateway_fee_location) {
return trans('texts.fees_disabled');
}
@ -118,6 +118,17 @@ class AccountGatewayDatatable extends EntityDatatable
$html .= $gatewayType->name . ' — ';
}
$html .= $accountGatewaySettings->feesToString();
if ($feeLocation == FEE_LOCATION_ITEM) {
if ($accountGatewaySettings->hasTaxes()) {
$html .= ' + ' . trans('texts.tax');
}
} else {
$field = ($feeLocation == FEE_LOCATION_CHARGE1 ? 'custom_invoice_taxes1' : 'custom_invoice_taxes1');
if (\Auth::user()->account->$field) {
$html .= ' + ' . trans('texts.tax');
}
}
};
return $html ?: trans('texts.no_fees');
},

View File

@ -2401,7 +2401,7 @@ $LANG = array(
'fees' => 'Fees',
'fee' => 'Fee',
'set_limits_fees' => 'Set :gateway_type Limits/Fees',
'fees_tax_help' => 'Enable line item taxes to set fee tax rates.',
'fees_tax_help' => 'Enable line item taxes to set the fee tax rates.',
'fees_sample' => 'The fee for a :amount invoice would be :total.',
'discount_sample' => 'The discount for a :amount invoice would be :total.',
'no_fees' => 'No Fees',
@ -2410,12 +2410,14 @@ $LANG = array(
'location' => 'Location',
'line_item' => 'Line Item',
'surcharge' => 'Surcharge',
'first_surcharge' => 'Enabled - Use first surcharge',
'second_surcharge' => 'Enabled - Use second surcharge',
'location_first_surcharge' => 'Enabled - First surcharge',
'location_second_surcharge' => 'Enabled - Second surcharge',
'location_line_item' => 'Enabled - Line item',
'online_payment_surcharge' => 'Online Payment Surcharge',
'gateway_fees' => 'Gateway Fees',
'fees_disabled' => 'Fees are disabled',
'gateway_fees_help' => 'Automatically add an online payment surcharge [partial payments are not supported].',
//'gateway_fees_help' => 'Automatically add an online payment surcharge [partial payments are not supported].',
'gateway_fees_help' => 'Automatically add an online payment surcharge or line item.<br/>Use \'Line item\' to support partial payments.',
'gateway' => 'Gateway',
);

View File

@ -27,9 +27,9 @@
<br/>
{!! Former::select('gateway_fee_location')
->addOption(trans('texts.disabled'), '')
->addOption(trans('texts.first_surcharge') . ($account->custom_invoice_label1 ? ' | ' . $account->custom_invoice_label1 : ''), FEE_LOCATION_CHARGE1)
->addOption(trans('texts.second_surcharge') . ($account->custom_invoice_label2 ? ' | ' . $account->custom_invoice_label2 : '' ), FEE_LOCATION_CHARGE2)
//->addOption(trans('texts.line_item'), FEE_LOCATION_ITEM)
->addOption(trans('texts.location_first_surcharge') . ($account->custom_invoice_label1 ? ' | ' . $account->custom_invoice_label1 : ''), FEE_LOCATION_CHARGE1)
->addOption(trans('texts.location_second_surcharge') . ($account->custom_invoice_label2 ? ' | ' . $account->custom_invoice_label2 : '' ), FEE_LOCATION_CHARGE2)
->addOption(trans('texts.location_line_item'), FEE_LOCATION_ITEM)
->help('gateway_fees_help')
->label('gateway_fees')!!}
<br/>
@ -164,14 +164,15 @@
{!! Former::text('fee_tax_rate1') !!}
{!! Former::text('fee_tax_name2') !!}
{!! Former::text('fee_tax_rate2') !!}
</div><br/>
<div class="help-block">
<span id="feeSample"></span>
@if ($account->gateway_fee_location == FEE_LOCATION_ITEM && !$account->invoice_item_taxes && $account->invoice_taxes && count($taxRates))
{{ trans('texts.fees_tax_help') }}
@endif
</div>
<br/><div id="feeSample" class="help-block"></div>
@if (false && !$account->invoice_item_taxes && $account->invoice_taxes && count($taxRates))
<br/><div class="help-block">{{ trans('texts.fees_tax_help') }}</div>
@endif
<br/><b>{{ trans('texts.gateway_fees_disclaimer') }}</b>
</div>
@ -252,6 +253,10 @@
$('#paymentLimitsModal').modal('show');
updateFeeSample();
@if ($account->gateway_fee_location == FEE_LOCATION_ITEM)
$('#taxDiv').show();
@endif
}
var limitsSlider = document.getElementById('payment-limits-slider');