mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 21:14:29 -04:00
Support refunding payment from 'More actions'
This commit is contained in:
parent
2739fcb37d
commit
0d71d54b07
@ -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/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')];
|
$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;
|
$actions[] = DropdownButton::DIVIDER;
|
||||||
if (! $payment->trashed()) {
|
if (! $payment->trashed()) {
|
||||||
$actions[] = ['url' => 'javascript:submitAction("archive")', 'label' => trans('texts.archive_payment')];
|
$actions[] = ['url' => 'javascript:submitAction("archive")', 'label' => trans('texts.archive_payment')];
|
||||||
@ -195,7 +200,7 @@ class PaymentController extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function update(UpdatePaymentRequest $request)
|
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();
|
return self::bulk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,6 +281,11 @@ class Payment extends EntityModel
|
|||||||
return $this->amount - $this->refunded;
|
return $this->amount - $this->refunded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function canBeRefunded()
|
||||||
|
{
|
||||||
|
return $this->getCompletedAmount() > 0 && ($this->isCompleted() || $this->isPartiallyRefunded());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed|null|\stdClass|string
|
* @return mixed|null|\stdClass|string
|
||||||
*/
|
*/
|
||||||
|
@ -12,6 +12,11 @@ class PaymentPresenter extends EntityPresenter
|
|||||||
return Utils::formatMoney($this->entity->amount, $this->entity->client->currency_id);
|
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()
|
public function client()
|
||||||
{
|
{
|
||||||
return $this->entity->client ? $this->entity->client->getDisplayName() : '';
|
return $this->entity->client ? $this->entity->client->getDisplayName() : '';
|
||||||
|
@ -73,37 +73,7 @@
|
|||||||
->render('datatable') !!}
|
->render('datatable') !!}
|
||||||
|
|
||||||
@if ($entityType == ENTITY_PAYMENT)
|
@if ($entityType == ENTITY_PAYMENT)
|
||||||
<div class="modal fade" id="paymentRefundModal" tabindex="-1" role="dialog" aria-labelledby="paymentRefundModalLabel" aria-hidden="true">
|
@include('partials/refund_payment')
|
||||||
<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">×</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>
|
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
{!! Former::close() !!}
|
{!! 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() {
|
$(function() {
|
||||||
|
|
||||||
// Handle datatable filtering
|
// Handle datatable filtering
|
||||||
@ -210,10 +165,6 @@
|
|||||||
actionListHandler();
|
actionListHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@if ($entityType == ENTITY_PAYMENT)
|
|
||||||
$('#completeRefundButton').click(handleRefundClicked)
|
|
||||||
@endif
|
|
||||||
|
|
||||||
$('.listForm_{{ $entityType }} .archive, .invoice').prop('disabled', true);
|
$('.listForm_{{ $entityType }} .archive, .invoice').prop('disabled', true);
|
||||||
$('.listForm_{{ $entityType }} .archive:not(.dropdown-toggle)').click(function() {
|
$('.listForm_{{ $entityType }} .archive:not(.dropdown-toggle)').click(function() {
|
||||||
submitForm_{{ $entityType }}('archive');
|
submitForm_{{ $entityType }}('archive');
|
||||||
|
52
resources/views/partials/refund_payment.blade.php
Normal file
52
resources/views/partials/refund_payment.blade.php
Normal 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">×</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>
|
@ -92,6 +92,8 @@
|
|||||||
|
|
||||||
</center>
|
</center>
|
||||||
|
|
||||||
|
@include('partials/refund_payment')
|
||||||
|
|
||||||
{!! Former::close() !!}
|
{!! Former::close() !!}
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@ -135,6 +137,10 @@
|
|||||||
$('.main-form').submit();
|
$('.main-form').submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function submitForm_payment(action) {
|
||||||
|
submitAction(action);
|
||||||
|
}
|
||||||
|
|
||||||
function onDeleteClick() {
|
function onDeleteClick() {
|
||||||
sweetConfirm(function() {
|
sweetConfirm(function() {
|
||||||
submitAction('delete');
|
submitAction('delete');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user