Support refunding payment from 'More actions'

This commit is contained in:
Hillel Coren 2017-02-09 12:46:58 +02:00
parent 2739fcb37d
commit 0d71d54b07
6 changed files with 75 additions and 51 deletions

View File

@ -134,6 +134,11 @@ class PaymentController extends BaseController
$actions[] = ['url' => url("/invoices/invoice_history/{$payment->invoice->public_id}?payment_id={$payment->public_id}"), 'label' => trans('texts.view_invoice')];
}
$actions[] = ['url' => url("/invoices/{$payment->invoice->public_id}/edit"), 'label' => trans('texts.edit_invoice')];
if ($payment->canBeRefunded()) {
$actions[] = ['url' => "javascript:showRefundModal({$payment->public_id}, \"{$payment->getCompletedAmount()}\", \"{$payment->present()->amount}\", \"{$payment->present()->currencySymbol}\")", 'label' => trans('texts.refund_payment')];
}
$actions[] = DropdownButton::DIVIDER;
if (! $payment->trashed()) {
$actions[] = ['url' => 'javascript:submitAction("archive")', 'label' => trans('texts.archive_payment')];
@ -195,7 +200,7 @@ class PaymentController extends BaseController
*/
public function update(UpdatePaymentRequest $request)
{
if (in_array($request->action, ['archive', 'delete', 'restore'])) {
if (in_array($request->action, ['archive', 'delete', 'restore', 'refund'])) {
return self::bulk();
}

View File

@ -281,6 +281,11 @@ class Payment extends EntityModel
return $this->amount - $this->refunded;
}
public function canBeRefunded()
{
return $this->getCompletedAmount() > 0 && ($this->isCompleted() || $this->isPartiallyRefunded());
}
/**
* @return mixed|null|\stdClass|string
*/

View File

@ -12,6 +12,11 @@ class PaymentPresenter extends EntityPresenter
return Utils::formatMoney($this->entity->amount, $this->entity->client->currency_id);
}
public function currencySymbol()
{
return Utils::getFromCache($this->entity->currency_id ? $this->entity->currency_id : DEFAULT_CURRENCY, 'currencies')->symbol;
}
public function client()
{
return $this->entity->client ? $this->entity->client->getDisplayName() : '';

View File

@ -73,37 +73,7 @@
->render('datatable') !!}
@if ($entityType == ENTITY_PAYMENT)
<div class="modal fade" id="paymentRefundModal" tabindex="-1" role="dialog" aria-labelledby="paymentRefundModalLabel" aria-hidden="true">
<div class="modal-dialog" style="min-width:150px">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="paymentRefundModalLabel">{{ trans('texts.refund_payment') }}</h4>
</div>
<div class="modal-body">
<div class="form-horizontal">
<div class="form-group">
<label for="refundAmount" class="col-sm-offset-2 col-sm-2 control-label">{{ trans('texts.amount') }}</label>
<div class="col-sm-4">
<div class="input-group">
<span class="input-group-addon" id="refundCurrencySymbol"></span>
<input type="number" class="form-control" id="refundAmount" name="amount" step="0.01" min="0.01" placeholder="{{ trans('texts.amount') }}">
</div>
<div class="help-block">{{ trans('texts.refund_max') }} <span id="refundMax"></span></div>
</div>
</div>
</div>
</div>
<div class="modal-footer" style="margin-top: 0px">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ trans('texts.cancel') }}</button>
<button type="button" class="btn btn-primary" id="completeRefundButton">{{ trans('texts.refund') }}</button>
</div>
</div>
</div>
</div>
@include('partials/refund_payment')
@endif
{!! Former::close() !!}
@ -143,21 +113,6 @@
}
}
@if ($entityType == ENTITY_PAYMENT)
var paymentId = null;
function showRefundModal(id, amount, formatted, symbol){
paymentId = id;
$('#refundCurrencySymbol').text(symbol);
$('#refundMax').text(formatted);
$('#refundAmount').val(amount).attr('max', amount);
$('#paymentRefundModal').modal('show');
}
function handleRefundClicked(){
submitForm_{{ $entityType }}('refund', paymentId);
}
@endif
$(function() {
// Handle datatable filtering
@ -210,10 +165,6 @@
actionListHandler();
}
@if ($entityType == ENTITY_PAYMENT)
$('#completeRefundButton').click(handleRefundClicked)
@endif
$('.listForm_{{ $entityType }} .archive, .invoice').prop('disabled', true);
$('.listForm_{{ $entityType }} .archive:not(.dropdown-toggle)').click(function() {
submitForm_{{ $entityType }}('archive');

View File

@ -0,0 +1,52 @@
<div class="modal fade" id="paymentRefundModal" tabindex="-1" role="dialog" aria-labelledby="paymentRefundModalLabel" aria-hidden="true">
<div class="modal-dialog" style="min-width:150px">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="paymentRefundModalLabel">{{ trans('texts.refund_payment') }}</h4>
</div>
<div class="modal-body">
<div class="form-horizontal">
<div class="form-group">
<label for="refundAmount" class="col-sm-offset-2 col-sm-2 control-label">{{ trans('texts.amount') }}</label>
<div class="col-sm-4">
<div class="input-group">
<span class="input-group-addon" id="refundCurrencySymbol"></span>
<input type="number" class="form-control" id="refundAmount" name="amount" step="0.01" min="0.01" placeholder="{{ trans('texts.amount') }}">
</div>
<div class="help-block">{{ trans('texts.refund_max') }} <span id="refundMax"></span></div>
</div>
</div>
</div>
</div>
<div class="modal-footer" style="margin-top: 0px">
<button type="button" class="btn btn-default" data-dismiss="modal">{{ trans('texts.cancel') }}</button>
<button type="button" class="btn btn-primary" id="completeRefundButton">{{ trans('texts.refund') }}</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var paymentId = null;
function showRefundModal(id, amount, formatted, symbol) {
paymentId = id;
$('#refundCurrencySymbol').text(symbol);
$('#refundMax').text(formatted);
$('#refundAmount').val(amount).attr('max', amount);
$('#paymentRefundModal').modal('show');
}
function handleRefundClicked(){
submitForm_payment('refund', paymentId);
}
$(function() {
$('#completeRefundButton').click(handleRefundClicked);
})
</script>

View File

@ -92,6 +92,8 @@
</center>
@include('partials/refund_payment')
{!! Former::close() !!}
<script type="text/javascript">
@ -135,6 +137,10 @@
$('.main-form').submit();
}
function submitForm_payment(action) {
submitAction(action);
}
function onDeleteClick() {
sweetConfirm(function() {
submitAction('delete');