mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
Working on gateway fees
This commit is contained in:
parent
5f23c89121
commit
fa2e50f15c
@ -768,7 +768,16 @@ class Invoice extends EntityModel implements BalanceAffecting
|
||||
*/
|
||||
public function getRequestedAmount()
|
||||
{
|
||||
return $this->partial > 0 ? $this->partial : $this->balance;
|
||||
$fee = 0;
|
||||
if ($this->account->gateway_fee_location) {
|
||||
$fee = $this->getGatewayFee();
|
||||
}
|
||||
|
||||
if ($this->partial > 0) {
|
||||
return $this->partial + $fee;
|
||||
} else {
|
||||
return $this->balance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,7 +15,8 @@ trait ChargesFees
|
||||
{
|
||||
$account = $this->account;
|
||||
$settings = $account->getGatewaySettings($gatewayTypeId);
|
||||
$taxField = $account->gateway_fee_location == FEE_LOCATION_CHARGE1 ? 'custom_taxes1' : 'custom_taxes1';
|
||||
$location = $account->gateway_fee_location;
|
||||
$taxField = $location == FEE_LOCATION_CHARGE1 ? 'custom_taxes1' : 'custom_taxes1';
|
||||
$fee = 0;
|
||||
|
||||
if (! $settings) {
|
||||
@ -28,6 +29,9 @@ trait ChargesFees
|
||||
|
||||
if ($settings->fee_percent) {
|
||||
// prevent charging taxes twice on the surcharge
|
||||
if ($location == FEE_LOCATION_ITEM) {
|
||||
$amount = $this->partial > 0 ? $this->partial : $this->balance;
|
||||
} else {
|
||||
$amount = $this->amount;
|
||||
if ($this->$taxField) {
|
||||
$taxAmount = 0;
|
||||
@ -36,22 +40,14 @@ trait ChargesFees
|
||||
}
|
||||
$amount -= $taxAmount;
|
||||
}
|
||||
}
|
||||
|
||||
$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) {
|
||||
if ($includeTax) {
|
||||
if ($location == FEE_LOCATION_ITEM) {
|
||||
$preTaxFee = $fee;
|
||||
|
||||
if ($settings->fee_tax_rate1) {
|
||||
@ -61,11 +57,37 @@ trait ChargesFees
|
||||
if ($settings->fee_tax_rate2) {
|
||||
$fee += $preTaxFee * $settings->fee_tax_rate2 / 100;
|
||||
}
|
||||
} elseif ($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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return round($fee, 2);
|
||||
}
|
||||
|
||||
public function getGatewayFee()
|
||||
{
|
||||
$account = $this->account;
|
||||
$location = $account->gateway_fee_location;
|
||||
|
||||
if (! $location) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($location == FEE_LOCATION_ITEM) {
|
||||
$item = $this->getGatewayFeeItem();
|
||||
return $item ? $item->amount() : 0;
|
||||
} else {
|
||||
return $this->$location;
|
||||
}
|
||||
}
|
||||
|
||||
public function getGatewayFeeItem()
|
||||
{
|
||||
if (! $this->relationLoaded('invoice_items')) {
|
||||
|
@ -1087,5 +1087,6 @@ class InvoiceRepository extends BaseRepository
|
||||
}
|
||||
|
||||
$this->save($data, $invoice);
|
||||
$invoice->load('invoice_items');
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user