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

Fixes for calcuting gateway fees and for removing unpaid gateway fees appropriately

This commit is contained in:
David Bomba 2020-10-11 08:31:50 +11:00
parent 965b7691fd
commit 8b48f26c79
2 changed files with 19 additions and 8 deletions

View File

@ -95,6 +95,7 @@ class InvoiceController extends Controller
}
$invoices->map(function ($invoice) {
$invoice->service()->removeUnpaidGatewayFees()->save();
$invoice->balance = Number::formatValue($invoice->balance, $invoice->client->currency());
$invoice->partial = Number::formatValue($invoice->partial, $invoice->client->currency());

View File

@ -163,19 +163,29 @@ class PaymentController extends Controller
$first_invoice = $invoices->first();
$fee_totals = round($gateway->calcGatewayFee($invoice_totals, true), $first_invoice->client->currency()->precision);
$starting_invoice_amount = $first_invoice->amount;
if (!$first_invoice->uses_inclusive_taxes) {
$fee_tax = 0;
$fee_tax += round(($first_invoice->tax_rate1 / 100) * $fee_totals, $first_invoice->client->currency()->precision);
$fee_tax += round(($first_invoice->tax_rate2 / 100) * $fee_totals, $first_invoice->client->currency()->precision);
$fee_tax += round(($first_invoice->tax_rate3 / 100) * $fee_totals, $first_invoice->client->currency()->precision);
// $fee_totals = round($gateway->calcGatewayFee($invoice_totals, true), $first_invoice->client->currency()->precision);
$fee_totals += $fee_tax;
}
// if (!$first_invoice->uses_inclusive_taxes) {
// $fee_tax = 0;
// $fee_tax += round(($first_invoice->tax_rate1 / 100) * $fee_totals, $first_invoice->client->currency()->precision);
// $fee_tax += round(($first_invoice->tax_rate2 / 100) * $fee_totals, $first_invoice->client->currency()->precision);
// $fee_tax += round(($first_invoice->tax_rate3 / 100) * $fee_totals, $first_invoice->client->currency()->precision);
// $fee_totals += $fee_tax;
// }
$first_invoice->service()->addGatewayFee($gateway, $invoice_totals)->save();
/**
*
* The best way to determine the exact gateway fee is to not calculate it in isolation (due to rounding)
* but to simply add it as a line item, and then subtract the starting and finishing amounts of
* the invoice.
*/
$fee_totals = $first_invoice->amount - $starting_invoice_amount;
$payment_hash = new PaymentHash;
$payment_hash->hash = Str::random(128);
$payment_hash->data = $payable_invoices;