1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 00:11:35 +02:00

Support negative gateway fees

This commit is contained in:
Hillel Coren 2017-03-16 17:32:46 +02:00
parent 5920940403
commit 2a7dec8893
9 changed files with 50 additions and 22 deletions

View File

@ -53,11 +53,11 @@ class AccountGatewaySettings extends EntityModel
{
$parts = [];
if (floatval($this->fee_amount)) {
if (floatval($this->fee_amount) != 0) {
$parts[] = Utils::formatMoney($this->fee_amount);
}
if (floatval($this->fee_percent)) {
if (floatval($this->fee_percent) != 0) {
$parts[] = (floor($this->fee_percent * 1000) / 1000) . '%';
}

View File

@ -851,7 +851,7 @@ class BasePaymentDriver
}
if ($fee = $this->invoice()->present()->gatewayFee($paymentMethod->payment_type->gateway_type_id)) {
$label .= sprintf(' - %s: %s', trans('texts.fee'), $fee);
$label .= ' - ' . $fee;
}
$links[] = [
@ -887,7 +887,7 @@ class BasePaymentDriver
}
if ($fee = $this->invoice()->present()->gatewayFee($gatewayTypeId)) {
$label .= sprintf(' - %s: %s', trans('texts.fee'), $fee);
$label .= ' - ' . $fee;
}
$links[] = [

View File

@ -257,6 +257,11 @@ class InvoicePresenter extends EntityPresenter
{
$invoice = $this->entity;
$account = $invoice->account;
if (! $account->gateway_fee_location) {
return '';
}
$settings = $account->getGatewaySettings($gatewayTypeId);
if (! $settings || ! $settings->areFeesEnabled()) {
@ -265,14 +270,28 @@ class InvoicePresenter extends EntityPresenter
$parts = [];
if ($settings->fee_amount) {
if (floatval($settings->fee_amount) != 0) {
$parts[] = $account->formatMoney($settings->fee_amount, $invoice->client);
}
if (floatval($settings->fee_percent) > 0) {
if (floatval($settings->fee_percent) != 0) {
$parts[] = (floor($settings->fee_percent * 1000) / 1000) . '%';
}
return join(' + ', $parts);
if (! count($parts)) {
return '';
}
$str = join(' + ', $parts);
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');
}
return $label . ': ' . $str;
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -561,11 +561,17 @@ NINJA.subtotals = function(invoice, hideBalance)
data.push([{text: invoiceLabels.discount , style: ['subtotalsLabel', 'discountLabel']}, {text: formatMoneyInvoice(invoice.discount_amount, invoice), style: ['subtotals', 'discount']}]);
}
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 == '1') {
data.push([{text: account.custom_invoice_label1 || invoiceLabels.surcharge, style: ['subtotalsLabel', 'customTax1Label']}, {text: formatMoneyInvoice(invoice.custom_value1, invoice), style: ['subtotals', 'customTax1']}]);
var customValue1 = NINJA.parseFloat(invoice.custom_value1);
var customValue1Label = customValue1 >= 0 ? (account.custom_invoice_label1 || invoiceLabels.surcharge) : invoiceLabels.discount;
var customValue2 = NINJA.parseFloat(invoice.custom_value2);
var customValue2Label = customValue2 >= 0 ? (account.custom_invoice_label2 || invoiceLabels.surcharge) : invoiceLabels.discount;
if (customValue1 && invoice.custom_taxes1 == '1') {
data.push([{text: customValue1Label, style: ['subtotalsLabel', 'customTax1Label']}, {text: formatMoneyInvoice(invoice.custom_value1, invoice), style: ['subtotals', 'customTax1']}]);
}
if (NINJA.parseFloat(invoice.custom_value2) && invoice.custom_taxes2 == '1') {
data.push([{text: account.custom_invoice_label2 || invoiceLabels.surcharge, style: ['subtotalsLabel', 'customTax2Label']}, {text: formatMoneyInvoice(invoice.custom_value2, invoice), style: ['subtotals', 'customTax2']}]);
if (customValue2 && invoice.custom_taxes2 == '1') {
data.push([{text: customValue2Label, style: ['subtotalsLabel', 'customTax2Label']}, {text: formatMoneyInvoice(invoice.custom_value2, invoice), style: ['subtotals', 'customTax2']}]);
}
for (var key in invoice.item_taxes) {
@ -585,11 +591,11 @@ NINJA.subtotals = function(invoice, hideBalance)
data.push([{text: taxStr, style: ['subtotalsLabel', 'tax2Label']}, {text: formatMoneyInvoice(invoice.tax_amount2, invoice), style: ['subtotals', 'tax2']}]);
}
if (NINJA.parseFloat(invoice.custom_value1) && invoice.custom_taxes1 != '1') {
data.push([{text: account.custom_invoice_label1 || invoiceLabels.surcharge, style: ['subtotalsLabel', 'custom1Label']}, {text: formatMoneyInvoice(invoice.custom_value1, invoice), style: ['subtotals', 'custom1']}]);
if (customValue1 && invoice.custom_taxes1 != '1') {
data.push([{text: customValue1Label, style: ['subtotalsLabel', 'custom1Label']}, {text: formatMoneyInvoice(invoice.custom_value1, invoice), style: ['subtotals', 'custom1']}]);
}
if (NINJA.parseFloat(invoice.custom_value2) && invoice.custom_taxes2 != '1') {
data.push([{text: account.custom_invoice_label2 || invoiceLabels.surcharge, style: ['subtotalsLabel', 'custom2Label']}, {text: formatMoneyInvoice(invoice.custom_value2, invoice), style: ['subtotals', 'custom2']}]);
if (customValue2 && invoice.custom_taxes2 != '1') {
data.push([{text: customValue2Label, style: ['subtotalsLabel', 'custom2Label']}, {text: formatMoneyInvoice(invoice.custom_value2, invoice), style: ['subtotals', 'custom2']}]);
}
var paid = invoice.amount - invoice.balance;

View File

@ -2403,6 +2403,7 @@ $LANG = array(
'set_limits_fees' => 'Set :gateway_type Limits/Fees',
'fees_tax_help' => 'Enable line item taxes to set 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',
'gateway_fees_disclaimer' => 'Warning: not all states/payment gateways allow adding fees, please review local laws/terms of service.',
'percent' => 'Percent',

View File

@ -131,14 +131,12 @@
->label('amount')
->onchange('updateFeeSample()')
->type('number')
->min('0')
->step('any') !!}
{!! Former::text('fee_percent')
->label('percent')
->onchange('updateFeeSample()')
->type('number')
->min('0')
->step('any')
->append('%') !!}
@ -312,7 +310,7 @@
function updateFeeSample() {
var feeAmount = NINJA.parseFloat($('#fee_amount').val()) || 0;
var feePercent = NINJA.parseFloat($('#fee_percent').val()) || 0;
var total = feeAmount + feePercent
var total = feeAmount + (feePercent * 100 / 100);
var subtotal = total;
var taxRate1 = $('#tax_rate1').val();
@ -327,7 +325,11 @@
total += subtotal * taxRate2 / 100;
}
var str = "{{ trans('texts.fees_sample') }}";
if (total > 0) {
var str = "{{ trans('texts.fees_sample') }}";
} else {
var str = "{{ trans('texts.discount_sample') }}";
}
str = str.replace(':amount', formatMoney(100));
str = str.replace(':total', formatMoney(total));
$('#feeSample').text(str);

View File

@ -125,7 +125,7 @@
@elseif (count($paymentTypes) == 1)
<a href='{!! $paymentURL !!}' class="btn btn-success btn-lg">{{ trans('texts.pay_now') }}</a>
@if ($fee = $invoice->present()->gatewayFee($gatewayTypeId))
<div class="help-block">{{ trans('texts.online_payment_surcharge') }}: {{ $fee }}</div>
<div class="help-block">{{ $fee }}</div>
@endif
@endif
@else