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()
|
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;
|
$account = $this->account;
|
||||||
$settings = $account->getGatewaySettings($gatewayTypeId);
|
$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;
|
$fee = 0;
|
||||||
|
|
||||||
if (! $settings) {
|
if (! $settings) {
|
||||||
@ -28,44 +29,65 @@ trait ChargesFees
|
|||||||
|
|
||||||
if ($settings->fee_percent) {
|
if ($settings->fee_percent) {
|
||||||
// prevent charging taxes twice on the surcharge
|
// prevent charging taxes twice on the surcharge
|
||||||
$amount = $this->amount;
|
if ($location == FEE_LOCATION_ITEM) {
|
||||||
if ($this->$taxField) {
|
$amount = $this->partial > 0 ? $this->partial : $this->balance;
|
||||||
$taxAmount = 0;
|
} else {
|
||||||
foreach ($this->getTaxes() as $key => $tax) {
|
$amount = $this->amount;
|
||||||
$taxAmount += $tax['amount'];
|
if ($this->$taxField) {
|
||||||
|
$taxAmount = 0;
|
||||||
|
foreach ($this->getTaxes() as $key => $tax) {
|
||||||
|
$taxAmount += $tax['amount'];
|
||||||
|
}
|
||||||
|
$amount -= $taxAmount;
|
||||||
}
|
}
|
||||||
$amount -= $taxAmount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$fee += $amount * $settings->fee_percent / 100;
|
$fee += $amount * $settings->fee_percent / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate final amount with tax
|
// calculate final amount with tax
|
||||||
if ($includeTax && $this->$taxField) {
|
if ($includeTax) {
|
||||||
$preTaxFee = $fee;
|
if ($location == FEE_LOCATION_ITEM) {
|
||||||
if (floatval($this->tax_rate1)) {
|
$preTaxFee = $fee;
|
||||||
$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 ($settings->fee_tax_rate1) {
|
||||||
$preTaxFee = $fee;
|
$fee += $preTaxFee * $settings->fee_tax_rate1 / 100;
|
||||||
|
}
|
||||||
|
|
||||||
if ($settings->fee_tax_rate1) {
|
if ($settings->fee_tax_rate2) {
|
||||||
$fee += $preTaxFee * $settings->fee_tax_rate1 / 100;
|
$fee += $preTaxFee * $settings->fee_tax_rate2 / 100;
|
||||||
}
|
}
|
||||||
|
} elseif ($this->$taxField) {
|
||||||
if ($settings->fee_tax_rate2) {
|
$preTaxFee = $fee;
|
||||||
$fee += $preTaxFee * $settings->fee_tax_rate2 / 100;
|
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);
|
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()
|
public function getGatewayFeeItem()
|
||||||
{
|
{
|
||||||
if (! $this->relationLoaded('invoice_items')) {
|
if (! $this->relationLoaded('invoice_items')) {
|
||||||
|
@ -1087,5 +1087,6 @@ class InvoiceRepository extends BaseRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->save($data, $invoice);
|
$this->save($data, $invoice);
|
||||||
|
$invoice->load('invoice_items');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user