mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 20:22:42 +01:00
Add payment status label
This commit is contained in:
parent
988ef9af66
commit
751ff62632
@ -17,6 +17,15 @@ class Payment extends EntityModel
|
||||
use PresentableTrait;
|
||||
use SoftDeletes;
|
||||
|
||||
public static $statusClasses = [
|
||||
PAYMENT_STATUS_PENDING => 'info',
|
||||
PAYMENT_STATUS_COMPLETED => 'success',
|
||||
PAYMENT_STATUS_FAILED => 'danger',
|
||||
PAYMENT_STATUS_PARTIALLY_REFUNDED => 'primary',
|
||||
PAYMENT_STATUS_VOIDED => 'default',
|
||||
PAYMENT_STATUS_REFUNDED => 'default',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
@ -302,6 +311,35 @@ class Payment extends EntityModel
|
||||
{
|
||||
return $value ? str_pad($value, 4, '0', STR_PAD_LEFT) : null;
|
||||
}
|
||||
|
||||
public static function calcStatusLabel($statusId, $statusName, $amount)
|
||||
{
|
||||
if ($statusId == PAYMENT_STATUS_PARTIALLY_REFUNDED) {
|
||||
return trans('texts.status_partially_refunded_amount', [
|
||||
'amount' => $amount,
|
||||
]);
|
||||
} else {
|
||||
return trans('texts.status_' . strtolower($statusName));
|
||||
}
|
||||
}
|
||||
|
||||
public static function calcStatusClass($statusId)
|
||||
{
|
||||
return static::$statusClasses[$statusId];
|
||||
}
|
||||
|
||||
|
||||
public function statusClass()
|
||||
{
|
||||
return static::calcStatusClass($this->payment_status_id);
|
||||
}
|
||||
|
||||
public function statusLabel()
|
||||
{
|
||||
$amount = $this->account->formatMoney($this->refunded, $this->client);
|
||||
return static::calcStatusLabel($this->payment_status_id, $this->payment_status->name, $amount);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Payment::creating(function ($payment) {
|
||||
|
@ -3,6 +3,7 @@
|
||||
use Utils;
|
||||
use URL;
|
||||
use Auth;
|
||||
use App\Models\Payment;
|
||||
use App\Models\PaymentMethod;
|
||||
|
||||
class PaymentDatatable extends EntityDatatable
|
||||
@ -140,29 +141,10 @@ class PaymentDatatable extends EntityDatatable
|
||||
|
||||
private function getStatusLabel($model)
|
||||
{
|
||||
$label = trans('texts.status_' . strtolower($model->status));
|
||||
$class = 'default';
|
||||
switch ($model->payment_status_id) {
|
||||
case PAYMENT_STATUS_PENDING:
|
||||
$class = 'info';
|
||||
break;
|
||||
case PAYMENT_STATUS_COMPLETED:
|
||||
$class = 'success';
|
||||
break;
|
||||
case PAYMENT_STATUS_FAILED:
|
||||
$class = 'danger';
|
||||
break;
|
||||
case PAYMENT_STATUS_PARTIALLY_REFUNDED:
|
||||
$label = trans('texts.status_partially_refunded_amount', [
|
||||
'amount' => Utils::formatMoney($model->refunded, $model->currency_id, $model->country_id),
|
||||
]);
|
||||
$class = 'primary';
|
||||
break;
|
||||
case PAYMENT_STATUS_VOIDED:
|
||||
case PAYMENT_STATUS_REFUNDED:
|
||||
$class = 'default';
|
||||
break;
|
||||
}
|
||||
$amount = Utils::formatMoney($model->refunded, $model->currency_id, $model->country_id);
|
||||
$label = Payment::calcStatusLabel($model->payment_status_id, $model->status, $amount);
|
||||
$class = Payment::calcStatusClass($model->payment_status_id);
|
||||
|
||||
return "<h4><div class=\"label label-{$class}\">$label</div></h4>";
|
||||
}
|
||||
}
|
||||
|
@ -28,4 +28,15 @@ class PaymentPresenter extends EntityPresenter {
|
||||
}
|
||||
}
|
||||
|
||||
public function statusLabel()
|
||||
{
|
||||
if ($label = parent::statusLabel()) {
|
||||
return $label;
|
||||
}
|
||||
|
||||
$class = $this->entity->statusClass();
|
||||
$label = $this->entity->statusLabel();
|
||||
|
||||
return "<span style=\"font-size:13px\" class=\"label label-{$class}\">{$label}</span>";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user