mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Working on gateway fees
This commit is contained in:
parent
b2cfc8b99a
commit
23eee0183e
@ -43,7 +43,8 @@ if (! defined('APP_NAME')) {
|
|||||||
|
|
||||||
define('INVOICE_ITEM_TYPE_STANDARD', 1);
|
define('INVOICE_ITEM_TYPE_STANDARD', 1);
|
||||||
define('INVOICE_ITEM_TYPE_TASK', 2);
|
define('INVOICE_ITEM_TYPE_TASK', 2);
|
||||||
define('INVOICE_ITEM_TYPE_GATEWAY_FEE', 3);
|
define('INVOICE_ITEM_TYPE_PENDING_GATEWAY_FEE', 3);
|
||||||
|
define('INVOICE_ITEM_TYPE_PAID_GATEWAY_FEE', 4);
|
||||||
|
|
||||||
define('PERSON_CONTACT', 'contact');
|
define('PERSON_CONTACT', 'contact');
|
||||||
define('PERSON_USER', 'user');
|
define('PERSON_USER', 'user');
|
||||||
|
@ -51,7 +51,6 @@ trait ChargesFees
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if ($account->gateway_fee_location == FEE_LOCATION_ITEM && $includeTax) {
|
if ($account->gateway_fee_location == FEE_LOCATION_ITEM && $includeTax) {
|
||||||
$preTaxFee = $fee;
|
$preTaxFee = $fee;
|
||||||
|
|
||||||
@ -63,8 +62,22 @@ trait ChargesFees
|
|||||||
$fee += $preTaxFee * $settings->fee_tax_rate2 / 100;
|
$fee += $preTaxFee * $settings->fee_tax_rate2 / 100;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
return round($fee, 2);
|
return round($fee, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getGatewayFeeItem()
|
||||||
|
{
|
||||||
|
if (! $this->relationLoaded('invoice_items')) {
|
||||||
|
$this->load('invoice_items');
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($this->invoice_items as $item) {
|
||||||
|
if ($item->invoice_item_type_id == INVOICE_ITEM_TYPE_PENDING_GATEWAY_FEE) {
|
||||||
|
return $item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ use App\Models\Invoice;
|
|||||||
use App\Models\InvoiceItem;
|
use App\Models\InvoiceItem;
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
use App\Models\Task;
|
use App\Models\Task;
|
||||||
|
use App\Models\GatewayType;
|
||||||
use App\Services\PaymentService;
|
use App\Services\PaymentService;
|
||||||
use Auth;
|
use Auth;
|
||||||
use DB;
|
use DB;
|
||||||
@ -1017,9 +1018,14 @@ class InvoiceRepository extends BaseRepository
|
|||||||
$invoice->load('invoice_items');
|
$invoice->load('invoice_items');
|
||||||
}
|
}
|
||||||
|
|
||||||
// first remove fee if already set
|
|
||||||
if ($location == FEE_LOCATION_ITEM) {
|
if ($location == FEE_LOCATION_ITEM) {
|
||||||
// todo
|
$data = $invoice->toArray();
|
||||||
|
foreach ($data['invoice_items'] as $key => $item) {
|
||||||
|
if ($item['invoice_item_type_id'] == INVOICE_ITEM_TYPE_PENDING_GATEWAY_FEE) {
|
||||||
|
unset($data[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//dd($data['invoice_items']);
|
||||||
} else {
|
} else {
|
||||||
if ($invoice->$location != 0) {
|
if ($invoice->$location != 0) {
|
||||||
$data = $invoice->toArray();
|
$data = $invoice->toArray();
|
||||||
@ -1033,16 +1039,35 @@ class InvoiceRepository extends BaseRepository
|
|||||||
{
|
{
|
||||||
$account = $invoice->account;
|
$account = $invoice->account;
|
||||||
$location = $account->gateway_fee_location;
|
$location = $account->gateway_fee_location;
|
||||||
|
$settings = $account->getGatewaySettings($gatewayTypeId);
|
||||||
|
|
||||||
if (! $location) {
|
if (! $location) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->clearGatewayFee($invoice);
|
$this->clearGatewayFee($invoice);
|
||||||
|
|
||||||
$fee = $invoice->calcGatewayFee($gatewayTypeId);
|
|
||||||
$data = $invoice->toArray();
|
$data = $invoice->toArray();
|
||||||
|
|
||||||
|
if ($location == FEE_LOCATION_ITEM) {
|
||||||
|
$fee = $invoice->calcGatewayFee($gatewayTypeId, false);
|
||||||
|
|
||||||
|
$item = [];
|
||||||
|
$item['product_key'] = trans('texts.surcharge');
|
||||||
|
$item['notes'] = trans('texts.online_payment_surcharge');
|
||||||
|
$item['qty'] = 1;
|
||||||
|
$item['cost'] = $fee;
|
||||||
|
$item['tax_rate1'] = $settings->fee_tax_rate1;
|
||||||
|
$item['tax_name1'] = $settings->fee_tax_name1;
|
||||||
|
$item['tax_rate2'] = $settings->fee_tax_rate2;
|
||||||
|
$item['tax_name2'] = $settings->fee_tax_name2;
|
||||||
|
$item['invoice_item_type_id'] = INVOICE_ITEM_TYPE_PENDING_GATEWAY_FEE;
|
||||||
|
|
||||||
|
$data['invoice_items'][] = $item;
|
||||||
|
} else {
|
||||||
|
$fee = $invoice->calcGatewayFee($gatewayTypeId);
|
||||||
|
|
||||||
$data[$location] = $fee;
|
$data[$location] = $fee;
|
||||||
|
}
|
||||||
|
|
||||||
$this->save($data, $invoice);
|
$this->save($data, $invoice);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user