Working on gateway fees

This commit is contained in:
Hillel Coren 2017-03-16 18:25:46 +02:00
parent 54275853fd
commit 0ddd4479b7
5 changed files with 19 additions and 19 deletions

View File

@ -394,8 +394,8 @@ if (! defined('APP_NAME')) {
define('GATEWAY_TYPE_CUSTOM', 6);
define('GATEWAY_TYPE_TOKEN', 'token');
define('FEE_LOCATION_CHARGE1', 'invoice_charge1');
define('FEE_LOCATION_CHARGE2', 'invoice_charge2');
define('FEE_LOCATION_CHARGE1', 'custom_value1');
define('FEE_LOCATION_CHARGE2', 'custom_value2');
define('FEE_LOCATION_ITEM', 'invoice_item');
define('REMINDER1', 'reminder1');

View File

@ -1189,6 +1189,12 @@ class AccountController extends BaseController
$account->token_billing_type_id = Input::get('token_billing_type_id');
$account->auto_bill_on_due_date = boolval(Input::get('auto_bill_on_due_date'));
$account->gateway_fee_location = Input::get('gateway_fee_location') ?: null;
if ($account->gateway_fee_location) {
$taxField = $account->gateway_fee_location == FEE_LOCATION_CHARGE1 ? 'custom_invoice_taxes1' : 'custom_invoice_taxes1';
$account->$taxField = false;
}
$account->save();
event(new UserSettingsChanged());

View File

@ -287,8 +287,6 @@ class InvoicePresenter extends EntityPresenter
if (floatval($settings->fee_amount) < 0 || floatval($settings->fee_percent) < 0) {
$label = trans('texts.discount');
} else {
//$field = $account->gateway_fee_location == FEE_LOCATION_CHARGE1 ? 'custom_invoice_label1' : 'custom_invoice_label2';
//$label = $account->$field;
$label = trans('texts.fee');
}

View File

@ -1025,22 +1025,16 @@ class InvoiceRepository extends BaseRepository
if ($location == FEE_LOCATION_ITEM) {
// todo
} else {
if ($location == FEE_LOCATION_CHARGE1) {
$field = 'custom_value1';
} elseif ($location == FEE_LOCATION_CHARGE2) {
$field = 'custom_value2';
}
if ($invoice->$field > 0) {
$data = $invoice->toArray();
$data[$field] = 0;
$data[$location] = 0;
$invoice = $this->save($data, $invoice);
}
}
$fee = $invoice->calcGatewayFee($gatewayTypeId);
$data = $invoice->toArray();
$data[$field] = $fee;
$data[$location] = $fee;
$this->save($data, $invoice);
}
}

View File

@ -238,18 +238,20 @@
->label(trans('texts.field_label'))
->placeholder($account->gateway_fee_location == FEE_LOCATION_CHARGE1 ? trans('texts.surcharge') : ' ')
->addGroupClass('pad-checkbox')
->append(Former::checkbox('custom_invoice_taxes1')
->value(1)
->raw() . trans('texts.charge_taxes')) !!}
->append($account->gateway_fee_location == FEE_LOCATION_CHARGE1 ? false :
Former::checkbox('custom_invoice_taxes1')
->value(1)
->raw() . trans('texts.charge_taxes')) !!}
{!! Former::text('custom_invoice_label2')
->label(trans('texts.field_label'))
->placeholder($account->gateway_fee_location == FEE_LOCATION_CHARGE2 ? trans('texts.surcharge') : ' ')
->addGroupClass('pad-checkbox')
->append(Former::checkbox('custom_invoice_taxes2')
->value(1)
->raw() . trans('texts.charge_taxes'))
->help(trans('texts.custom_invoice_charges_helps')) !!}
->append($account->gateway_fee_location == FEE_LOCATION_CHARGE2 ? false :
Former::checkbox('custom_invoice_taxes2')
->value(1)
->raw() . trans('texts.charge_taxes'))
->help(trans('texts.custom_invoice_charges_helps')) !!}
</div>
</div>