mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-09 20:52:56 +01:00
Added getCompletedAmount to payments
This commit is contained in:
parent
38866ff6f0
commit
e5e65c0349
@ -307,8 +307,8 @@ class ActivityListener
|
||||
$this->activityRepo->create(
|
||||
$payment,
|
||||
ACTIVITY_TYPE_DELETE_PAYMENT,
|
||||
$payment->amount - $payment->refunded,
|
||||
($payment->amount - $payment->refunded) * -1
|
||||
$payment->getCompletedAmount(),
|
||||
$payment->getCompletedAmount() * -1
|
||||
);
|
||||
}
|
||||
|
||||
@ -343,8 +343,8 @@ class ActivityListener
|
||||
$this->activityRepo->create(
|
||||
$payment,
|
||||
ACTIVITY_TYPE_FAILED_PAYMENT,
|
||||
($payment->amount - $payment->refunded),
|
||||
($payment->amount - $payment->refunded) * -1
|
||||
$payment->getCompletedAmount(),
|
||||
$payment->getCompletedAmount() * -1
|
||||
);
|
||||
}
|
||||
|
||||
@ -367,8 +367,8 @@ class ActivityListener
|
||||
$this->activityRepo->create(
|
||||
$payment,
|
||||
ACTIVITY_TYPE_RESTORE_PAYMENT,
|
||||
$event->fromDeleted ? ($payment->amount - $payment->refunded) * -1 : 0,
|
||||
$event->fromDeleted ? ($payment->amount - $payment->refunded) : 0
|
||||
$event->fromDeleted ? $payment->getCompletedAmount() * -1 : 0,
|
||||
$event->fromDeleted ? $payment->getCompletedAmount() : 0
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -90,22 +90,22 @@ class Payment extends EntityModel
|
||||
{
|
||||
return $this->payment_status_id = PAYMENT_STATUS_PENDING;
|
||||
}
|
||||
|
||||
|
||||
public function isFailed()
|
||||
{
|
||||
return $this->payment_status_id = PAYMENT_STATUS_FAILED;
|
||||
}
|
||||
|
||||
|
||||
public function isCompleted()
|
||||
{
|
||||
return $this->payment_status_id == PAYMENT_STATUS_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
public function isPartiallyRefunded()
|
||||
{
|
||||
return $this->payment_status_id == PAYMENT_STATUS_PARTIALLY_REFUNDED;
|
||||
}
|
||||
|
||||
|
||||
public function isRefunded()
|
||||
{
|
||||
return $this->payment_status_id == PAYMENT_STATUS_REFUNDED;
|
||||
@ -122,15 +122,15 @@ class Payment extends EntityModel
|
||||
if (!$amount) {
|
||||
$amount = $this->amount;
|
||||
}
|
||||
|
||||
|
||||
$new_refund = min($this->amount, $this->refunded + $amount);
|
||||
$refund_change = $new_refund - $this->refunded;
|
||||
|
||||
|
||||
if ($refund_change) {
|
||||
$this->refunded = $new_refund;
|
||||
$this->payment_status_id = $this->refunded == $this->amount ? PAYMENT_STATUS_REFUNDED : PAYMENT_STATUS_PARTIALLY_REFUNDED;
|
||||
$this->save();
|
||||
|
||||
|
||||
Event::fire(new PaymentWasRefunded($this, $refund_change));
|
||||
}
|
||||
}
|
||||
@ -167,6 +167,11 @@ class Payment extends EntityModel
|
||||
return ENTITY_PAYMENT;
|
||||
}
|
||||
|
||||
public function getCompletedAmount()
|
||||
{
|
||||
return $this->amount - $this->refunded;
|
||||
}
|
||||
|
||||
public function getBankDataAttribute()
|
||||
{
|
||||
if (!$this->routing_number) {
|
||||
@ -182,9 +187,9 @@ class Payment extends EntityModel
|
||||
}
|
||||
|
||||
Payment::creating(function ($payment) {
|
||||
|
||||
|
||||
});
|
||||
|
||||
Payment::created(function ($payment) {
|
||||
event(new PaymentWasCreated($payment));
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user