mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-09 20:52:56 +01:00
Working on gateway fees
This commit is contained in:
parent
f1c464c4cf
commit
5fcf0c57a4
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Utils;
|
||||
|
||||
/**
|
||||
* Class AccountGatewaySettings.
|
||||
*/
|
||||
@ -41,4 +43,28 @@ class AccountGatewaySettings extends EntityModel
|
||||
{
|
||||
// to Disable created_at
|
||||
}
|
||||
|
||||
public function areFeesEnabled()
|
||||
{
|
||||
return floatval($this->fee_amount) || floatval($this->fee_percent);
|
||||
}
|
||||
|
||||
public function feesToString()
|
||||
{
|
||||
$parts = [];
|
||||
|
||||
if (floatval($this->fee_amount)) {
|
||||
$parts[] = Utils::formatMoney($this->fee_amount);
|
||||
}
|
||||
|
||||
if (floatval($this->fee_percent)) {
|
||||
$parts[] = $this->fee_percent . '%';
|
||||
}
|
||||
|
||||
if (floatval($this->fee_tax_rate1) || floatval($this->fee_tax_rate1)) {
|
||||
$parts[] = trans('texts.tax');
|
||||
}
|
||||
|
||||
return join(' + ', $parts);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ use Utils;
|
||||
class AccountGatewayDatatable extends EntityDatatable
|
||||
{
|
||||
private static $accountGateways;
|
||||
private static $accountGatewaySettings;
|
||||
|
||||
public $entityType = ENTITY_ACCOUNT_GATEWAY;
|
||||
|
||||
@ -62,26 +63,16 @@ class AccountGatewayDatatable extends EntityDatatable
|
||||
[
|
||||
'limit',
|
||||
function ($model) {
|
||||
if ($model->gateway_id == GATEWAY_CUSTOM) {
|
||||
$gatewayTypes = [GATEWAY_TYPE_CUSTOM];
|
||||
} else {
|
||||
$accountGateway = $this->getAccountGateway($model->id);
|
||||
$paymentDriver = $accountGateway->paymentDriver();
|
||||
$gatewayTypes = $paymentDriver->gatewayTypes();
|
||||
$gatewayTypes = array_diff($gatewayTypes, [GATEWAY_TYPE_TOKEN]);
|
||||
}
|
||||
|
||||
$gatewayTypes = $this->getGatewayTypes($model->id, $model->gateway_id);
|
||||
$html = '';
|
||||
foreach ($gatewayTypes as $gatewayTypeId) {
|
||||
$accountGatewaySettings = AccountGatewaySettings::scope()->where('account_gateway_settings.gateway_type_id',
|
||||
'=', $gatewayTypeId)->first();
|
||||
$gatewayType = GatewayType::find($gatewayTypeId);
|
||||
$accountGatewaySettings = $this->getAccountGatewaySetting($gatewayTypeId);
|
||||
$gatewayType = Utils::getFromCache($gatewayTypeId, 'gatewayTypes');
|
||||
|
||||
if (count($gatewayTypes) > 1) {
|
||||
if ($html) {
|
||||
$html .= '<br>';
|
||||
}
|
||||
|
||||
$html .= $gatewayType->name . ' — ';
|
||||
}
|
||||
|
||||
@ -106,7 +97,25 @@ class AccountGatewayDatatable extends EntityDatatable
|
||||
[
|
||||
'fees',
|
||||
function ($model) {
|
||||
return 'Fees description...';
|
||||
$gatewayTypes = $this->getGatewayTypes($model->id, $model->gateway_id);
|
||||
$html = '';
|
||||
foreach ($gatewayTypes as $gatewayTypeId) {
|
||||
$accountGatewaySettings = $this->getAccountGatewaySetting($gatewayTypeId);
|
||||
if (! $accountGatewaySettings || ! $accountGatewaySettings->areFeesEnabled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$gatewayType = Utils::getFromCache($gatewayTypeId, 'gatewayTypes');
|
||||
|
||||
if (count($gatewayTypes) > 1) {
|
||||
if ($html) {
|
||||
$html .= '<br>';
|
||||
}
|
||||
$html .= $gatewayType->name . ' — ';
|
||||
}
|
||||
$html .= $accountGatewaySettings->feesToString();
|
||||
};
|
||||
return $html ?: trans('texts.no_fees');
|
||||
},
|
||||
],
|
||||
];
|
||||
@ -168,9 +177,7 @@ class AccountGatewayDatatable extends EntityDatatable
|
||||
$actions[] = [
|
||||
trans('texts.set_limits_fees', ['gateway_type' => $gatewayType->name]),
|
||||
function () use ($gatewayType) {
|
||||
$accountGatewaySettings = AccountGatewaySettings::scope()
|
||||
->where('account_gateway_settings.gateway_type_id', '=', $gatewayType->id)
|
||||
->first();
|
||||
//$accountGatewaySettings = $this->getAccountGatewaySetting($gatewayType->id);
|
||||
//$min = $accountGatewaySettings && $accountGatewaySettings->min_limit !== null ? $accountGatewaySettings->min_limit : 'null';
|
||||
//$max = $accountGatewaySettings && $accountGatewaySettings->max_limit !== null ? $accountGatewaySettings->max_limit : 'null';
|
||||
return "javascript:showLimitsModal('{$gatewayType->name}', {$gatewayType->id})";
|
||||
@ -200,4 +207,30 @@ class AccountGatewayDatatable extends EntityDatatable
|
||||
|
||||
return static::$accountGateways[$id];
|
||||
}
|
||||
|
||||
private function getAccountGatewaySetting($gatewayTypeId)
|
||||
{
|
||||
if (isset(static::$accountGatewaySettings[$gatewayTypeId])) {
|
||||
return static::$accountGatewaySettings[$gatewayTypeId];
|
||||
}
|
||||
|
||||
static::$accountGatewaySettings[$gatewayTypeId] = AccountGatewaySettings::scope()
|
||||
->where('account_gateway_settings.gateway_type_id', '=', $gatewayTypeId)->first();
|
||||
|
||||
return static::$accountGatewaySettings[$gatewayTypeId];
|
||||
}
|
||||
|
||||
private function getGatewayTypes($id, $gatewayId)
|
||||
{
|
||||
if ($gatewayId == GATEWAY_CUSTOM) {
|
||||
$gatewayTypes = [GATEWAY_TYPE_CUSTOM];
|
||||
} else {
|
||||
$accountGateway = $this->getAccountGateway($id);
|
||||
$paymentDriver = $accountGateway->paymentDriver();
|
||||
$gatewayTypes = $paymentDriver->gatewayTypes();
|
||||
$gatewayTypes = array_diff($gatewayTypes, [GATEWAY_TYPE_TOKEN]);
|
||||
}
|
||||
|
||||
return $gatewayTypes;
|
||||
}
|
||||
}
|
||||
|
@ -2405,6 +2405,7 @@ $LANG = array(
|
||||
'fee_percent' => 'Percent',
|
||||
'fees_tax_help' => 'Enable line item taxes to set fee tax rates.',
|
||||
'fees_sample' => 'The fee for a :amount invoice would be :total.',
|
||||
'no_fees' => 'No Fees',
|
||||
|
||||
);
|
||||
|
||||
|
@ -51,7 +51,7 @@
|
||||
->setOptions('sPaginationType', 'bootstrap')
|
||||
->setOptions('bFilter', false)
|
||||
->setOptions('bAutoWidth', false)
|
||||
->setOptions('aoColumns', [[ "sWidth"=> "30%" ], ["sWidth"=> "30%"], ["sWidth"=> "20%"], ["sWidth"=> "20%"]])
|
||||
->setOptions('aoColumns', [[ "sWidth"=> "24%" ], ["sWidth"=> "27%"], ["sWidth"=> "27%"], ["sWidth"=> "20%"]])
|
||||
->setOptions('aoColumnDefs', [['bSortable'=>false, 'aTargets'=>[1, 2, 3]]])
|
||||
->render('datatable') !!}
|
||||
|
||||
@ -234,7 +234,7 @@
|
||||
}
|
||||
|
||||
$('#paymentLimitsModal').modal('show');
|
||||
|
||||
|
||||
updateFeeSample();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user