diff --git a/app/Listeners/ActivityListener.php b/app/Listeners/ActivityListener.php index 6b7391b61868..52c2e26f9027 100644 --- a/app/Listeners/ActivityListener.php +++ b/app/Listeners/ActivityListener.php @@ -106,11 +106,13 @@ class ActivityListener public function deletedInvoice(InvoiceWasDeleted $event) { + $invoice = $event->invoice; + $this->activityRepo->create( - $event->invoice, + $invoice, ACTIVITY_TYPE_DELETE_INVOICE, - $event->invoice->balance * -1, - $event->invoice->getAmountPaid() * -1 + $invoice->affectsBalance() ? $invoice->balance * -1 : 0, + $invoice->affectsBalance() ? $invoice->getAmountPaid() * -1 : 0 ); } @@ -128,11 +130,13 @@ class ActivityListener public function restoredInvoice(InvoiceWasRestored $event) { + $invoice = $event->invoice; + $this->activityRepo->create( - $event->invoice, + $invoice, ACTIVITY_TYPE_RESTORE_INVOICE, - $event->fromDeleted ? $event->invoice->balance : 0, - $event->fromDeleted ? $event->invoice->getAmountPaid() : 0 + $invoice->affectsBalance() && $event->fromDeleted ? $invoice->balance : 0, + $invoice->affectsBalance() && $event->fromDeleted ? $invoice->getAmountPaid() : 0 ); } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 14c5f08602b4..ab4d9bc14be9 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -46,9 +46,14 @@ class Invoice extends EntityModel implements BalanceAffecting return $this->is_recurring ? trans('texts.recurring') : $this->invoice_number; } + public function affectsBalance() + { + return !$this->is_quote && !$this->is_recurring; + } + public function getAdjustment() { - if ($this->is_quote || $this->is_recurring) { + if (!$this->affectsBalance()) { return 0; }