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(
|
$this->activityRepo->create(
|
||||||
$payment,
|
$payment,
|
||||||
ACTIVITY_TYPE_DELETE_PAYMENT,
|
ACTIVITY_TYPE_DELETE_PAYMENT,
|
||||||
$payment->amount - $payment->refunded,
|
$payment->getCompletedAmount(),
|
||||||
($payment->amount - $payment->refunded) * -1
|
$payment->getCompletedAmount() * -1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,8 +343,8 @@ class ActivityListener
|
|||||||
$this->activityRepo->create(
|
$this->activityRepo->create(
|
||||||
$payment,
|
$payment,
|
||||||
ACTIVITY_TYPE_FAILED_PAYMENT,
|
ACTIVITY_TYPE_FAILED_PAYMENT,
|
||||||
($payment->amount - $payment->refunded),
|
$payment->getCompletedAmount(),
|
||||||
($payment->amount - $payment->refunded) * -1
|
$payment->getCompletedAmount() * -1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,8 +367,8 @@ class ActivityListener
|
|||||||
$this->activityRepo->create(
|
$this->activityRepo->create(
|
||||||
$payment,
|
$payment,
|
||||||
ACTIVITY_TYPE_RESTORE_PAYMENT,
|
ACTIVITY_TYPE_RESTORE_PAYMENT,
|
||||||
$event->fromDeleted ? ($payment->amount - $payment->refunded) * -1 : 0,
|
$event->fromDeleted ? $payment->getCompletedAmount() * -1 : 0,
|
||||||
$event->fromDeleted ? ($payment->amount - $payment->refunded) : 0
|
$event->fromDeleted ? $payment->getCompletedAmount() : 0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,22 +90,22 @@ class Payment extends EntityModel
|
|||||||
{
|
{
|
||||||
return $this->payment_status_id = PAYMENT_STATUS_PENDING;
|
return $this->payment_status_id = PAYMENT_STATUS_PENDING;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isFailed()
|
public function isFailed()
|
||||||
{
|
{
|
||||||
return $this->payment_status_id = PAYMENT_STATUS_FAILED;
|
return $this->payment_status_id = PAYMENT_STATUS_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isCompleted()
|
public function isCompleted()
|
||||||
{
|
{
|
||||||
return $this->payment_status_id == PAYMENT_STATUS_COMPLETED;
|
return $this->payment_status_id == PAYMENT_STATUS_COMPLETED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isPartiallyRefunded()
|
public function isPartiallyRefunded()
|
||||||
{
|
{
|
||||||
return $this->payment_status_id == PAYMENT_STATUS_PARTIALLY_REFUNDED;
|
return $this->payment_status_id == PAYMENT_STATUS_PARTIALLY_REFUNDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isRefunded()
|
public function isRefunded()
|
||||||
{
|
{
|
||||||
return $this->payment_status_id == PAYMENT_STATUS_REFUNDED;
|
return $this->payment_status_id == PAYMENT_STATUS_REFUNDED;
|
||||||
@ -122,15 +122,15 @@ class Payment extends EntityModel
|
|||||||
if (!$amount) {
|
if (!$amount) {
|
||||||
$amount = $this->amount;
|
$amount = $this->amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
$new_refund = min($this->amount, $this->refunded + $amount);
|
$new_refund = min($this->amount, $this->refunded + $amount);
|
||||||
$refund_change = $new_refund - $this->refunded;
|
$refund_change = $new_refund - $this->refunded;
|
||||||
|
|
||||||
if ($refund_change) {
|
if ($refund_change) {
|
||||||
$this->refunded = $new_refund;
|
$this->refunded = $new_refund;
|
||||||
$this->payment_status_id = $this->refunded == $this->amount ? PAYMENT_STATUS_REFUNDED : PAYMENT_STATUS_PARTIALLY_REFUNDED;
|
$this->payment_status_id = $this->refunded == $this->amount ? PAYMENT_STATUS_REFUNDED : PAYMENT_STATUS_PARTIALLY_REFUNDED;
|
||||||
$this->save();
|
$this->save();
|
||||||
|
|
||||||
Event::fire(new PaymentWasRefunded($this, $refund_change));
|
Event::fire(new PaymentWasRefunded($this, $refund_change));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -167,6 +167,11 @@ class Payment extends EntityModel
|
|||||||
return ENTITY_PAYMENT;
|
return ENTITY_PAYMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCompletedAmount()
|
||||||
|
{
|
||||||
|
return $this->amount - $this->refunded;
|
||||||
|
}
|
||||||
|
|
||||||
public function getBankDataAttribute()
|
public function getBankDataAttribute()
|
||||||
{
|
{
|
||||||
if (!$this->routing_number) {
|
if (!$this->routing_number) {
|
||||||
@ -182,9 +187,9 @@ class Payment extends EntityModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
Payment::creating(function ($payment) {
|
Payment::creating(function ($payment) {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Payment::created(function ($payment) {
|
Payment::created(function ($payment) {
|
||||||
event(new PaymentWasCreated($payment));
|
event(new PaymentWasCreated($payment));
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user